/** * Attempt to find NFO files inside the NZB's of releases. * * @param object $nntp Instance of class NNTP. * @param string $groupID (optional) Group id. * @param string $guidChar (optional) First character of the release GUID (used for multi-processing). * @param int $processImdb (optional) Attempt to find IMDB id's in the NZB? * @param int $processTvrage (optional) Attempt to find TvRage id's in the NZB? * * @return int How many NFO's were processed? * * @access public */ public function processNfoFiles($nntp, $groupID = '', $guidChar = '', $processImdb = 1, $processTvrage = 1) { $ret = 0; $guidCharQuery = $guidChar === '' ? '' : 'AND r.guid ' . $this->pdo->likeString($guidChar, false, true); $groupIDQuery = $groupID === '' ? '' : 'AND r.groupid = ' . $groupID; $optionsQuery = self::NfoQueryString($this->pdo); $res = $this->pdo->query(sprintf(' SELECT r.id, r.guid, r.groupid, r.name FROM releases r WHERE 1=1 %s %s %s ORDER BY r.nfostatus ASC, r.postdate DESC LIMIT %d', $optionsQuery, $guidCharQuery, $groupIDQuery, $this->nzbs)); $nfoCount = count($res); if ($nfoCount > 0) { $this->pdo->log->doEcho($this->pdo->log->primary(PHP_EOL . ($guidChar === '' ? '' : '[' . $guidChar . '] ') . ($groupID === '' ? '' : '[' . $groupID . '] ') . 'Processing ' . $nfoCount . ' NFO(s), starting at ' . $this->nzbs . ' * = hidden NFO, + = NFO, - = no NFO, f = download failed.')); if ($this->echo) { // Get count of releases per nfo status $nfoStats = $this->pdo->queryDirect(sprintf(' SELECT r.nfostatus AS status, COUNT(*) AS count FROM releases r WHERE 1=1 %s %s %s GROUP BY r.nfostatus ORDER BY r.nfostatus ASC', $optionsQuery, $guidCharQuery, $groupIDQuery)); if ($nfoStats instanceof Traversable) { $outString = PHP_EOL . 'Available to process'; foreach ($nfoStats as $row) { $outString .= ', ' . $row['status'] . ' = ' . number_format($row['count']); } $this->pdo->log->doEcho($this->pdo->log->header($outString . '.')); } } $groups = new Groups(['Settings' => $this->pdo]); $nzbContents = new NZBContents(['Echo' => $this->echo, 'NNTP' => $nntp, 'Nfo' => $this, 'Settings' => $this->pdo, 'PostProcess' => new PostProcess(['Echo' => $this->echo, 'Nfo' => $this, 'Settings' => $this->pdo])]); $movie = new Movie(['Echo' => $this->echo, 'Settings' => $this->pdo]); $tvRage = new TvRage(['Echo' => $this->echo, 'Settings' => $this->pdo]); foreach ($res as $arr) { $fetchedBinary = $nzbContents->getNFOfromNZB($arr['guid'], $arr['id'], $arr['groupid'], $groups->getByNameByID($arr['groupid'])); if ($fetchedBinary !== false) { // Insert nfo into database. $cp = 'COMPRESS(%s)'; $nc = $this->pdo->escapeString($fetchedBinary); $ckreleaseid = $this->pdo->queryOneRow(sprintf('SELECT id FROM releasenfo WHERE releaseid = %d', $arr['id'])); if (!isset($ckreleaseid['id'])) { $this->pdo->queryInsert(sprintf('INSERT INTO releasenfo (nfo, releaseid) VALUES (' . $cp . ', %d)', $nc, $arr['id'])); } $this->pdo->queryExec(sprintf('UPDATE releases SET nfostatus = %d WHERE id = %d', self::NFO_FOUND, $arr['id'])); $ret++; $movie->doMovieUpdate($fetchedBinary, 'nfo', $arr['id'], $processImdb); // If set scan for tvrage info. if ($processTvrage == 1) { $rageId = $this->parseRageId($fetchedBinary); if ($rageId !== false) { $show = $tvRage->parseNameEpSeason($arr['name']); if (is_array($show) && $show['name'] != '') { // Update release with season, ep, and air date info (if available) from release title. $tvRage->updateEpInfo($show, $arr['id']); $rid = $tvRage->getByRageID($rageId); if (!$rid) { $tvrShow = $tvRage->getRageInfoFromService($rageId); $tvRage->updateRageInfo($rageId, $show, $tvrShow, $arr['id']); } } } } } } } // Remove nfo that we cant fetch after 5 attempts. $releases = $this->pdo->queryDirect(sprintf('SELECT r.id FROM releases r WHERE r.nzbstatus = %d AND r.nfostatus < %d %s %s', NZB::NZB_ADDED, $this->maxRetries, $groupIDQuery, $guidCharQuery)); if ($releases instanceof Traversable) { foreach ($releases as $release) { $this->pdo->queryExec(sprintf('DELETE FROM releasenfo WHERE nfo IS NULL AND releaseid = %d', $release['id'])); } } // Set releases with no NFO. $this->pdo->queryExec(sprintf(' UPDATE releases r SET r.nfostatus = %d WHERE r.nzbstatus = %d AND r.nfostatus < %d %s %s', self::NFO_FAILED, NZB::NZB_ADDED, $this->maxRetries, $groupIDQuery, $guidCharQuery)); if ($this->echo) { if ($nfoCount > 0) { echo PHP_EOL; } if ($ret > 0) { $this->pdo->log->doEcho($ret . ' NFO file(s) found/processed.', true); } } return $ret; }
} else { $db->queryExec(sprintf("UPDATE releases SET dehashstatus = %d - 1 WHERE id = %d", $res['dehashstatus'], $res['releaseid'])); echo '.'; } } } } else { if (isset($pieces[1]) && $pieces[0] == 'par2') { $nntp = new NNTP(); if ($nntp->doConnect() === false) { exit($c->error("Unable to connect to usenet.")); } $relID = $pieces[1]; $guid = $pieces[2]; $groupID = $pieces[3]; $nzbcontents = new NZBContents(array('echo' => true, 'nntp' => $nntp, 'nfo' => new Info(), 'db' => $db, 'pp' => new PProcess(['Settings' => $pdo, 'Nfo' => $Nfo, 'NameFixer' => $namefixer]))); $res = $nzbcontents->checkPAR2($guid, $relID, $groupID, 1, 1); if ($res === false) { echo '.'; } $nntp->doQuit(); } else { if (isset($pieces[1]) && $pieces[0] == 'predbft') { $pre = $pieces[1]; if ($res = $db->queryOneRow(sprintf('SELECT id AS preid, title, source, searched FROM prehash ' . 'WHERE id = %d', $pre))) { $namefixer->done = $namefixer->matched = false; $ftmatched = $searched = 0; $ftmatched = $namefixer->matchPredbFT($res, 1, 1, true, 1); if ($ftmatched > 0) { $searched = 1; } elseif ($ftmatched < 0) {
/** * Attempts to fix release names using the Par2 File. * * @param int $time 1: 24 hours, 2: no time limit * @param int $echo 1: change the name, anything else: preview of what could have been changed. * @param int $cats 1: other categories, 2: all categories * @param $nameStatus * @param $show * @param NNTP $nntp */ public function fixNamesWithPar2($time, $echo, $cats, $nameStatus, $show, $nntp) { $this->_echoStartMessage($time, 'par2 files'); if ($cats === 3) { $query = sprintf(' SELECT rel.id AS releaseid, rel.guid, rel.groupid FROM releases rel WHERE nzbstatus = %d AND prehashid = 0', Enzebe::NZB_ADDED); $cats = 2; } else { $query = sprintf(' SELECT rel.id AS releaseid, rel.guid, rel.groupid FROM releases rel WHERE (isrenamed = %d OR rel.categoryid = %d) AND proc_par2 = %d', self::IS_RENAMED_NONE, Category::CAT_MISC_OTHER, self::PROC_PAR2_NONE); } $releases = $this->_getReleases($time, $cats, $query); if ($releases instanceof Traversable && $releases !== false) { $total = $releases->rowCount(); if ($total > 0) { $this->_totalReleases = $total; echo $this->pdo->log->primary(number_format($total) . ' releases to process.'); $Nfo = new Nfo(['Echo' => $this->echooutput, 'Settings' => $this->pdo]); $nzbContents = new NZBContents(['Echo' => $this->echooutput, 'NNTP' => $nntp, 'Nfo' => $Nfo, 'Settings' => $this->pdo, 'PostProcess' => new PostProcess(['Settings' => $this->pdo, 'Nfo' => $Nfo])]); foreach ($releases as $release) { if ($nzbContents->checkPAR2($release['guid'], $release['releaseid'], $release['groupid'], $nameStatus, $show) === true) { $this->fixed++; } $this->checked++; $this->_echoRenamed($show); } $this->_echoFoundCount($echo, ' files'); } else { echo $this->pdo->log->alternate('Nothing to fix.'); } } }
$releases = $pdo->queryDirect(sprintf(' SELECT r.id AS releaseid, r.guid, r.group_id FROM releases r WHERE r.guid %s AND r.nzbstatus = 1 AND r.proc_par2 = 0 AND r.preid = 0 ORDER BY r.postdate ASC LIMIT %s', $pdo->likeString($guidChar, false, true), $maxperrun)); if ($releases instanceof Traversable) { $nntp = new NNTP(['Settings' => $pdo]); if (($pdo->getSetting('alternate_nntp') == '1' ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) { exit($pdo->log->error("Unable to connect to usenet.")); } $Nfo = new Nfo(['Settings' => $pdo, 'Echo' => true]); $nzbcontents = new NZBContents(array('Echo' => true, 'NNTP' => $nntp, 'Nfo' => $Nfo, 'Settings' => $pdo, 'PostProcess' => new PostProcess(['Settings' => $pdo, 'Nfo' => $Nfo, 'NameFixer' => $namefixer]))); foreach ($releases as $release) { $res = $nzbcontents->checkPAR2($release['guid'], $release['releaseid'], $release['group_id'], 1, 1); if ($res === false) { echo '.'; } } } break; case $pieces[0] === 'miscsorter' && isset($guidChar) && isset($maxperrun) && is_numeric($maxperrun): $releases = $pdo->queryDirect(sprintf(' SELECT r.id AS releaseid FROM releases r WHERE r.guid %s AND r.nzbstatus = 1 AND r.nfostatus = 1 AND r.proc_sorter = 0 AND r.isrenamed = 0
if (!is_dir($tmpPath)) { $old = umask(0777); @mkdir($tmpPath, 0777, true); @chmod($tmpPath, 0777); @umask($old); if (!is_dir($tmpPath)) { exit('Unable to create temp directory:' . $tmpPath . PHP_EOL); } } $unrarPath = $pdo->getSetting('unrarpath'); if (empty($unrarPath)) { exit('The site setting for the unrar path must not be empty!' . PHP_EOL); } $nntp = new NNTP(['Settings' => $pdo]); $nfo = new Nfo(['Echo' => true, 'Settings' => $pdo]); $nzbContents = new NZBContents(array('Settings' => $pdo, 'Echo' => true, 'Nfo' => $nfo, 'PostProcess' => new PostProcess(['Settings' => $pdo, 'Nfo' => $nfo]), 'NNTP' => $nntp)); $categorize = new Categorize(['Settings' => $pdo]); $releases = $pdo->queryDirect(sprintf(' SELECT rf.name AS filename, r.categoryid, r.name, r.guid, r.id, r.group_id, r.postdate, r.searchname AS oldname, g.name AS groupname FROM releasefiles rf INNER JOIN releases r ON rf.releaseid = r.id INNER JOIN groups g ON r.group_id = g.id WHERE (r.isrenamed = 0 OR r.categoryid = 7020) AND r.passwordstatus = 0 AND rf.name %s ORDER BY r.postdate DESC', $pdo->likeString('Linux_2rename.sh'))); if ($releases instanceof Traversable) { $nntp->doConnect(); $sphinx = new SphinxSearch(); foreach ($releases as $release) { // Clear old files.