From 92bc3c8f349d1b6ca161ec4789fd30c7da92c7cb Mon Sep 17 00:00:00 2001 From: DariusIII Date: Mon, 9 May 2016 22:10:59 +0200 Subject: [PATCH] Small improvements in additional processing. --- Changelog | 1 + newznab/Category.php | 21 ++++++--- newznab/NameFixer.php | 3 ++ newznab/PreDb.php | 10 +++-- newznab/processing/post/ProcessAdditional.php | 43 +++++++++++++++++-- 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/Changelog b/Changelog index 95e9bfeb2..45cf26e72 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2016-05-09 DariusIII + * Upd: Small improvements in additional processing * Fix: Wrong class in Movie.php * Chg: Replace/remove refferences to python scripts where possible. * Fix: Change TIME() to lowercase time() diff --git a/newznab/Category.php b/newznab/Category.php index a7cd60506..5e56eb37a 100644 --- a/newznab/Category.php +++ b/newznab/Category.php @@ -326,12 +326,24 @@ class Category } } + /** + * Return the parent and category name from the supplied categoryID. + * @param $ID + * + * @return string + */ public function getNameByID($ID) { - $parent = $this->pdo->queryOneRow(sprintf("SELECT title FROM categories WHERE id = %d", substr($ID, 0, 1) . "000")); - $cat = $this->pdo->queryOneRow(sprintf("SELECT title FROM categories WHERE id = %d", $ID)); - - return $parent["title"] . " " . $cat["title"]; + $cat = $this->pdo->queryOneRow( + sprintf(" + SELECT c.title AS ctitle, cp.title AS ptitle + FROM categories c + INNER JOIN categories cp ON c.parentid = cp.id + WHERE c.id = %d", + $ID + ) + ); + return $cat["ptitle"] . " -> " . $cat["ctitle"]; } /** @@ -441,5 +453,4 @@ class Category " ORDER BY c.id" ); } - } diff --git a/newznab/NameFixer.php b/newznab/NameFixer.php index d2e71a81f..f04b6cf75 100755 --- a/newznab/NameFixer.php +++ b/newznab/NameFixer.php @@ -686,6 +686,9 @@ class NameFixer case "Extension, ": $status = "isrenamed = 1, iscategorized = 1,"; break; + case "CRC/OSO, ": + $status = "isrenamed = 1, iscategorized = 1,"; + break; } $this->pdo->queryExec( sprintf(' diff --git a/newznab/PreDb.php b/newznab/PreDb.php index 11a6f5bb1..88910a273 100644 --- a/newznab/PreDb.php +++ b/newznab/PreDb.php @@ -74,10 +74,12 @@ Class PreDb $res = $this->pdo->queryDirect( sprintf(' - SELECT p.id AS preid, r.id AS releaseid - FROM predb p - INNER JOIN releases r ON p.title = r.searchname - WHERE r.preid < 1 %s', + SELECT p.id AS preid, r.id AS releaseid + FROM predb p + INNER JOIN releases r + FORCE INDEX (ix_releases_preid_searchname) + ON p.title = r.searchname + WHERE r.preid < 1 %s', $datesql ) ); diff --git a/newznab/processing/post/ProcessAdditional.php b/newznab/processing/post/ProcessAdditional.php index a39be9c48..0ea996fba 100644 --- a/newznab/processing/post/ProcessAdditional.php +++ b/newznab/processing/post/ProcessAdditional.php @@ -209,6 +209,11 @@ class ProcessAdditional */ protected $_nfo; + /** + * @var \newznab\processing\post\CRC + */ + protected $_crc; + /** * @var bool */ @@ -381,6 +386,17 @@ class ProcessAdditional */ protected $_compressedFilesChecked; + /** + * Should we download the last rar? + * @var bool + */ + protected $_fetchLastFiles; + /** + * Are we downloading the last rar? + * @var bool + */ + protected $_reverse; + /** * @param array $options Class instances / echo to cli. */ @@ -420,10 +436,14 @@ class ProcessAdditional $this->_srrInfo = new \SrrInfo(); $this->_nfo = ($options['Nfo'] instanceof Nfo ? $options['Nfo'] : new Nfo(['Echo' => $this->_echoCLI, 'Settings' => $this->pdo])); $this->sphinx = ($options['SphinxSearch'] instanceof SphinxSearch ? $options['SphinxSearch'] : new SphinxSearch()); + if (class_exists('newznab\processing\post\CRC')) { + $this->_crc = new CRC(['Settings' => $this->pdo, 'Echo' => $this->_echoCLI, 'NameFixer' => $this->_nameFixer]); + } $this->_innerFileBlacklist = ($this->pdo->getSetting('innerfileblacklist') == '' ? false : $this->pdo->getSetting('innerfileblacklist')); $this->_maxNestedLevels = ($this->pdo->getSetting('maxnestedlevels') == 0 ? 3 : $this->pdo->getSetting('maxnestedlevels')); $this->_extractUsingRarInfo = ($this->pdo->getSetting('extractusingrarinfo') == 0 ? false : true); + $this->_fetchLastFiles = ($this->pdo->getSetting('fetchlastcompressedfiles') == 0 ? false : true); $this->_7zipPath = false; $this->_unrarPath = false; @@ -626,7 +646,9 @@ class ProcessAdditional $this->_releases = $this->pdo->query( sprintf( ' - SELECT r.id, r.guid, r.name, c.disablepreview, r.size, r.groupid, r.nfostatus, r.completion, r.categories_id, r.searchname, r.preid + SELECT r.id, r.id AS releaseid, r.guid, r.name, r.size, r.groupid, + r.nfostatus, r.completion, r.categories_id, r.searchname, r.preid, + c.disablepreview FROM releases r LEFT JOIN categories c ON c.id = r.categories_id WHERE r.nzbstatus = 1 @@ -729,7 +751,7 @@ class ProcessAdditional $this->_processNZBCompressedFiles(); // Download rar/zip in reverse order, to get the last rar or zip file. - if ($this->pdo->getSetting('fetchlastcompressedfiles') == 1) { + if ($this->_fetchLastFiles == 1) { $this->_processNZBCompressedFiles(true); } @@ -981,7 +1003,8 @@ class ProcessAdditional */ protected function _processNZBCompressedFiles($reverse = false) { - if ($reverse) { + $this->_reverse = $reverse; + if ($this->_reverse) { if (!krsort($this->_nzbContents)) { return; } @@ -1098,6 +1121,20 @@ class ProcessAdditional return false; } + if (isset($this->_crc) && $this->_reverse === true) { + $fileData = (isset($dataSummary['file_list'][0]) ? $dataSummary['file_list'][0] : ''); + if(isset($fileData['crc32']) && isset($fileData['size']) && $fileData['size'] > 104857600) { + $matchedCRC = $this->_crc->checkCRCInfo( + $this->_release, + $fileData['crc32'], + $fileData['size'], + '', + $fileData['date'] + ); + $this->_release['preid'] = ($matchedCRC !== false ? $matchedCRC : 0); + } + } + switch ($dataSummary['main_type']) { case \ArchiveInfo::TYPE_RAR: if ($this->_echoCLI) {