Пример #1
0
function checkTvImages($pdo, $tvrage)
{
    $text = new Text();
    $images = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tvrage->imgSavePath), RecursiveIteratorIterator::SELF_FIRST);
    if ($images instanceof \Traversable) {
        $imgCount = iterator_count($images);
        echo PHP_EOL . $pdo->log->header("Matching " . number_format($imgCount) . " files to their RageIDs and setting hascover.") . PHP_EOL;
        $checkCnt = $notReqdCnt = $badRageCnt = 0;
        foreach ($images as $file) {
            $rightCut = $text->cutStringUsingLast('/', $file, "right", false);
            $leftCut = $text->cutStringUsingLast('.', $rightCut, "left", false);
            $check = $pdo->queryOneRow(sprintf("SELECT id, hascover\n\t\t\t\t\t\t\t\t\tFROM tvrage_titles\n\t\t\t\t\t\t\t\t\tWHERE rageid = %d", $leftCut));
            if ($check) {
                if ($check['hascover'] == 0) {
                    $pdo->queryExec(sprintf("UPDATE tvrage_titles\n\t\t\t\t\t\t\t\t\t\tSET hascover = 1\n\t\t\t\t\t\t\t\t\t\tWHERE id = %d", $check['id']));
                    $checkCnt++;
                } else {
                    $notReqdCnt++;
                }
            } else {
                $missingRageCnt++;
            }
        }
    }
    echo PHP_EOL . $pdo->log->primary("Updated " . number_format($checkCnt) . " RageIDs. " . number_format($notReqdCnt) . " were already set and " . number_format($missingRageCnt) . " images did not have matching RageIDs in the database.") . PHP_EOL;
}
Пример #2
0
Файл: DB.php Проект: zetas/nZEDb
 /**
  * Checks if the query is empty. Cleans the query of whitespace is needed.
  *
  * @param reference string $query
  *
  * @return bool
  */
 private function parseQuery(&$query)
 {
     if (empty($query)) {
         return false;
     }
     if (nZEDb_QUERY_STRIP_WHITESPACE) {
         $query = Text::collapseWhiteSpace($query);
     }
     return true;
 }
Пример #3
0
 /**
  * Cleans file names for PreDB Match
  */
 protected function _cleanMatchFiles($fileName = '')
 {
     // first strip all non-printing chars  from filename
     $this->_fileName = $this->text->stripNonPrintingChars($fileName);
     if (strlen($this->_fileName) !== false && strlen($this->_fileName) > 0 && strpos($this->_fileName, '.') !== 0) {
         switch (true) {
             case strpos($this->_fileName, '.') !== false:
                 //some filenames start with a period that ends up creating bad matches so we don't process them
                 $this->_fileName = $this->text->cutStringUsingLast('.', $this->_fileName, "left", false);
                 continue;
                 //if filename has a .part001, send it back to the function to cut the next period
             //if filename has a .part001, send it back to the function to cut the next period
             case preg_match('/\\.part\\d+$/', $this->_fileName):
                 $this->_fileName = $this->text->cutStringUsingLast('.', $this->_fileName, "left", false);
                 continue;
                 //if filename has a .vol001, send it back to the function to cut the next period
             //if filename has a .vol001, send it back to the function to cut the next period
             case preg_match('/\\.vol\\d+(\\+\\d+)?$/', $this->_fileName):
                 $this->_fileName = $this->text->cutStringUsingLast('.', $this->_fileName, "left", false);
                 continue;
                 //if filename contains a slash, cut the string and keep string to the right of the last slash to remove dir
             //if filename contains a slash, cut the string and keep string to the right of the last slash to remove dir
             case strpos($this->_fileName, '\\') !== false:
                 $this->_fileName = $this->text->cutStringUsingLast('\\', $this->_fileName, "right", false);
                 continue;
                 // A lot of obscured releases have one NFO file properly named with a track number (Audio) at the front of it
                 // This will strip out the track and match it to its pre title
             // A lot of obscured releases have one NFO file properly named with a track number (Audio) at the front of it
             // This will strip out the track and match it to its pre title
             case preg_match('/^\\d{2}-/', $this->_fileName):
                 $this->_fileName = preg_replace('/^\\d{2}-/', '', $this->_fileName);
         }
         return trim($this->_fileName);
     }
 }
