diff --git a/newznab/NameFixer.php b/newznab/NameFixer.php index 99369faf2..aecc025a6 100755 --- a/newznab/NameFixer.php +++ b/newznab/NameFixer.php @@ -482,20 +482,28 @@ class NameFixer $queryLimit = ($limit === '') ? '' : ' LIMIT ' . $limit; // 24 hours, other cats if ($time == 1 && $cats == 1) { - //echo $this->pdo->log->header($query . $this->timeother . ";\n"); - $releases = $this->pdo->queryDirect($query . $this->timeother . $queryLimit); + $queryTime = $this->timeother; } // 24 hours, all cats else if ($time == 1 && $cats == 2) { - //echo $this->pdo->log->header($query . $this->timeall . ";\n"); - $releases = $this->pdo->queryDirect($query . $this->timeall . $queryLimit); + $queryTime = $this->timeall; } //other cats else if ($time == 2 && $cats == 1) { - //echo $this->pdo->log->header($query . $this->fullother . ";\n"); - $releases = $this->pdo->queryDirect($query . $this->fullother . $queryLimit); - } // all cats + $queryTime = $this->fullother; + } + // all cats else if ($time == 2 && $cats == 2) { - //echo $this->pdo->log->header($query . $this->fullall . ";\n"); - $releases = $this->pdo->queryDirect($query . $this->fullall . $queryLimit); + $queryTime = $this->fullall; + } + + if (isset($queryTime)) { + $query .= $queryTime; + // Remove GROUP BY if it exists for filename based renames + if (strpos($query, 'proc_files') !== false) { + $query = str_replace('GROUP BY r.id', '', $query); + } + echo $this->pdo->log->header("{$query};\n"); + + $releases = $this->pdo->queryDirect($query . $queryLimit); } return $releases; diff --git a/newznab/processing/PostProcess.php b/newznab/processing/PostProcess.php index 11cf73aab..86ad5b77d 100755 --- a/newznab/processing/PostProcess.php +++ b/newznab/processing/PostProcess.php @@ -12,7 +12,6 @@ use newznab\Music; use newznab\NameFixer; use newznab\Nfo; use newznab\Sharing; -//use newznab\processing\tv\TvRage; use newznab\processing\tv\TVDB; use newznab\processing\tv\TVMaze; use newznab\processing\tv\TMDB; @@ -23,7 +22,7 @@ use newznab\db\Settings; use newznab\processing\post\AniDB; use newznab\processing\post\ProcessAdditional; use newznab\SpotNab; -use newznab\utility; +use newznab\utility\Utility; require_once NN_LIBS . 'rarinfo/par2info.php'; require_once NN_LIBS . 'rarinfo/srrinfo.php'; @@ -116,7 +115,6 @@ class PostProcess $this->pdo = (($options['Settings'] instanceof Settings) ? $options['Settings'] : new Settings()); $this->groups = (($options['Groups'] instanceof Groups) ? $options['Groups'] : new Groups(['Settings' => $this->pdo])); $this->_par2Info = new \Par2Info(); - $this->_srrInfo = new \SrrInfo(); $this->debugging = ($options['Logger'] instanceof Logger ? $options['Logger'] : new Logger(['ColorCLI' => $this->pdo->log])); $this->nameFixer = (($options['NameFixer'] instanceof NameFixer) ? $options['NameFixer'] : new NameFixer(['Echo' => $this->echooutput, 'Settings' => $this->pdo, 'Groups' => $this->groups])); $this->Nfo = (($options['Nfo'] instanceof Nfo) ? $options['Nfo'] : new Nfo(['Echo' => $this->echooutput, 'Settings' => $this->pdo])); @@ -465,6 +463,9 @@ class PostProcess */ public function parseSRR($messageID, $relID, &$nntp, $show) { + $this->_srrInfo = new \SrrInfo(); + $foundMatch = false; + if ($messageID === '') { return false; } @@ -479,9 +480,8 @@ class PostProcess FROM releases r LEFT JOIN groups g ON r.groupid = g.id WHERE r.isrenamed = 0 - AND r.categoryid IN (%s) + AND r.prehashid = 0 AND r.id = %d', - implode(',', Category::CAT_GROUP_OTHER), $relID ) ); @@ -492,32 +492,49 @@ class PostProcess // Get the SRR file. $srr = $nntp->getMessages($query['groupname'], $messageID, $this->alternateNNTP); + if ($nntp->isError($srr)) { - echo "Couldn't connect to usenet, dummy"; + if ($srr->getMessage() === 'No such article found') { + $this->pdo->log->doEcho($this->pdo->log->primaryOver('f')); + } return false; } // Put the SRR into SrrInfo, check if there's an error. $this->_srrInfo->setData($srr); if ($this->_srrInfo->error) { + $this->pdo->log->doEcho($this->pdo->log->primaryOver("-")); return false; } // Get the file list from SrrInfo. $summary = $this->_srrInfo->getSummary(); - var_dump($summary); if ($summary !== false && empty($summary['error'])) { - $foundName = false; - // Try to get a new name. - $query['textstring'] = $summary['file_name']; - if ($this->nameFixer->checkName($query, 1, 'SRR, ', 1, $show) === true) { - $foundName = true; - } + $this->pdo->log->doEcho($this->pdo->log->primaryOver("+")); - if ($foundName === true) { - return true; + // Try to get a Pre Match by the OSO release name. + if (isset($summary['oso_info']['name']) && !empty($summary['oso_info']['name'])) { + $query['textstring'] = $summary['oso_info']['name']; + $foundMatch = $this->nameFixer->checkName($query, 1, 'SRR, ', 1, $show, true); + } + // Loop through the stored files in the SRR and try to get a Pre Match + if ($foundMatch === false && is_array($summary['stored_files']) && !empty($summary['stored_files'])) { + foreach ($summary['stored_files'] AS $storedFile) { + if ($foundMatch === true) { + break; + } else if (isset($storedFile['name']) && !empty($storedFile['name'])) { + $query['textstring'] = Utility::cutStringUsingLast('.', $storedFile['name'], 'left', false); + $foundMatch = $this->nameFixer->checkName($query, 1, 'SRR, ', 1, $show, true); + } + } + } + // This field is rarely populated but worth a shot for a rename + if ($foundMatch === false && isset($summary['file_name']) && !empty($summary['file_name'])) { + $query['textstring'] = Utility::cutStringUsingLast('.', $summary['file_name'], 'left', false); + $foundMatch = $this->nameFixer->checkName($query, 1, 'SRR, ', 1, $show, true); } } - return false; + unset($this->_srrInfo); + return $foundMatch; } } diff --git a/newznab/processing/post/ProcessAdditional.php b/newznab/processing/post/ProcessAdditional.php index b27b05def..229eb30a9 100644 --- a/newznab/processing/post/ProcessAdditional.php +++ b/newznab/processing/post/ProcessAdditional.php @@ -421,7 +421,7 @@ class ProcessAdditional $this->_releaseExtra = ($options['ReleaseExtra'] instanceof ReleaseExtra ? $options['ReleaseExtra'] : new ReleaseExtra($this->pdo)); $this->_releaseImage = ($options['ReleaseImage'] instanceof ReleaseImage ? $options['ReleaseImage'] : new ReleaseImage($this->pdo)); $this->_par2Info = new \Par2Info(); - $this->_SRRInfo = new \SrrInfo(); + $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()); @@ -1328,11 +1328,10 @@ class ProcessAdditional if (is_file($file)) { // Process PAR2 files. - if ($this->_foundPAR2Info === false && preg_match('/\.par2$/', $file)) { + if ($this->_foundPAR2Info === false && preg_match('/\.par2$/i', $file)) { $this->_siftPAR2Info($file); } // Process SRR files - else if ($this->_foundSRRInfo === false && preg_match('/\.srr$/', $file)) { - exit; + else if ($this->_foundSRRInfo === false && preg_match('/\.srr$/i', $file)) { $this->_siftSRRInfo($file); } // Process NFO files. else if ($this->_releaseHasNoNFO === true && preg_match('/(\.(nfo|inf|ofn)|info\.txt)$/i', $file)) { @@ -2338,44 +2337,65 @@ class ProcessAdditional /** * Get file info from inside SRR and attempt to get a release name. * - * @param string $fileLocation + * @param string $srr */ - protected function _siftSRRInfo($fileLocation) + protected function _siftSRRInfo($srr) { - $releaseInfo = $this->pdo->queryOneRow( - sprintf( - ' - SELECT UNIX_TIMESTAMP(postdate) AS postdate, isrenamed - FROM releases - WHERE id = %d', + $foundMatch = false; + + $query = $this->pdo->queryOneRow( + sprintf(' + SELECT + r.id, r.groupid, r.categoryid, r.name, r.searchname, + UNIX_TIMESTAMP(r.postdate) AS post_date, + r.id AS releaseid + FROM releases r + WHERE r.isrenamed = 0 + AND r.prehashid = 0 + AND r.id = %d', $this->_release['id'] ) ); - if ($releaseInfo === false) { + if ($query === false) { return; } - // Only get a new name if the category is OTHER. - if ($releaseInfo['isrenamed'] == 0 && - in_array( - ((int)$this->_release['categoryid']), - Category::CAT_GROUP_OTHER - ) - ) { - $srr = $this->_SRRInfo->getSummary($fileLocation); + // Put the SRR into SrrInfo, check if there's an error. + $this->_srrInfo->open($srr); + if ($this->_srrInfo->error) { + $this->pdo->log->doEcho($this->pdo->log->primaryOver("-")); + return; + } - if ($this->_SRRInfo->error) { - return; + // Get the file list from SrrInfo. + $summary = $this->_srrInfo->getSummary(); + if ($summary !== false && empty($summary['error'])) { + $this->pdo->log->doEcho($this->pdo->log->primaryOver("+")); + + // Try to get a Pre Match by the OSO release name. + if (isset($summary['oso_info']['name']) && !empty($summary['oso_info']['name'])) { + $query['textstring'] = $summary['oso_info']['name']; + $foundMatch = $this->_nameFixer->checkName($query, $this->_echoCLI, 'SRR, ', 1, 1, true); } - - // Try to get a new name. - $this->_release['textstring'] = $srr['file_name']; - $this->_release['releaseid'] = $this->_release['id']; - if ($this->_nameFixer->checkName($this->_release, ($this->_echoCLI ? true : false), 'SRR, ', 1, 1) === true) { - $this->_foundSRRInfo = true; + // Loop through the stored files in the SRR and try to get a Pre Match + if ($foundMatch === false && is_array($summary['stored_files']) && !empty($summary['stored_files'])) { + foreach ($summary['stored_files'] AS $storedFile) { + if ($foundMatch === true) { + break; + } else if (isset($storedFile['name']) && !empty($storedFile['name'])) { + $query['textstring'] = Utility::cutStringUsingLast('.', $storedFile['name'], 'left', false); + $foundMatch = $this->_nameFixer->checkName($query, $this->_echoCLI, 'SRR, ', 1, 1, true); + } + } + } + // This field is rarely populated but worth a shot for a rename + if ($foundMatch === false && isset($summary['file_name']) && !empty($summary['file_name'])) { + $query['textstring'] = Utility::cutStringUsingLast('.', $summary['file_name'], 'left', false); + $foundMatch = $this->_nameFixer->checkName($query, $this->_echoCLI, 'SRR, ', 1, 1, true); } } + $this->_foundSRRInfo = $foundMatch; } /**