/** * Queues anime releases for processing */ public function processAnimeReleases() { $results = $this->pdo->queryDirect(sprintf(' SELECT searchname, id FROM releases WHERE nzbstatus = %d AND anidbid IS NULL AND categoryid = %d ORDER BY postdate DESC LIMIT %d', NZB::NZB_ADDED, Category::CAT_TV_ANIME, $this->aniqty)); if ($results instanceof \Traversable) { $this->doRandomSleep(); $this->padb = new \nzedb\db\populate\AniDB(['Echo' => $this->echooutput, 'Settings' => $this->pdo]); foreach ($results as $release) { $matched = $this->matchAnimeRelease($release); if ($matched === false) { $this->pdo->queryExec(sprintf(' UPDATE releases SET anidbid = %d WHERE id = %d', $this->status, $release['id'])); } } } else { $this->pdo->log->doEcho($this->pdo->log->info("No work to process."), true); } }
public function processGamesReleases() { $res = $this->pdo->queryDirect(sprintf(' SELECT searchname, id FROM releases WHERE nzbstatus = 1 %s AND gamesinfo_id = 0 AND categoryid = 4050 ORDER BY postdate DESC LIMIT %d', $this->renamed, $this->gameQty)); if ($res instanceof \Traversable && $res->rowCount() > 0) { if ($this->echoOutput) { $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $res->rowCount() . ' games release(s).')); } foreach ($res as $arr) { // Reset maxhitrequest $this->maxHitRequest = false; $startTime = microtime(true); $usedgb = false; $gameInfo = $this->parseTitle($arr['searchname']); if ($gameInfo !== false) { if ($this->echoOutput) { $this->pdo->log->doEcho($this->pdo->log->headerOver('Looking up: ') . $this->pdo->log->primary($gameInfo['title'] . ' (PC)')); } // Check for existing games entry. $gameCheck = $this->getGamesInfoByName($gameInfo['title']); if ($gameCheck === false) { $gameId = $this->updateGamesInfo($gameInfo); $usedgb = true; if ($gameId === false) { $gameId = -2; // Leave gamesinfo_id 0 to parse again if ($this->maxHitRequest === true) { $gameId = 0; } } } else { $gameId = $gameCheck['id']; } // Update release. $this->pdo->queryExec(sprintf('UPDATE releases SET gamesinfo_id = %d WHERE id = %d', $gameId, $arr['id'])); } else { // Could not parse release title. $this->pdo->queryExec(sprintf('UPDATE releases SET gamesinfo_id = %d WHERE id = %d', -2, $arr['id'])); if ($this->echoOutput) { echo '.'; } } // Sleep to not flood giantbomb. $diff = floor((microtime(true) - $startTime) * 1000000); if ($this->sleepTime * 1000 - $diff > 0 && $usedgb === true) { usleep($this->sleepTime * 1000 - $diff); } } } else { if ($this->echoOutput) { $this->pdo->log->doEcho($this->pdo->log->header('No games releases to process.')); } } }
/** * Match added comments to releases. * * @access protected */ protected function matchComments() { $res = $this->pdo->query(' SELECT r.id, r.nzb_guid FROM releases r INNER JOIN release_comments rc ON rc.nzb_guid = r.nzb_guid WHERE rc.releaseid = 0'); $found = count($res); if ($found > 0) { foreach ($res as $row) { $this->pdo->queryExec(sprintf("UPDATE release_comments SET releaseid = %d WHERE nzb_guid = %s", $row['id'], $this->pdo->escapeString($row['nzb_guid']))); $this->pdo->queryExec(sprintf('UPDATE releases SET comments = comments + 1 WHERE id = %d', $row['id'])); } if (nZEDb_ECHOCLI) { echo '(Sharing) Matched ' . $found . ' comments.' . PHP_EOL; } } // Update first time seen. $siteTimes = $this->pdo->queryDirect('SELECT createddate, siteid FROM release_comments WHERE createddate > \'2005-01-01\' GROUP BY siteid ORDER BY createddate ASC'); if ($siteTimes instanceof \Traversable && $siteTimes->rowCount()) { foreach ($siteTimes as $site) { $this->pdo->queryExec(sprintf('UPDATE sharing_sites SET first_time = %s WHERE site_guid = %s', $this->pdo->escapeString($site['createddate']), $this->pdo->escapeString($site['siteid']))); } } }
public function add($form) { $content = $this->row2Object($form); $content = $this->validate($content); if ($content->ordinal == 1) { $this->pdo->queryDirect("UPDATE content SET ordinal = ordinal + 1 WHERE ordinal > 0"); } return $this->data_add($content); }
/** * @param bool $local */ public function processMusicReleases($local = false) { $res = $this->pdo->queryDirect(sprintf('SELECT searchname, id FROM releases ' . 'WHERE musicinfoid IS NULL AND nzbstatus = 1 %s AND categoryid IN (3010, 3040, 3050) ' . 'ORDER BY postdate DESC LIMIT %d', $this->renamed, $this->musicqty)); if ($res instanceof \Traversable && $res->rowCount() > 0) { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $res->rowCount() . ' music release(s).')); } foreach ($res as $arr) { $startTime = microtime(true); $usedAmazon = false; $album = $this->parseArtist($arr['searchname']); if ($album !== false) { $newname = $album["name"] . ' (' . $album["year"] . ')'; if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->headerOver('Looking up: ') . $this->pdo->log->primary($newname)); } // Do a local lookup first $musicCheck = $this->getMusicInfoByName('', $album["name"]); if ($musicCheck === false && in_array($album['name'] . $album['year'], $this->failCache)) { // Lookup recently failed, no point trying again if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->headerOver('Cached previous failure. Skipping.') . PHP_EOL); } $albumId = -2; } else { if ($musicCheck === false && $local === false) { $albumId = $this->updateMusicInfo($album['name'], $album['year']); $usedAmazon = true; if ($albumId === false) { $albumId = -2; $this->failCache[] = $album['name'] . $album['year']; } } else { $albumId = $musicCheck['id']; } } // Update release. $this->pdo->queryExec(sprintf("UPDATE releases SET musicinfoid = %d WHERE id = %d", $albumId, $arr["id"])); } else { $this->pdo->queryExec(sprintf("UPDATE releases SET musicinfoid = %d WHERE id = %d", -2, $arr["id"])); echo '.'; } // Sleep to not flood amazon. $diff = floor((microtime(true) - $startTime) * 1000000); if ($this->sleeptime * 1000 - $diff > 0 && $usedAmazon === true) { usleep($this->sleeptime * 1000 - $diff); } } if ($this->echooutput) { echo "\n"; } } else { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header('No music releases to process.')); } } }
/** * Get movie releases with covers for movie browse page. * * @param $cat * @param $start * @param $num * @param $orderBy * @param $maxAge * @param array $excludedCats * * @return bool|\PDOStatement */ public function getMovieRange($cat, $start, $num, $orderBy, $maxAge = -1, $excludedCats = []) { $catsrch = ''; if (count($cat) > 0 && $cat[0] != -1) { $catsrch = (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat); } $order = $this->getMovieOrder($orderBy); $sql = sprintf("\n\t\t\tSELECT\n\t\t\tGROUP_CONCAT(r.id ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_id,\n\t\t\tGROUP_CONCAT(r.rarinnerfilecount ORDER BY r.postdate DESC SEPARATOR ',') as grp_rarinnerfilecount,\n\t\t\tGROUP_CONCAT(r.haspreview ORDER BY r.postdate DESC SEPARATOR ',') AS grp_haspreview,\n\t\t\tGROUP_CONCAT(r.passwordstatus ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_password,\n\t\t\tGROUP_CONCAT(r.guid ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_guid,\n\t\t\tGROUP_CONCAT(rn.id ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_nfoid,\n\t\t\tGROUP_CONCAT(groups.name ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_grpname,\n\t\t\tGROUP_CONCAT(r.searchname ORDER BY r.postdate DESC SEPARATOR '#') AS grp_release_name,\n\t\t\tGROUP_CONCAT(r.postdate ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_postdate,\n\t\t\tGROUP_CONCAT(r.size ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_size,\n\t\t\tGROUP_CONCAT(r.totalpart ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_totalparts,\n\t\t\tGROUP_CONCAT(r.comments ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_comments,\n\t\t\tGROUP_CONCAT(r.grabs ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_grabs,\n\t\t\tm.*, groups.name AS group_name, rn.id as nfoid FROM releases r\n\t\t\tLEFT OUTER JOIN groups ON groups.id = r.group_id\n\t\t\tLEFT OUTER JOIN release_nfos rn ON rn.releaseid = r.id\n\t\t\tINNER JOIN movieinfo m ON m.imdbid = r.imdbid\n\t\t\tWHERE r.nzbstatus = 1 AND r.imdbid != '0000000'\n\t\t\tAND m.title != ''\n\t\t\tAND r.passwordstatus <= %d AND %s %s %s %s\n\t\t\tGROUP BY m.imdbid ORDER BY %s %s %s", $this->showPasswords, $this->getBrowseBy(), $catsrch, $maxAge > 0 ? 'AND r.postdate > NOW() - INTERVAL ' . $maxAge . 'DAY ' : '', count($excludedCats) > 0 ? ' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')' : '', $order[0], $order[1], $start === false ? '' : ' LIMIT ' . $num . ' OFFSET ' . $start); return $this->pdo->queryDirect($sql); }
public function processConsoleReleases() { $res = $this->pdo->queryDirect(sprintf(' SELECT searchname, id FROM releases WHERE nzbstatus = %d %s AND consoleinfoid IS NULL AND categoryid BETWEEN 1000 AND 1999 ORDER BY postdate DESC LIMIT %d', NZB::NZB_ADDED, $this->renamed, $this->gameqty)); if ($res instanceof Traversable && $res->rowCount() > 0) { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $res->rowCount() . ' console release(s).')); } foreach ($res as $arr) { $startTime = microtime(true); $usedAmazon = false; $gameId = self::CONS_NTFND; $gameInfo = $this->parseTitle($arr['searchname']); if ($gameInfo !== false) { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->headerOver('Looking up: ') . $this->pdo->log->primary($gameInfo['title'] . ' (' . $gameInfo['platform'] . ')')); } // Check for existing console entry. $gameCheck = $this->getConsoleInfoByName($gameInfo['title'], $gameInfo['platform']); if ($gameCheck === false) { $gameId = $this->updateConsoleInfo($gameInfo); $usedAmazon = true; } else { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->headerOver("Found Local: ") . $this->pdo->log->primary("{$gameCheck['title']} - {$gameCheck['platform']}") . PHP_EOL); } $gameId = $gameCheck['id']; } } elseif ($this->echooutput) { echo '.'; } // Update release. $this->pdo->queryExec(sprintf(' UPDATE releases SET consoleinfoid = %d WHERE id = %d', $gameId, $arr['id'])); // Sleep to not flood amazon. $diff = floor((microtime(true) - $startTime) * 1000000); if ($this->sleeptime * 1000 - $diff > 0 && $usedAmazon === true) { usleep($this->sleeptime * 1000 - $diff); } } } else { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header('No console releases to process.')); } } }
/** * Retrieves a list of Anime titles, optionally filtered by starting character and title * * @param string $letter * @param string $animetitle * @return array|bool */ public function getAnimeList($letter = '', $animetitle = '') { $regex = 'REGEXP'; $rsql = ''; if ($letter != '') { if ($letter == '0-9') { $letter = '[0-9]'; } $rsql .= sprintf('AND at.title %s %s', $regex, $this->pdo->escapeString('^' . $letter)); } $tsql = ''; if ($animetitle != '') { $tsql .= sprintf('AND at.title %s', $this->pdo->likeString($animetitle, true, true)); } return $this->pdo->queryDirect(sprintf('SELECT at.anidbid, at.title, ai.type, ai.categories, ai.rating, ai.startdate, ai.enddate FROM anidb_titles AS at LEFT JOIN anidb_info AS ai USING (anidbid) WHERE at.anidbid > 0 %s %s GROUP BY at.anidbid ORDER BY at.title ASC', $rsql, $tsql)); }
/** * Purge a single group or all groups. * * @param int|string|bool $id The group ID. If false, purge all groups. */ public function purge($id = false) { if ($id === false) { $this->resetall(); } else { $this->reset($id); } $releaseArray = $this->pdo->queryDirect(sprintf("SELECT id, guid FROM releases %s", $id === false ? '' : 'WHERE group_id = ' . $id)); if ($releaseArray instanceof \Traversable) { $releases = new Releases(['Settings' => $this->pdo, 'Groups' => $this]); $nzb = new NZB($this->pdo); $releaseImage = new ReleaseImage($this->pdo); foreach ($releaseArray as $release) { $releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $nzb, $releaseImage); } } }
/** * Write an NZB to the hard drive for a single release. * * @param int $relID The ID of the release in the DB. * @param string $relGuid The guid of the release. * @param string $name The name of the release. * @param string $cTitle The name of the category this release is in. * * @return bool Have we successfully written the NZB to the hard drive? * * @access public */ public function writeNZBforReleaseId($relID, $relGuid, $name, $cTitle) { $path = $this->buildNZBPath($relGuid, $this->nzbSplitLevel, true) . $relGuid . '.nzb.gz'; $fp = gzopen($path, 'wb7'); if ($fp) { $nzb_guid = ''; gzwrite($fp, sprintf($this->_nzbHeadString, htmlspecialchars($cTitle, ENT_QUOTES, 'utf-8'), htmlspecialchars($name, ENT_QUOTES, 'utf-8'))); $collections = $this->pdo->queryDirect($this->_collectionsQuery . $relID); if ($collections instanceof \Traversable) { foreach ($collections as $collection) { $poster = htmlspecialchars($collection['fromname'], ENT_QUOTES, 'utf-8'); $binaries = $this->pdo->queryDirect(sprintf($this->_binariesQuery, $collection['id'])); if ($binaries instanceof \Traversable) { foreach ($binaries as $binary) { // Buffer segment writes, increases performance. $string = ''; $parts = $this->pdo->queryDirect(sprintf($this->_partsQuery, $binary['id'])); if ($parts instanceof \Traversable) { foreach ($parts as $part) { if ($nzb_guid === '') { $nzb_guid = $part['messageid']; } $string .= ' <segment bytes="' . $part['size'] . '" number="' . $part['partnumber'] . '">' . htmlspecialchars($part['messageid'], ENT_QUOTES, 'utf-8') . "</segment>\n"; } } gzwrite($fp, '<file poster="' . $poster . '" date="' . $collection['udate'] . '" subject="' . htmlspecialchars($binary['name'], ENT_QUOTES, 'utf-8') . ' (1/' . $binary['totalparts'] . ")\">\n <groups>\n <group>" . $collection['groupname'] . "</group>\n </groups>\n <segments>\n" . $string . " </segments>\n</file>\n"); } } } } gzwrite($fp, '</nzb>'); gzclose($fp); if (is_file($path)) { // Mark release as having NZB and delete CBP. $this->pdo->queryExec(sprintf(' UPDATE releases SET nzbstatus = %d %s WHERE id = %d; DELETE c, b, p FROM %s c JOIN %s b ON(c.id=b.collection_id) STRAIGHT_JOIN %s p ON(b.id=p.binaryid) WHERE c.releaseid = %d', NZB::NZB_ADDED, $nzb_guid === '' ? '' : ', nzb_guid = UNHEX( ' . $this->pdo->escapestring(md5($nzb_guid)) . ' )', $relID, $this->_tableNames['cName'], $this->_tableNames['bName'], $this->_tableNames['pName'], $relID)); // Chmod to fix issues some users have with file permissions. chmod($path, 0777); return true; } else { echo "ERROR: {$path} does not exist.\n"; } } return false; }
public function getPreFileNames($args = []) { $timestart = time(); $counter = $counted = 0; $limit = $orderby = ''; $show = isset($args[2]) && $args[2] === 'show' ? 1 : 0; if (isset($args[1]) && is_numeric($args[1])) { $orderby = "ORDER BY r.id DESC"; $limit = "LIMIT " . $args[1]; } echo $this->pdo->log->header("\nMatch PreFiles ({$args[1]}) Started at " . date('g:i:s')); echo $this->pdo->log->primary("Matching predb filename to cleaned release_files.name.\n"); $query = $this->pdo->queryDirect(sprintf(' SELECT r.id AS releaseid, r.name, r.searchname, r.group_id, r.categoryid, rf.name AS filename FROM releases r INNER JOIN release_files rf ON r.id = rf.releaseid AND rf.name IS NOT NULL WHERE r.preid = 0 GROUP BY r.id %s %s', $orderby, $limit)); if ($query !== false) { $total = $query->rowCount(); if ($total > 0 && $query instanceof \Traversable) { echo $this->pdo->log->header("\n" . number_format($total) . ' releases to process.'); foreach ($query as $row) { $success = $this->matchPredbFiles($row, 1, 1, true, $show); if ($success === 1) { $counted++; } if ($show === 0) { $this->consoletools->overWritePrimary("Renamed Releases: [" . number_format($counted) . "] " . $this->consoletools->percentString(++$counter, $total)); } } echo $this->pdo->log->header("\nRenamed " . number_format($counted) . " releases in " . $this->consoletools->convertTime(TIME() - $timestart) . "."); } else { echo $this->pdo->log->info("\nNothing to do."); } } }
/** * @note Post comment for the release if that release has no comment for failure. * Only one user is allowed to post comment for that release, rest will just * update the failed count in dnzb_failures table * * @param $relid * @param $uid */ public function postComment($relid, $uid) { $dupe = 0; $text = 'This release has failed to download properly. It might fail for other users too. This comment is automatically generated.'; $check = $this->pdo->queryDirect(sprintf(' SELECT text FROM release_comments WHERE releaseid = %d', $relid)); if ($check instanceof \Traversable) { foreach ($check as $dbl) { if ($dbl['text'] == $text) { $dupe = 1; break; } } } if ($dupe === 0) { $this->rc->addComment($relid, $text, $uid, ''); } }
/** * Process book releases, 1 category at a time. */ public function processBookReleases() { $bookids = []; if (preg_match('/^\\d+$/', $this->bookreqids)) { $bookids[] = $this->bookreqids; } else { $bookids = explode(', ', $this->bookreqids); } $total = count($bookids); if ($total > 0) { for ($i = 0; $i < $total; $i++) { $this->processBookReleasesHelper($this->pdo->queryDirect(sprintf(' SELECT searchname, id, categoryid FROM releases WHERE nzbstatus = 1 %s AND bookinfoid IS NULL AND categoryid in (%s) ORDER BY postdate DESC LIMIT %d', $this->renamed, $bookids[$i], $this->bookqty)), $bookids[$i]); } } }
exit($pdo->log->error("This script is not intended to be run manually, it is called from groupfixrelnames_threaded.py.")); } else { if (isset($argv[1])) { $namefixer = new NameFixer(['Settings' => $pdo]); $pieces = explode(' ', $argv[1]); $guidChar = $pieces[1]; $maxperrun = $pieces[2]; $thread = $pieces[3]; switch (true) { case $pieces[0] === 'nfo' && isset($guidChar) && isset($maxperrun) && is_numeric($maxperrun): $releases = $pdo->queryDirect(sprintf(' SELECT r.id AS releaseid, r.guid, r.group_id, r.categoryid, r.name, r.searchname, uncompress(nfo) AS textstring FROM releases r INNER JOIN release_nfos rn ON r.id = rn.releaseid WHERE r.guid %s AND r.nzbstatus = 1 AND r.proc_nfo = 0 AND r.nfostatus = 1 AND r.preid = 0 ORDER BY r.postdate DESC LIMIT %s', $pdo->likeString($guidChar, false, true), $maxperrun)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { if (preg_match('/^=newz\\[NZB\\]=\\w+/', $release['textstring'])) { $namefixer->done = $namefixer->matched = false; $pdo->queryDirect(sprintf('UPDATE releases SET proc_nfo = 1 WHERE id = %d', $release['releaseid'])); $namefixer->checked++; echo '.'; } else { $namefixer->done = $namefixer->matched = false; if ($namefixer->checkName($release, true, 'NFO, ', 1, 1) !== true) {
exit($pdo->log->error("\nThis script will check all images in covers/xxx and compare to db->xxxinfo.\nTo run:\nphp {$argv['0']} true\n")); } $row = $pdo->queryOneRow("SELECT value FROM settings WHERE setting = 'coverspath'"); if ($row !== false) { \nzedb\utility\Utility::setCoversConstant($row['value']); } else { die("Unable to set Covers' constant!\n"); } $path2covers = nZEDb_COVERS . 'xxx' . DS; $dirItr = new RecursiveDirectoryIterator($path2covers); $itr = new RecursiveIteratorIterator($dirItr, RecursiveIteratorIterator::LEAVES_ONLY); foreach ($itr as $filePath) { if (is_file($filePath) && preg_match('/-cover\\.jpg/', $filePath)) { preg_match('/(\\d+)-cover\\.jpg/', basename($filePath), $match); if (isset($match[1])) { $run = $pdo->queryDirect("UPDATE xxxinfo SET cover = 1 WHERE cover = 0 AND id = " . $match[1]); if ($run->rowCount() >= 1) { $covers++; } else { $run = $pdo->queryDirect("SELECT id FROM xxxinfo WHERE id = " . $match[1]); if ($run->rowCount() == 0) { echo $pdo->log->info($filePath . " not found in db."); } } } } if (is_file($filePath) && preg_match('/-backdrop\\.jpg/', $filePath)) { preg_match('/(\\d+)-backdrop\\.jpg/', basename($filePath), $match1); if (isset($match1[1])) { $run = $pdo->queryDirect("UPDATE xxxinfo SET backdrop = 1 WHERE backdrop = 0 AND id = " . $match1[1]); if ($run->rowCount() >= 1) {
function create_guids($live, $delete = false) { $pdo = new Settings(); $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); $timestart = TIME(); $relcount = $deleted = $total = 0; $relrecs = false; if ($live == "true") { $relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC")); } else { if ($live == "limited") { $relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC LIMIT 10000")); } } if ($relrecs) { $total = $relrecs->rowCount(); } if ($total > 0) { echo $pdo->log->header("Creating nzb_guids for " . number_format($total) . " releases."); $releases = new Releases(['Settings' => $pdo]); $nzb = new NZB($pdo); $releaseImage = new ReleaseImage($pdo); $reccnt = 0; if ($relrecs instanceof Traversable) { foreach ($relrecs as $relrec) { $reccnt++; $nzbpath = $nzb->NZBPath($relrec['guid']); if ($nzbpath !== false) { $nzbfile = nzedb\utility\Utility::unzipGzipFile($nzbpath); if ($nzbfile) { $nzbfile = @simplexml_load_string($nzbfile); } if (!$nzbfile) { if (isset($delete) && $delete == 'delete') { //echo "\n".$nzb->NZBPath($relrec['guid'])." is not a valid xml, deleting release.\n"; $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage); $deleted++; } continue; } $binary_names = array(); foreach ($nzbfile->file as $file) { $binary_names[] = $file["subject"]; } if (count($binary_names) == 0) { if (isset($delete) && $delete == 'delete') { //echo "\n".$nzb->NZBPath($relrec['guid'])." has no binaries, deleting release.\n"; $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage); $deleted++; } continue; } asort($binary_names); foreach ($nzbfile->file as $file) { if ($file["subject"] == $binary_names[0]) { $segment = $file->segments->segment; $nzb_guid = md5($segment); $pdo->queryExec("UPDATE releases set nzb_guid = " . $pdo->escapestring($nzb_guid) . " WHERE id = " . $relrec["id"]); $relcount++; $consoletools->overWritePrimary("Created: [" . $deleted . "] " . $consoletools->percentString($reccnt, $total) . " Time:" . $consoletools->convertTimer(TIME() - $timestart)); break; } } } else { if (isset($delete) && $delete == 'delete') { //echo $pdo->log->primary($nzb->NZBPath($relrec['guid']) . " does not have an nzb, deleting."); $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage); } } } } if ($relcount > 0) { echo "\n"; } echo $pdo->log->header("Updated " . $relcount . " release(s). This script ran for " . $consoletools->convertTime(TIME() - $timestart)); } else { echo $pdo->log->info('Query time: ' . $consoletools->convertTime(TIME() - $timestart)); exit($pdo->log->info("No releases are missing the guid.")); } }
if (!preg_match('/\\.csv$/', $path)) { $path = dirname($path) . '/' . basename($path) . '/predb_dump.csv'; } if (!preg_match('/^\\//', $path)) { $path = getcwd() . '/' . $path; } if (file_exists($path) && is_file($path)) { unlink($path); } if (isset($argv[3])) { $table = $argv[3]; } else { $table = 'predb'; } echo $pdo->log->header("SELECT title, nfo, size, files, filename, nuked, nukereason, category, predate, source, requestid, g.name FROM " . $table . " p LEFT OUTER JOIN groups g ON p.group_id = g.id INTO OUTFILE '" . $path . "' FIELDS TERMINATED BY '\\t\\t' ENCLOSED BY \"'\" LINES TERMINATED BY '\\r\\n';n"); $pdo->queryDirect("SELECT title, nfo, size, files, filename, nuked, nukereason, category, predate, source, requestid, g.name FROM " . $table . " p LEFT OUTER JOIN groups g ON p.group_id = g.id INTO OUTFILE '" . $path . "' FIELDS TERMINATED BY '\t\t' ENCLOSED BY \"'\" LINES TERMINATED BY '\r\n'"); } else { if (isset($argv[1]) && ($argv[1] == 'local' || $argv[1] == 'remote') && isset($argv[2]) && is_file($argv[2])) { if (!preg_match('/^\\//', $path)) { $path = (require_once getcwd() . '/' . $argv[2]); } if (isset($argv[3])) { $table = $argv[3]; } else { $table = 'predb'; } // Truncate predb_imports to clear any old data $pdo->queryDirect("TRUNCATE TABLE predb_imports"); // Import file into predb_imports if ($argv[1] == 'remote') { echo $pdo->log->header("LOAD DATA LOCAL INFILE '" . $path . "' IGNORE into table predb_imports FIELDS TERMINATED BY '\\t\\t' ENCLOSED BY \"'\" LINES TERMINATED BY '\\r\\n' (title, nfo, size, files, filename, nuked, nukereason, category, predate, source, requestid, groupname);");
exit($pdo->log->error("\nThis script will check all images in covers/games and compare to db->gamesinfo.\nTo run:\nphp {$argv['0']} true\n")); } $row = $pdo->queryOneRow("SELECT value FROM settings WHERE setting = 'coverspath'"); if ($row !== false) { Misc::setCoversConstant($row['value']); } else { die("Unable to set Covers' constant!\n"); } $path2covers = nZEDb_COVERS . 'games' . DS; $dirItr = new \RecursiveDirectoryIterator($path2covers); $itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY); foreach ($itr as $filePath) { if (is_file($filePath) && preg_match('/\\d+\\.jpg/', $filePath)) { preg_match('/(\\d+)\\.jpg/', basename($filePath), $match); if (isset($match[1])) { $run = $pdo->queryDirect("UPDATE gamesinfo SET cover = 1 WHERE cover = 0 AND id = " . $match[1]); if ($run !== false) { if ($run->rowCount() >= 1) { $covers++; } else { $run = $pdo->queryDirect("SELECT id FROM gamesinfo WHERE id = " . $match[1]); if ($run !== false && $run->rowCount() == 0) { echo $pdo->log->info($filePath . " not found in db."); } } } } } } $qry = $pdo->queryDirect("SELECT id FROM gamesinfo WHERE cover = 1"); if ($qry instanceof \Traversable) {
$ran = true; $where = ''; if (isset($argv[3]) && $argv[3] === "truncate") { echo "Truncating tables\n"; $pdo->queryExec("TRUNCATE TABLE consoleinfo"); $pdo->queryExec("TRUNCATE TABLE gamesinfo"); $pdo->queryExec("TRUNCATE TABLE movieinfo"); $pdo->queryExec("TRUNCATE TABLE video_data"); $pdo->queryExec("TRUNCATE TABLE musicinfo"); $pdo->queryExec("TRUNCATE TABLE bookinfo"); $pdo->queryExec("TRUNCATE TABLE release_nfos"); $pdo->queryExec("TRUNCATE TABLE releaseextrafull"); $pdo->queryExec("TRUNCATE TABLE xxxinfo"); } echo $pdo->log->header("Resetting all postprocessing"); $qry = $pdo->queryDirect("SELECT id FROM releases"); $affected = 0; if ($qry instanceof \Traversable) { $total = $qry->rowCount(); foreach ($qry as $releases) { $pdo->queryExec(sprintf("\n\t\t\t\t\t\tUPDATE releases\n\t\t\t\t\t\tSET consoleinfoid = NULL, gamesinfo_id = 0, imdbid = NULL, musicinfoid = NULL,\n\t\t\t\t\t\t\tbookinfoid = NULL, rageid = -1, xxxinfo_id = 0, passwordstatus = -1, haspreview = -1,\n\t\t\t\t\t\t\tjpgstatus = 0, videostatus = 0, audiostatus = 0, nfostatus = -1\n\t\t\t\t\t\tWHERE id = %d", $releases['id'])); $consoletools->overWritePrimary("Resetting Releases: " . $consoletools->percentString(++$affected, $total)); } } } } if (isset($argv[1]) && ($argv[1] === "consoles" || $argv[1] === "all")) { $ran = true; if (isset($argv[3]) && $argv[3] === "truncate") { $pdo->queryExec("TRUNCATE TABLE consoleinfo"); }
* (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (see LICENSE.txt in the base directory. If * not, see: * * @link <http://www.gnu.org/licenses/>. * @author niel * @copyright 2014 nZEDb */ require_once dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php'; use nzedb\db\Settings; $pdo = new Settings(); if (!$pdo->getSetting('tablepergroup')) { exit("Tables per groups is not enabled, quitting!"); } // Doing it this way in case there are tables existing not related to the active/backfill list (i.e. I don't have a clue when these tables get deleted so I'm doing any that are there). $tables = $pdo->queryDirect("SELECT SUBSTR(TABLE_NAME, 12) AS suffix FROM information_schema.TABLES WHERE TABLE_SCHEMA = (SELECT DATABASE()) AND TABLE_NAME LIKE 'collections%' ORDER BY TABLE_NAME"); $query1 = "ALTER table collections%s add noise char(32) not null default '' after releaseid"; if ($tables instanceof \Traversable) { foreach ($tables as $table) { echo "Updating table collections{$table['suffix']}" . PHP_EOL; $pdo->queryExec(sprintf($query1, $table['suffix']), true); } echo 'All done!' . PHP_EOL; }
$pdo->queryExec("UPDATE groups SET first_record = 0, first_record_postdate = NULL, last_record = 0, last_record_postdate = NULL, last_updated = NULL"); echo $pdo->log->primary("Reseting all groups completed."); $arr = ["tvrage_titles", "release_nfos", "release_comments", 'sharing', 'sharing_sites', "users_releases", "user_movies", "user_series", "movieinfo", "musicinfo", "release_files", "audio_data", "release_subtitles", "video_data", "releaseextrafull", "parts", "missed_parts", "binaries", "collections", "releases"]; foreach ($arr as &$value) { $rel = $pdo->queryExec("TRUNCATE TABLE {$value}"); if ($rel !== false) { echo $pdo->log->primary("Truncating {$value} completed."); } } unset($value); $sql = "SHOW table status"; $tables = $pdo->query($sql); foreach ($tables as $row) { $tbl = $row['name']; if (preg_match('/collections_\\d+/', $tbl) || preg_match('/binaries_\\d+/', $tbl) || preg_match('/parts_\\d+/', $tbl) || preg_match('/missed_parts_\\d+/', $tbl) || preg_match('/\\d+_collections/', $tbl) || preg_match('/\\d+_binaries/', $tbl) || preg_match('/\\d+_parts/', $tbl) || preg_match('/\\d+_missed_parts_\\d+/', $tbl)) { $rel = $pdo->queryDirect(sprintf('DROP TABLE %s', $tbl)); if ($rel !== false) { echo $pdo->log->primary("Dropping {$tbl} completed."); } } } (new SphinxSearch())->truncateRTIndex('releases_rt'); $pdo->optimise(false, 'full'); echo $pdo->log->header("Deleting nzbfiles subfolders."); try { $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($pdo->getSetting('nzbpath'), \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($files as $file) { if (basename($file) != '.gitignore' && basename($file) != 'tmpunrar') { $todo = $file->isDir() ? 'rmdir' : 'unlink'; @$todo($file); }
$splitqry = $newOldqry = ''; $splitqry = $tRun->proc_query(4, null, null, $db_name); $newOldqry = $tRun->proc_query(6, null, null, null); $splitres = $pdo->queryOneRow($splitqry, false); $runVar['timers']['newOld'] = $pdo->queryOneRow($newOldqry, false); //assign split query results to main var if (is_array($splitres)) { foreach ($splitres as $splitkey => $split) { $runVar['counts']['now'][$splitkey] = $split; } } $runVar['timers']['query']['split_time'] = time() - $timer02; $runVar['timers']['query']['split1_time'] = time() - $timer01; $timer03 = time(); //This is subpartition compatible -- loops through all partitions and adds their total row counts instead of doing a slow query count $partitions = $pdo->queryDirect(sprintf("\n\t\t\t\tSELECT SUM(TABLE_ROWS) AS count, PARTITION_NAME AS category\n\t\t\t\tFROM information_schema.PARTITIONS\n\t\t\t\tWHERE TABLE_NAME = 'releases'\n\t\t\t\tAND TABLE_SCHEMA = %s\n\t\t\t\tGROUP BY PARTITION_NAME", $pdo->escapeString($db_name))); foreach ($partitions as $partition) { $runVar['counts']['now'][$partition['category']] = $partition['count']; } unset($partitions); $runVar['timers']['query']['init_time'] = time() - $timer03; $runVar['timers']['query']['init1_time'] = time() - $timer01; $timer04 = time(); $proc1qry = $tRun->proc_query(1, $runVar['settings']['book_reqids'], $runVar['settings']['request_hours'], $db_name); $proc1res = $pdo->queryOneRow($proc1qry !== false ? $proc1qry : '', $tRun->rand_bool($runVar['counts']['iterations'])); $runVar['timers']['query']['proc1_time'] = time() - $timer04; $runVar['timers']['query']['proc11_time'] = time() - $timer01; $timer05 = time(); $proc2qry = $tRun->proc_query(2, $runVar['settings']['book_reqids'], $runVar['settings']['request_hours'], $db_name); $proc2res = $pdo->queryOneRow($proc2qry !== false ? $proc2qry : '', $tRun->rand_bool($runVar['counts']['iterations'])); $runVar['timers']['query']['proc2_time'] = time() - $timer05;
$releases = new Releases(['Settings' => $pdo]); $count = $total = $all = 0; $nzb = new NZB($pdo); $ri = new ReleaseImage($pdo); $consoleTools = new ConsoleTools(['ColorCLI' => $pdo->log]); $size = ' size '; if ($argv[2] === 'near') { $size = ' size between (size *.99) AND (size * 1.01) '; } if ($crosspostt != 0) { $query = sprintf('SELECT max(id) AS id, id AS idx, guid FROM releases WHERE adddate > (NOW() - INTERVAL %d HOUR) GROUP BY name, fromname, group_id,' . $size . 'HAVING COUNT(*) > 1', $crosspostt); } else { $query = sprintf('SELECT max(id) AS id, id AS idx, guid FROM releases GROUP BY name, fromname, group_id,' . $size . 'HAVING COUNT(*) > 1'); } do { $resrel = $pdo->queryDirect($query); if ($resrel instanceof \Traversable) { $total = $resrel->rowCount(); echo $pdo->log->header(number_format($total) . " Releases have Duplicates"); foreach ($resrel as $rowrel) { $nzbpath = $nzb->getNZBPath($rowrel['guid']); if (isset($argv[3]) && is_dir($argv[3])) { $path = $argv[3]; if (substr($path, strlen($path) - 1) != '/') { $path = $path . "/"; } if (!file_exists($path . $rowrel['guid'] . ".nzb.gz") && file_exists($nzbpath)) { if (@copy($nzbpath, $path . $rowrel['guid'] . ".nzb.gz") !== true) { exit("\n" . $pdo->log->error("\nUnable to write " . $path . $rowrel['guid'] . ".nzb.gz")); } }
/** * Get all newest TV with covers for poster wall. * * @return array */ public function getNewestTV() { return $this->pdo->queryDirect("SELECT r.rageid, r.guid, r.name, r.searchname, r.size, r.completion,\n\t\t\t\tr.postdate, r.categoryid, r.comments, r.grabs,\n\t\t\t\ttv.id as tvid, tv.imgdata, tv.releasetitle as tvtitle\n\t\t\tFROM releases r\n\t\t\tINNER JOIN tvrage_titles tv USING (rageid)\n\t\t\tWHERE r.categoryid BETWEEN 5000 AND 5999\n\t\t\tAND tv.rageid > 0\n\t\t\tAND length(tv.imgdata) > 0\n\t\t\tAND r.id in (select max(id) from releases where rageid > 0 group by rageid)\n\t\t\tORDER BY r.postdate DESC\n\t\t\tLIMIT 24"); }
<?php //This script will update all records in the xxxinfo table where there is no cover require_once dirname(__FILE__) . '/../../../www/config.php'; use nzedb\db\Settings; $pdo = new Settings(); $movie = new XXX(['Echo' => true, 'Settings' => $pdo]); $movies = $pdo->queryDirect("SELECT title FROM xxxinfo WHERE cover = 0"); if ($movies instanceof Traversable) { echo $pdo->log->primary("Updating " . number_format($movies->rowCount()) . " movie covers."); foreach ($movies as $mov) { $starttime = microtime(true); $mov = $movie->updateXXXInfo($mov['title']); // sleep so that it's not ddos' the site $diff = floor((microtime(true) - $starttime) * 1000000); if (333333 - $diff > 0) { echo "\nsleeping\n"; usleep(333333 - $diff); } } echo "\n"; }
exit($pdo->log->error("\nThis script will move all collections, binaries, parts into tables per group.\n\n" . "php {$argv['0']} true ...: To process all parts and leave the parts/binaries/collections tables intact.\n" . "php {$argv['0']} true truncate ...: To process all parts and truncate parts/binaries/collections tables after completed.\n")); } $start = time(); $consoleTools = new ConsoleTools(['ColorCLI' => $pdo->log]); $groups = new Groups(['Settings' => $pdo]); $actgroups = $pdo->query("SELECT DISTINCT group_id from collections"); echo $pdo->log->info("Creating new collections, binaries, and parts tables for each group that has collections."); foreach ($actgroups as $group) { $pdo->queryExec("DROP TABLE IF EXISTS collections_" . $group['group_id']); $pdo->queryExec("DROP TABLE IF EXISTS binaries_" . $group['group_id']); $pdo->queryExec("DROP TABLE IF EXISTS parts_" . $group['group_id']); if ($groups->createNewTPGTables($group['group_id']) === false) { exit($pdo->log->error("\nThere is a problem creating new parts/files tables for group {$group['name']}.\n")); } } $collections_rows = $pdo->queryDirect("SELECT group_id FROM collections GROUP BY group_id"); echo $pdo->log->info("Counting parts, this could table a few minutes."); $parts_count = $pdo->queryOneRow("SELECT COUNT(*) AS cnt FROM parts"); $i = 0; if ($collections_rows instanceof \Traversable) { foreach ($collections_rows as $row) { $groupName = $groups->getByNameByID($row['group_id']); echo $pdo->log->header("Processing {$groupName}"); //collection $pdo->queryExec("INSERT IGNORE INTO collections_" . $row['group_id'] . " (subject, fromname, date, xref, totalfiles, group_id, collectionhash, dateadded, filecheck, filesize, releaseid) " . "SELECT subject, fromname, date, xref, totalfiles, group_id, collectionhash, dateadded, filecheck, filesize, releaseid FROM collections WHERE group_id = {$row['group_id']}"); $collections = $pdo->queryOneRow("SELECT COUNT(*) AS cnt FROM collections where group_id = " . $row['group_id']); $ncollections = $pdo->queryOneRow("SELECT COUNT(*) AS cnt FROM collections_" . $row['group_id']); echo $pdo->log->primary("Group {$groupName}, Collections = {$collections['cnt']} [{$ncollections['cnt']}]"); //binaries $pdo->queryExec("INSERT IGNORE INTO binaries_{$row['group_id']} (name, filenumber, totalparts, currentparts, binaryhash, partcheck, partsize, collection_id) " . "SELECT name, filenumber, totalparts, currentparts, binaryhash, partcheck, partsize, n.id FROM binaries b " . "INNER JOIN collections c ON b.collection_id = c.id " . "INNER JOIN collections_{$row['group_id']} n ON c.collectionhash = n.collectionhash AND c.group_id = {$row['group_id']}"); $binaries = $pdo->queryOneRow("SELECT COUNT(*) AS cnt FROM binaries b INNER JOIN collections c ON b.collection_id = c.id where c.group_id = {$row['group_id']}");
* not, see: * * @link <http://www.gnu.org/licenses/>. * @author niel / kevin * @copyright 2014 nZEDb */ if (!isset($argv[1]) || !in_array($argv[1], ['1'])) { exit('Options: (enter a number, it\'s not recommended to rerun the same fix)' . PHP_EOL . '1: 2014-07-28: Add unique key to binaryhash to be able to do multiple updates in 1 statement.' . PHP_EOL); } require_once dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'config.php'; use nzedb\db\Settings; $pdo = new Settings(); if (!$pdo->getSetting('tablepergroup')) { exit("Tables per groups is not enabled, quitting!"); } $groups = $pdo->queryDirect('SELECT id FROM groups WHERE active = 1 OR backfill = 1'); if ($groups === false) { echo "No active groups. Fix not needed.\n"; } else { $queries = array(); switch ($argv[1]) { case 1: // Drop this index, as we will recreate it as a unique. $queries[] = ['t' => 1, 'q' => 'ALTER TABLE binaries_%d DROP INDEX ix_binary_binaryhash']; // Recreate the index as unique so we can use on duplicate key update, saving select / update query. $queries[] = ['t' => 1, 'q' => 'ALTER IGNORE TABLE binaries_%d ADD UNIQUE INDEX ix_binary_binaryhash(binaryhash)']; break; default: exit; } $groupCount = $groups->rowCount();
exit($pdo->log->error("tmux session: '" . $tmux_session . "' is already running, aborting.\n")); } $nntpproxy = $pdo->getSetting('nntpproxy'); if ($nntpproxy == '1') { $modules = ["nntp", "socketpool"]; foreach ($modules as &$value) { if (!python_module_exist($value)) { exit($pdo->log->error("\nNNTP Proxy requires " . $value . " python module but it's not installed. Aborting.\n")); } } } //reset collections dateadded to now if dateadded > delay time check echo $pdo->log->header("Resetting expired collections dateadded to now. This could take a minute or two. Really."); if ($tablepergroup == 1) { $sql = "SHOW table status"; $tables = $pdo->queryDirect($sql); $ran = 0; foreach ($tables as $row) { $tbl = $row['name']; if (preg_match('/collections_\\d+/', $tbl)) { $run = $pdo->queryExec('UPDATE ' . $tbl . ' SET dateadded = now() WHERE dateadded < now() - INTERVAL ' . $delaytimet . ' HOUR'); if ($run !== false) { $ran += $run->rowCount(); } } } echo $pdo->log->primary(number_format($ran) . " collections reset."); } else { $ran = 0; $run = $pdo->queryExec('update collections set dateadded = now() WHERE dateadded < now() - INTERVAL ' . $delaytimet . ' HOUR'); if ($run !== false) {
use nzedb\db\Settings; $pdo = new Settings(); if (!isset($argv[1]) || $argv[1] != "all" && $argv[1] != "full" && !is_numeric($argv[1])) { exit($pdo->log->error(" This script tries to match a release name or searchname to a PreDB title by using Full Text Search Matching.\n" . "It will first parse PreDB titles to match, order by oldest to newest pre.\n\n" . "php predbftmatch.php 1000 show 1000\t...: to limit to 1000 presently unsearched PreDB titles ordered by oldest to newest predate and show renaming offset title return by 1000.\n" . "php predbftmatch.php full show\t\t...: to run on all unmatched PreDB titles and show renaming.\n" . "php predbftmatch.php all show\t\t...: to run on all PreDB titles (Around 2-3 seconds per pre runtime).\n\n" . "Doing a limited search (first example) is recommended for testing. As you match more PreDB IDs to your releases and search existing pres, the loops will get smaller and smaller.\n\n")); } $namefixer = new NameFixer(['Settings' => $pdo]); $offset = ''; $timestart = time(); $counter = $counted = 0; if (isset($argv[3]) && is_numeric($argv[3])) { $offset = " OFFSET " . $argv[3]; } $titles = false; //Selects all PreDB Titles to Match Against if (isset($argv[1]) && $argv[1] === "all") { $titles = $pdo->queryDirect("SELECT id AS preid, title, source, searched FROM predb\n\t\t\t\t\tWHERE LENGTH(title) >= 15 AND title NOT REGEXP '[\"\\<\\> ]'\n\t\t\t\t\tORDER BY predate ASC"); //Selects all PreDB Titles that don't have a current match in releases (slower intial query but less loop time) } else { if (isset($argv[1]) && $argv[1] === "full") { $titles = $pdo->queryDirect("SELECT id AS preid, title, source, searched FROM predb\n\t\t\t\t\tWHERE LENGTH(title) >= 15 AND searched = 0\n\t\t\t\t\tAND title NOT REGEXP '[\"\\<\\> ]' ORDER BY predate ASC"); //Selects PreDB Titles where predate is greater than the past user selected number of hours } else { if (isset($argv[1]) && is_numeric($argv[1])) { $titles = $pdo->queryDirect(sprintf("SELECT id AS preid, title, source, searched FROM predb\n\t\t\t\t\t\t WHERE LENGTH(title) >= 15 AND searched = 0\n\t\t\t\t\t\t AND title NOT REGEXP '[\"\\<\\> ]' ORDER BY predate ASC LIMIT %d %s", $argv[1], $offset)); } } } if (isset($argv[2]) && $argv[2] === "show") { $show = 1; } else { $show = 0;
/** * 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.group_id = ' . $groupID; $optionsQuery = self::NfoQueryString($this->pdo); $res = $this->pdo->query(sprintf(' SELECT r.id, r.guid, r.group_id, 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]); foreach ($res as $arr) { $fetchedBinary = $nzbContents->getNFOfromNZB($arr['guid'], $arr['id'], $arr['group_id'], $groups->getByNameByID($arr['group_id'])); if ($fetchedBinary !== false) { // Insert nfo into database. $cp = 'COMPRESS(%s)'; $nc = $this->pdo->escapeString($fetchedBinary); $ckreleaseid = $this->pdo->queryOneRow(sprintf('SELECT releaseid FROM release_nfos WHERE releaseid = %d', $arr['id'])); if (!isset($ckreleaseid['releaseid'])) { $this->pdo->queryInsert(sprintf('INSERT INTO release_nfos (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. Disabled for now while TvRage is down. TODO: Add Other Scraper Checks if ($processTvrage == 1) { /*$tvRage = new TvRage(['Echo' => $this->echo, 'Settings' => $this->pdo]); $showId = $this->parseShowId($fetchedBinary); if ($showId !== 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 AND r.nfostatus > %d %s %s', NZB::NZB_ADDED, $this->maxRetries, self::NFO_FAILED, $groupIDQuery, $guidCharQuery)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { // remove any release_nfos for failed $this->pdo->queryExec(sprintf(' DELETE FROM release_nfos WHERE nfo IS NULL AND releaseid = %d', $release['id'])); // set release.nfostatus to failed $this->pdo->queryExec(sprintf(' UPDATE releases r SET r.nfostatus = %d WHERE r.id = %d', self::NFO_FAILED, $release['id'])); } } 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; }