Пример #4
0
Файл: TV.php Проект: zetas/nZEDb
 /**
  * Parses the release searchname for the season/episode/airdate information
  *
  * @param $relname
  *
  * @return array
  */
 private function parseSeasonEp($relname)
 {
     $episodeArr = [];
     // S01E01-E02 and S01E01-02
     if (preg_match('/^(.*?)[^a-z0-9]s(\\d{1,2})[^a-z0-9]?e(\\d{1,3})(?:[e-])(\\d{1,3})[^a-z0-9]/i', $relname, $matches)) {
         $episodeArr['season'] = intval($matches[2]);
         $episodeArr['episode'] = [intval($matches[3]), intval($matches[4])];
     } else {
         if (preg_match('/^(.*?)[^a-z0-9]s(\\d{2})[^a-z0-9]?e(\\d{2})e?(\\d{2})[^a-z0-9]/i', $relname, $matches)) {
             $episodeArr['season'] = intval($matches[2]);
             $episodeArr['episode'] = intval($matches[3]);
         } else {
             if (preg_match('/^(.*?)[^a-z0-9]s(\\d{1,2})[^a-z0-9]?e(\\d{1,3})[abr]?[^a-z0-9]/i', $relname, $matches)) {
                 $episodeArr['season'] = intval($matches[2]);
                 $episodeArr['episode'] = intval($matches[3]);
             } else {
                 if (preg_match('/^(.*?)[^a-z0-9]s(\\d{1,2})[^a-z0-9]/i', $relname, $matches)) {
                     $episodeArr['season'] = intval($matches[2]);
                     $episodeArr['episode'] = 'all';
                 } else {
                     if (preg_match('/^(.*?)[^a-z0-9]s(\\d{1,2})[^a-z0-9]?d\\d{1}[^a-z0-9]/i', $relname, $matches)) {
                         $episodeArr['season'] = intval($matches[2]);
                         $episodeArr['episode'] = 'all';
                     } else {
                         if (preg_match('/^(.*?)[^a-z0-9](\\d{1,2})x(\\d{1,3})[^a-z0-9]/i', $relname, $matches)) {
                             $episodeArr['season'] = intval($matches[2]);
                             $episodeArr['episode'] = intval($matches[3]);
                         } else {
                             if (preg_match('/^(.*?)[^a-z0-9](?P<airdate>(19|20)(\\d{2})[.\\/-](\\d{2})[.\\/-](\\d{2}))[^a-z0-9]/i', $relname, $matches)) {
                                 $episodeArr['season'] = $matches[4] . $matches[5];
                                 $episodeArr['episode'] = $matches[5] . '/' . $matches[6];
                                 $episodeArr['airdate'] = date('Y-m-d', strtotime(preg_replace('/[^0-9]/i', '/', $matches['airdate'])));
                                 //yyyy-mm-dd
                             } else {
                                 if (preg_match('/^(.*?)[^a-z0-9](?P<airdate>(\\d{2})[^a-z0-9](\\d{2})[^a-z0-9](19|20)(\\d{2}))[^a-z0-9]/i', $relname, $matches)) {
                                     $episodeArr['season'] = $matches[5] . $matches[6];
                                     $episodeArr['episode'] = $matches[3] . '/' . $matches[4];
                                     $episodeArr['airdate'] = date('Y-m-d', strtotime(preg_replace('/[^0-9]/i', '/', $matches['airdate'])));
                                     //yyyy-mm-dd
                                 } else {
                                     if (preg_match('/^(.*?)[^a-z0-9](\\d{2})[^a-z0-9](\\d{2})[^a-z0-9](\\d{2})[^a-z0-9]/i', $relname, $matches)) {
                                         // Add extra logic to capture the proper YYYY year
                                         $episodeArr['season'] = $matches[4] = $matches[4] <= 99 && $matches[4] > 15 ? '19' . $matches[4] : '20' . $matches[4];
                                         $episodeArr['episode'] = $matches[2] . '/' . $matches[3];
                                         $tmpAirdate = $episodeArr['season'] . '/' . $episodeArr['episode'];
                                         $episodeArr['airdate'] = date('Y-m-d', strtotime(preg_replace('/[^0-9]/i', '/', $tmpAirdate)));
                                         //yyyy-mm-dd
                                     } else {
                                         if (preg_match('/^(.*?)[^a-z0-9]20(\\d{2})[^a-z0-9](\\d{1,3})[^a-z0-9]/i', $relname, $matches)) {
                                             $episodeArr['season'] = '20' . $matches[2];
                                             $episodeArr['episode'] = intval($matches[3]);
                                         } else {
                                             if (preg_match('/^(.*?)[^a-z0-9](19|20)(\\d{2})[^a-z0-9]Part(\\d{1,2})[^a-z0-9]/i', $relname, $matches)) {
                                                 $episodeArr['season'] = $matches[2] . $matches[3];
                                                 $episodeArr['episode'] = intval($matches[4]);
                                             } else {
                                                 if (preg_match('/^(.*?)[^a-z0-9](?:Part|Pt)[^a-z0-9](\\d{1,2})[^a-z0-9]/i', $relname, $matches)) {
                                                     $episodeArr['season'] = 1;
                                                     $episodeArr['episode'] = intval($matches[2]);
                                                 } else {
                                                     if (preg_match('/^(.*?)[^a-z0-9](?:Part|Pt)[^a-z0-9]([ivx]+)/i', $relname, $matches)) {
                                                         $episodeArr['season'] = 1;
                                                         $epLow = strtolower($matches[2]);
                                                         $episodeArr['episode'] = Text::convertRomanToInt($epLow);
                                                     } else {
                                                         if (preg_match('/^(.*?)[^a-z0-9]EP?[^a-z0-9]?(\\d{1,3})/i', $relname, $matches)) {
                                                             $episodeArr['season'] = 1;
                                                             $episodeArr['episode'] = intval($matches[2]);
                                                         } else {
                                                             if (preg_match('/^(.*?)[^a-z0-9]Seasons?[^a-z0-9]?(\\d{1,2})/i', $relname, $matches)) {
                                                                 $episodeArr['season'] = intval($matches[2]);
                                                                 $episodeArr['episode'] = 'all';
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $episodeArr;
 }
Пример #5
0
 protected function _validate(array $fields)
 {
     $defaults = ['checkpasswordedrar' => false, 'ffmpegpath' => '', 'mediainfopath' => '', 'nzbpath' => '', 'tmpunrarpath' => '', 'unrarpath' => '', 'yydecoderpath' => ''];
     $fields += $defaults;
     // Make sure keys exist to avoid error notices.
     ksort($fields);
     // Validate settings
     $fields['nzbpath'] = Text::trailingSlash($fields['nzbpath']);
     $error = null;
     switch (true) {
         case $fields['mediainfopath'] != '' && !is_file($fields['mediainfopath']):
             $error = Settings::ERR_BADMEDIAINFOPATH;
             break;
         case $fields['ffmpegpath'] != '' && !is_file($fields['ffmpegpath']):
             $error = Settings::ERR_BADFFMPEGPATH;
             break;
         case $fields['unrarpath'] != '' && !is_file($fields['unrarpath']):
             $error = Settings::ERR_BADUNRARPATH;
             break;
         case empty($fields['nzbpath']):
             $error = Settings::ERR_BADNZBPATH_UNSET;
             break;
         case !file_exists($fields['nzbpath']) || !is_dir($fields['nzbpath']):
             $error = Settings::ERR_BADNZBPATH;
             break;
         case !is_readable($fields['nzbpath']):
             $error = Settings::ERR_BADNZBPATH_UNREADABLE;
             break;
         case $fields['checkpasswordedrar'] == 1 && !is_file($fields['unrarpath']):
             $error = Settings::ERR_DEEPNOUNRAR;
             break;
         case $fields['tmpunrarpath'] != '' && !file_exists($fields['tmpunrarpath']):
             $error = Settings::ERR_BADTMPUNRARPATH;
             break;
         case $fields['yydecoderpath'] != '' && $fields['yydecoderpath'] !== 'simple_php_yenc_decode' && !file_exists($fields['yydecoderpath']):
             $error = Settings::ERR_BAD_YYDECODER_PATH;
     }
     return $error;
 }
Пример #6
0
function encodeAsJSON($data)
{
    $json = json_encode(Text::encodeAsUTF8($data));
    if ($json === false) {
        showApiError(201);
    }
    return $json;
}
Пример #7
0
 public function updateSchemaData(array $options = [])
 {
     $changed = false;
     $default = ['file' => '10-settings.tsv', 'path' => 'resources' . DS . 'db' . DS . 'schema' . DS . 'data' . DS, 'regex' => '#^(?P<section>.*)\\t(?P<subsection>.*)\\t(?P<name>.*)\\t(?P<value>.*)\\t(?P<hint>.*)\\t(?P<setting>.*)$#', 'value' => function (array $matches) {
         return "{$matches['section']}\t{$matches['subsection']}\t{$matches['name']}\t{$matches['value']}\t{$matches['hint']}\t{$matches['setting']}";
     }];
     $options += $default;
     $file = [];
     $filespec = Text::trailingSlash($options['path']) . $options['path'];
     if (file_exists($filespec) && ($file = file($filespec, FILE_IGNORE_NEW_LINES))) {
         $count = count($file);
         $index = 0;
         while ($index < $count) {
             if (preg_match($options['regex'], $file[$index], $matches)) {
                 if (VERBOSE) {
                     echo $this->log->primary("Matched: " . $file[$index]);
                 }
                 $index++;
                 if (is_callable($options['value'])) {
                     $file[$index] = $options['value']($matches);
                 } else {
                     $file[$index] = $options['value'];
                 }
                 $changed = true;
             }
         }
     }
     if ($changed) {
         if (file_put_contents($filespec, implode("\n", $file)) === false) {
             echo $this->log->error("Error writing file to disc!!");
         }
     }
 }
Пример #8
0
<?php

use nzedb\Releases;
use nzedb\utility\Text;
if (!$page->users->isLoggedIn()) {
    $page->show403();
}
$releases = new Releases(['Settings' => $page->settings]);
if (isset($_GET["id"])) {
    $rel = $releases->getByGuid($_GET["id"]);
    if (!$rel) {
        $page->show404();
    }
    $nfo = $releases->getReleaseNfo($rel['id']);
    $nfo['nfoUTF'] = Text::cp437toUTF($nfo['nfo']);
    $page->smarty->assign('rel', $rel);
    $page->smarty->assign('nfo', $nfo);
    $page->title = "NFO File";
    $page->meta_title = "View Nfo";
    $page->meta_keywords = "view,nzb,nfo,description,details";
    $page->meta_description = "View Nfo File";
    $modal = false;
    if (isset($_GET['modal'])) {
        $modal = true;
        $page->smarty->assign('modal', true);
    }
    $page->content = $page->smarty->fetch('viewnfo.tpl');
    if ($modal) {
        echo $page->content;
    } else {
        $page->trimWhiteSpace = false;
Пример #9
0
 public static function setCoversConstant($path)
 {
     if (!defined('nZEDb_COVERS')) {
         switch (true) {
             case substr($path, 0, 1) == '/' || substr($path, 1, 1) == ':' || substr($path, 0, 1) == '\\':
                 define('nZEDb_COVERS', Text::trailingSlash($path));
                 break;
             case strlen($path) > 0 && substr($path, 0, 1) != '/' && substr($path, 1, 1) != ':' && substr($path, 0, 1) != '\\':
                 define('nZEDb_COVERS', realpath(nZEDb_ROOT . Text::trailingSlash($path)));
                 break;
             case empty($path):
                 // Default to resources location.
             // Default to resources location.
             default:
                 define('nZEDb_COVERS', nZEDb_RES . 'covers' . DS);
         }
     }
 }
Пример #10
0
if (!isset($argv[1])) {
    $message = <<<HELP
This script can export a predb dump file. You may use the full path, or a relative path.
For exporting, the path must be writeable by mysql, any existing file will be overwritten.
Filename is optional, if not included it defaults to predb_export_YYYYMMDDhhmmss.tsv where
YYYYMMDDhhmmss is the current UTC date-time.

php {$argv[0]} /path/to/write/to/[<file-name>]                    ...: To export.

HELP;
    exit($message);
} else {
    $path = !preg_match('#^/#', $argv[1]) ? realpath($argv[1]) : $argv[1];
}
if (file_exists($path) && is_file($path)) {
    unlink($path);
} else {
    if (is_dir($path)) {
        $path = Text::trailingSlash($path) . 'predb_export_' . strftime('%Y%m%d%H%M%S') . '.tsv';
    }
}
Misc::clearScreen();
$table = isset($argv[2]) ? $argv[2] : 'predb';
$predb = new PreDb();
if (nZEDb_ECHOCLI) {
    echo "Exporting table: {$table} to '{$path}'\n";
}
$result = $predb->executeExport(['enclosed' => '', 'fields' => '\\t\\t', 'limit' => 0, 'lines' => '\\r\\n', 'path' => $path]);
if ($result == false) {
    echo "ERROR: Failed to export file!\nMake sure the MySQL user has permission to write to the location.\n";
}