/** * 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', \Enzebe::NZB_ADDED, \Category::CAT_TV_ANIME, $this->aniqty)); if ($results instanceof \Traversable) { $this->doRandomSleep(); $this->padb = new \newznab\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.')); } } }
function categorizeRelease($update = true, $where, $echooutput = false) { $pdo = new Settings(); $cat = new Categorize(); $consoletools = new consoleTools(); $relcount = $chgcount = 0; $c = new ColorCLI(); echo $c->primary("SELECT id, searchname, groupid, categoryid FROM releases " . $where); $resrel = $pdo->queryDirect("SELECT id, searchname, groupid, categoryid FROM releases " . $where); $total = $resrel->rowCount(); if ($total > 0) { foreach ($resrel as $rowrel) { $catId = $cat->determineCategory($rowrel['groupid'], $rowrel['searchname']); if ($rowrel['categoryid'] != $catId) { if ($update === true) { $pdo->queryExec(sprintf("\n\t\t\t\t\t\t\tUPDATE releases\n\t\t\t\t\t\t\tSET iscategorized = 1,\n\t\t\t\t\t\t\t\trageid = -1,\n\t\t\t\t\t\t\t\tseriesfull = NULL,\n\t\t\t\t\t\t\t\tseason = NULL,\n\t\t\t\t\t\t\t\tepisode = NULL,\n\t\t\t\t\t\t\t\ttvtitle = NULL,\n\t\t\t\t\t\t\t\ttvairdate = NULL,\n\t\t\t\t\t\t\t\timdbid = NULL,\n\t\t\t\t\t\t\t\tmusicinfoid = NULL,\n\t\t\t\t\t\t\t\tconsoleinfoid = NULL,\n\t\t\t\t\t\t\t\tgamesinfo_id = 0,\n\t\t\t\t\t\t\t\txxxinfo_id = 0,\n\t\t\t\t\t\t\t\tbookinfoid = NULL,\n\t\t\t\t\t\t\t\tanidbid = NULL,\n\t\t\t\t\t\t\t\tcategoryid = %d\n\t\t\t\t\t\t\tWHERE id = %d", $catId, $rowrel['id'])); } $chgcount++; } $relcount++; if ($echooutput) { $consoletools->overWritePrimary("Re-Categorized: [" . number_format($chgcount) . "] " . $consoletools->percentString($relcount, $total)); } } } if ($echooutput !== false && $relcount > 0) { echo "\n"; } return $chgcount; }
public function getCalendar($date = "") { if (!preg_match('/\\d{4}-\\d{2}-\\d{2}/', $date)) { $date = date("Y-m-d"); } $sql = $this->pdo->queryDirect(sprintf("\n\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\tFROM episodeinfo\n\t\t\t\t\t\tWHERE DATE(airdate) = %s\n\t\t\t\t\t\tORDER BY airdate ASC", $this->pdo->escapeString($date))); return $sql; }
/** * Process all untagged movies to link them to a movieinfo row. */ public function processMovieReleases() { $ret = 0; $nfo = new Nfo(); $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where imdbid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 100", Category::CAT_PARENT_MOVIE)); if ($this->pdo->getNumRows($res) > 0) { if ($this->echooutput) { echo "MovProc : Processing " . $this->pdo->getNumRows($res) . " movie releases\n"; } while ($arr = $this->pdo->getAssocArray($res)) { $imdbID = false; /* Preliminary IMDB id Detection from NFO file */ $rawnfo = ''; if ($nfo->getNfo($arr['id'], $rawnfo)) { $imdbID = $this->parseImdbFromNfo($rawnfo); } if ($imdbID !== false) { // Set IMDB (if found in nfo) and move along $this->pdo->queryExec(sprintf("update releases set imdbid = %s where id = %d", $this->pdo->escapeString($imdbID), $arr["id"])); //check for existing movie entry $movCheck = $this->getMovieInfo($imdbID); if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) { $movieId = $this->updateMovieInfo($imdbID); } continue; } $moviename = $this->parseMovieName($arr['searchname']); if ($moviename !== false) { if ($this->echooutput) { echo 'MovProc : ' . $moviename . ' [' . $arr['searchname'] . ']' . "\n"; } //$buffer = getUrl("https://www.google.com/search?source=ig&hl=en&rlz=&btnG=Google+Search&aq=f&oq=&q=".urlencode($moviename.' site:imdb.com')); $buffer = Utility::getUrl(['url' => 'http://www.bing.com/search?&q=' . urlencode($moviename . ' site:imdb.com')]); // make sure we got some data if ($buffer !== false && strlen($buffer)) { $imdbId = $this->parseImdbFromNfo($buffer); if ($imdbId !== false) { //update release with imdb id $this->pdo->queryExec(sprintf("update releases SET imdbid = %s WHERE id = %d", $this->pdo->escapeString($imdbId), $arr["id"])); //check for existing movie entry $movCheck = $this->getMovieInfo($imdbId); if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) { $movieId = $this->updateMovieInfo($imdbId); } } else { //no imdb id found, set to all zeros so we dont process again $this->pdo->queryExec(sprintf("update releases SET imdbid = %d WHERE id = %d", 0, $arr["id"])); } } else { //url fetch failed, will try next run } } else { //no valid movie name found, set to all zeros so we dont process again $this->pdo->queryExec(sprintf("update releases SET imdbid = %d WHERE id = %d", 0, $arr["id"])); } } } }
/** * */ 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.')); } } }
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); }
/** * 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)); }
/** * Removes funky chars from beginning and end of string */ public function removeSpecial() { $sql = "select id, searchname from releases where 1 = 1 "; $sql .= $this->limited ? "AND adddate BETWEEN NOW() - INTERVAL 1 DAY AND NOW()" : ""; $sql .= " order by postdate desc"; $res = $this->pdo->queryDirect($sql); while ($r = $this->pdo->getAssocArray($res)) { $oldname = $r['searchname']; if (preg_match('/^(\\:|\\"|\\-| )+/', $r['searchname'])) { while (preg_match('/^(\\:|\\"|\\-| |\\_)+/', $r['searchname'])) { $r['searchname'] = substr($r['searchname'], 1); } $this->updateName($this->pdo, $r['id'], $oldname, $r['searchname']); } if (preg_match('/^000\\-/', $r['searchname'])) { while (preg_match('/^000\\-/', $r['searchname'])) { $r['searchname'] = substr($r['searchname'], 4); } $this->updateName($this->pdo, $r['id'], $oldname, $r['searchname']); } if (preg_match('/(\\:|\\"|\\-| |\\/)$/', $r['searchname'])) { while (preg_match('/(\\:|\\"|\\-| |\\/)$/', $r['searchname'])) { $r['searchname'] = substr($r['searchname'], 0, -1); } $this->updateName($this->pdo, $r['id'], $oldname, $r['searchname']); } if (preg_match('/\\"/', $r['searchname'])) { while (preg_match('/\\"/', $r['searchname'])) { $r['searchname'] = str_replace('"', '', $r['searchname']); } $this->updateName($this->pdo, $r['id'], $oldname, $r['searchname']); } if (preg_match('/\\-\\d{1}$/', $r['searchname'])) { while (preg_match('/\\-\\d{1}$/', $r['searchname'])) { $r['searchname'] = preg_replace('/\\-\\d{1}$/', '', $r['searchname']); } $this->updateName($this->pdo, $r['id'], $oldname, $r['searchname']); } if (preg_match('/\\!+.*?mom.*?\\!+/i', $r['searchname'])) { while (preg_match('/\\!+.*?mom.*?\\!+/i', $r['searchname'])) { $r['searchname'] = preg_replace('/\\!+.*?mom.*?\\!+/i', '', $r['searchname']); } $this->updateName($this->pdo, $r['id'], $oldname, $r['searchname']); } if (preg_match('/(\\/)/i', $r['searchname'])) { while (preg_match('/(\\/)/i', $r['searchname'])) { $r['searchname'] = preg_replace('/(\\/)/i', '', $r['searchname']); } $this->updateName($this->pdo, $r['id'], $oldname, $r['searchname']); } } }
/** * Matches the hashes within the predb table to release files and subjects (names) which are hashed. * * @param $time * @param $echo * @param $cats * @param $namestatus * @param $show * * @return int */ public function parseTitles($time, $echo, $cats, $namestatus, $show) { $namefixer = new NameFixer(['Echo' => $this->echooutput, 'ConsoleTools' => $this->pdo->log, 'Settings' => $this->pdo]); $consoletools = new ConsoleTools(['ColorCLI' => $this->pdo->log]); $updated = $checked = 0; $tq = ''; if ($time == 1) { $tq = 'AND r.adddate > (NOW() - INTERVAL 3 HOUR) ORDER BY rf.releaseid, rf.size DESC'; } $ct = ''; if ($cats == 1) { $ct = 'AND r.categoryid IN (1090, 2020, 3050, 6050, 5050, 7050, 8010)'; } if ($this->echooutput) { $te = ''; if ($time == 1) { $te = ' in the past 3 hours'; } echo $this->pdo->log->header('Fixing search names' . $te . " using the predb hash."); } $regex = "AND (r.ishashed = 1 OR rf.ishashed = 1)"; if ($cats === 3) { $query = sprintf('SELECT r.id AS releaseid, r.name, r.searchname, r.categoryid, r.groupid, ' . 'dehashstatus, rf.name AS filename FROM releases r ' . 'LEFT OUTER JOIN releasefiles rf ON r.id = rf.releaseid ' . 'WHERE nzbstatus = 1 AND dehashstatus BETWEEN -6 AND 0 AND prehashid = 0 %s', $regex); } else { $query = sprintf('SELECT r.id AS releaseid, r.name, r.searchname, r.categoryid, r.groupid, ' . 'dehashstatus, rf.name AS filename FROM releases r ' . 'LEFT OUTER JOIN releasefiles rf ON r.id = rf.releaseid ' . 'WHERE nzbstatus = 1 AND isrenamed = 0 AND dehashstatus BETWEEN -6 AND 0 %s %s %s', $regex, $ct, $tq); } $res = $this->pdo->queryDirect($query); $total = $res->rowCount(); echo $this->pdo->log->primary(number_format($total) . " releases to process."); if ($res instanceof Traversable) { foreach ($res as $row) { if (preg_match('/[a-fA-F0-9]{32,40}/i', $row['name'], $matches)) { $updated = $updated + $namefixer->matchPredbHash($matches[0], $row, $echo, $namestatus, $this->echooutput, $show); } else { if (preg_match('/[a-fA-F0-9]{32,40}/i', $row['filename'], $matches)) { $updated = $updated + $namefixer->matchPredbHash($matches[0], $row, $echo, $namestatus, $this->echooutput, $show); } } if ($show === 2) { $consoletools->overWritePrimary("Renamed Releases: [" . number_format($updated) . "] " . $consoletools->percentString(++$checked, $total)); } } } if ($echo == 1) { echo $this->pdo->log->header("\n" . $updated . " releases have had their names changed out of: " . number_format($checked) . " files."); } else { echo $this->pdo->log->header("\n" . $updated . " releases could have their names changed. " . number_format($checked) . " files were checked."); } return $updated; }
public function testRegex($regex, $groupname, $poster, $ignorematched, $matchagainstbins) { $cat = new Categorize(); $groups = new Groups(); $groupID = $groups->getByNameByID($groupname); $group = $groups->getCBPTableNames($this->tablePerGroup, $groupID); $catList = $cat->getForSelect(); $matches = []; if ($groupname === 0) { $groupname = '.*'; } if ($matchagainstbins !== '') { $sql = sprintf("select b.*, '0' as size, '0' as blacklistID, g.name as groupname from %s b left join groups g on g.id = b.groupid where b.groupid IN (select g.id from groups g where g.name REGEXP %s) order by b.date desc", $group['bname'], $this->pdo->escapeString('^' . $groupname . '$')); } else { $sql = sprintf("select rrt.* from releaseregextesting rrt where rrt.groupname REGEXP %s order by rrt.date desc", $this->pdo->escapeString('^' . $groupname . '$')); } $resbin = $this->pdo->queryDirect($sql); while ($rowbin = $this->pdo->getAssocArray($resbin)) { if ($ignorematched !== '' && ($rowbin['regexid'] != '' || $rowbin['blacklistid'] == 1)) { continue; } $regexarr = ["id" => "", 'regex' => $regex, 'poster' => $poster, "categoryid" => ""]; $regexCheck = $this->performMatch($regexarr, $rowbin['name'], $rowbin['fromname']); if ($regexCheck !== false) { $relname = $regexCheck['name']; $relparts = explode("/", $regexCheck['parts']); $matches[$relname]['name'] = $relname; $matches[$relname]['parts'] = $regexCheck['parts']; $matches[$relname]['bincount'] = isset($matches[$relname]['bincount']) ? $matches[$relname]['bincount'] + 1 : 1; $matches[$relname]['bininfo'][] = $rowbin; $matches[$relname]['binsize'][] = $rowbin['size']; $matches[$relname]['totalsize'] = array_sum($matches[$relname]['binsize']); $matches[$relname]['relparts'][$relparts[1]] = $relparts[1]; $matches[$relname]['reltotalparts'] = array_sum($matches[$relname]['relparts']); $matches[$relname]['regexid'] = $regexCheck['regexid']; if (ctype_digit($regexCheck['regcatid'])) { $matches[$relname]['catname'] = $catList[$regexCheck['regcatid']]; } else { $matches[$relname]['catname'] = $catList[$cat->determineCategory($groupname, $relname)]; } } } //echo '<pre>'; //print_r(array_pop($matches)); //echo '</pre>'; return $matches; }
/** * 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 groupid = ' . $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'))); $binaries = $this->pdo->queryDirect($this->_binariesQuery . $relID . ' ORDER BY name'); if ($binaries instanceof \Traversable) { foreach ($binaries as $binary) { $poster = htmlspecialchars($binary['fromname'], ENT_QUOTES, 'utf-8'); if ($binary instanceof \Traversable) { foreach ($binary as $bin) { // Buffer segment writes, increases performance. $string = ''; $parts = $this->pdo->queryDirect(sprintf($this->_partsQuery, $bin['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="' . $bin['udate'] . '" subject="' . htmlspecialchars($bin['name'], ENT_QUOTES, 'utf-8') . ' (1/' . $bin['totalparts'] . ")\">\n <groups>\n <group>" . $bin['groupname'] . "</group>\n </groups>\n <segments>\n" . $string . " </segments>\n</file>\n"); } } } } gzwrite($fp, '</nzb>'); gzclose($fp); if (is_file($path)) { $this->pdo->queryExec(sprintf(' UPDATE releases SET nzbstatus = %d %s WHERE id = %d', NZB::NZB_ADDED, $nzb_guid === '' ? '' : ', nzb_guid = UNHEX( ' . $this->pdo->escapestring(md5($nzb_guid)) . ' )', $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; }
/** * Process all untagged releases to see if they are found in predb. */ public function processReleases($daysback = 3) { if ($this->echooutput) { echo "Predb : Updating releases with pre data\n"; } $matched = 0; $releasesQuery = $this->pdo->queryDirect(sprintf('SELECT id, searchname FROM releases WHERE preid IS NULL AND adddate > DATE_SUB(NOW(), INTERVAL %d DAY)', $daysback)); while ($arr = $this->pdo->getAssocArray($releasesQuery)) { $arr['searchname'] = str_replace(' ', '_', $arr['searchname']); $sql = sprintf("SELECT id FROM predb WHERE dirname = %s LIMIT 1", $this->pdo->escapeString($arr['searchname'])); $predbQuery = $this->pdo->queryOneRow($sql); if ($predbQuery) { $this->pdo->queryExec(sprintf('UPDATE releases SET preid = %d WHERE id = %d', $predbQuery['id'], $arr['id'])); $matched++; } } if ($this->echooutput) { echo "Predb : Matched pre data to " . $matched . " releases\n"; } }
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 releasefiles.name.\n"); $query = $this->pdo->queryDirect(sprintf(' SELECT r.id AS releaseid, r.name, r.searchname, r.groupid, r.categoryid, rf.name AS filename FROM releases r INNER JOIN releasefiles rf ON r.id = rf.releaseid AND rf.name IS NOT NULL WHERE r.prehashid = 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."); } } }
/** * Categorizes releases. * * @param string $type name or searchname | Categorize using the search name or subject. * @param string $where Optional "where" query parameter. * * @return int Quantity of categorized releases. * @access public */ public function categorizeRelease($type, $where = '') { $cat = new \Categorize(['Settings' => $this->pdo]); $categorized = $total = 0; $releases = $this->pdo->queryDirect(sprintf('SELECT id, %s, groupid FROM releases %s', $type, $where)); if ($releases && $releases->rowCount()) { $total = $releases->rowCount(); foreach ($releases as $release) { $catId = $cat->determineCategory($release['groupid'], $release[$type]); $this->pdo->queryExec(sprintf('UPDATE releases SET categoryid = %d, iscategorized = 1 WHERE id = %d', $catId, $release['id'])); $categorized++; if ($this->echoCLI) { $this->consoleTools->overWritePrimary('Categorizing: ' . $this->consoleTools->percentString($categorized, $total)); } } } if ($this->echoCLI !== false && $categorized > 0) { echo PHP_EOL; } return $categorized; }
/** * 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]); } } }
/** * Process all untagged releases to see if musicinfo exists for them. */ public function processMusicReleases() { $ret = 0; $numlookedup = 0; $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where musicinfoid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 1000", Category::CAT_PARENT_MUSIC)); if ($this->pdo->getNumRows($res) > 0) { if ($this->echooutput) { echo "MusicPr : Processing " . $this->pdo->getNumRows($res) . " audio releases\n"; } while ($arr = $this->pdo->getAssocArray($res)) { if ($numlookedup > Music::NUMTOPROCESSPERTIME) { return; } $albumId = -2; $album = $this->parseArtist($arr['searchname']); if ($album !== false) { if ($this->echooutput) { echo 'MusicPr : Looking up: ' . $album["artist"] . ' - ' . $album["album"] . "\n"; } //check for existing music entry $albumCheck = $this->getMusicInfoByName($album["artist"], $album["album"]); if ($albumCheck === false) { // // get from amazon // $numlookedup++; $ret = $this->updateMusicInfo($album["artist"], $album["album"], $album['year']); if ($ret !== false) { $albumId = $ret; } } else { $albumId = $albumCheck["id"]; } } $this->pdo->queryExec(sprintf("update releases SET musicinfoid = %d WHERE id = %d", $albumId, $arr["id"])); } } }
/** * Check all untagged console releases for their extended metadata. */ public function processConsoleReleases() { $ret = 0; $numlookedup = 0; $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where consoleinfoid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 100", Category::CAT_PARENT_GAME)); if ($this->pdo->getNumRows($res) > 0) { if ($this->echooutput) { echo "ConsPrc : Processing " . $this->pdo->getNumRows($res) . " console releases\n"; } while ($arr = $this->pdo->getAssocArray($res)) { if ($numlookedup > Console::NUMTOPROCESSPERTIME) { return; } $gameInfo = $this->parseTitle($arr['searchname']); if ($gameInfo !== false) { if ($this->echooutput) { echo 'ConsPrc : ' . $gameInfo["title"] . ' (' . $gameInfo["platform"] . ')' . "\n"; } //check for existing console entry $gameCheck = $this->getConsoleInfoByName($gameInfo["title"], $gameInfo["platform"]); if ($gameCheck === false) { $numlookedup++; $gameId = $this->updateConsoleInfo($gameInfo); if ($gameId === false) { $gameId = -2; } } else { $gameId = $gameCheck["id"]; } //update release $this->pdo->queryExec(sprintf("update releases SET consoleinfoid = %d WHERE id = %d", $gameId, $arr["id"])); } else { //could not parse release title $this->pdo->queryExec(sprintf("update releases SET consoleinfoid = %d WHERE id = %d", -2, $arr["id"])); } } } }
/** * Process all untagged book releases for additional metadata. */ public function processBookReleases() { $numlookedup = 0; $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where bookinfoid IS NULL and categoryid = %d ORDER BY postdate DESC LIMIT 100", Category::CAT_BOOK_EBOOK)); if ($this->pdo->getNumRows($res) > 0) { if ($this->echooutput) { echo "BookPrc : Processing " . $this->pdo->getNumRows($res) . " book releases\n"; } while ($arr = $this->pdo->getAssocArray($res)) { if ($numlookedup > Book::NUMTOPROCESSPERTIME) { return; } $bookId = -2; $book = $this->parseAuthor($arr['searchname']); if ($book !== false) { if ($this->echooutput) { echo 'BookPrc : ' . $book["author"] . ' - ' . $book["title"] . "\n"; } //check for existing book entry $bookCheck = $this->getBookInfoByName($book["author"], $book["title"]); if ($bookCheck === false) { // // get from amazon // $numlookedup++; $ret = $this->updateBookInfo($book["author"], $book["title"]); if ($ret !== false) { $bookId = $ret; } } else { $bookId = $bookCheck["id"]; } } $this->pdo->queryExec(sprintf("update releases SET bookinfoid = %d WHERE id = %d", $bookId, $arr["id"])); } } }
$rel = $pdo->queryExec("TRUNCATE TABLE {$value}"); if ($rel !== false) { echo $pdo->log->primary("Truncating {$value} completed."); } } unset($value); $tpg = $pdo->getSetting('tablepergroup'); $tablepergroup = !empty($tpg) ? $tpg : 0; if ($tablepergroup == 1) { $sql = 'SHOW table status'; $tables = $pdo->query($sql); foreach ($tables as $row) { $tbl = $row['name']; if (preg_match('/binaries_\\d+/', $tbl) || preg_match('/parts_\\d+/', $tbl) || preg_match('/partrepair_\\d+/', $tbl) || preg_match('/\\d+_binaries/', $tbl) || preg_match('/\\d+_parts/', $tbl) || preg_match('/\\d+_partrepair_\\d+/', $tbl)) { if ($argv[1] == "drop") { $rel = $pdo->queryDirect(sprintf('DROP TABLE %s', $tbl)); if ($rel !== false) { echo $pdo->log->primary("Dropping {$tbl} completed."); } } else { $rel = $pdo->queryDirect(sprintf('TRUNCATE TABLE %s', $tbl)); if ($rel !== false) { echo $pdo->log->primary("Truncating {$tbl} completed."); } } } } } $delcount = $pdo->queryDirect("DELETE FROM releases WHERE nzbstatus = 0"); echo $pdo->log->primary($delcount->rowCount() . " releases had no nzb, deleted."); } else {
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', \Enzebe::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 && in_array($gameInfo['title'] . $gameInfo['platform'], $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); } $gameId = -2; } else { if ($gameCheck === false) { $gameId = $this->updateConsoleInfo($gameInfo); $usedAmazon = true; if ($gameId === false) { $gameId = -2; $this->failCache[] = $gameInfo['title'] . $gameInfo['platform']; } } 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.')); } } }
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.groupid, r.categoryid, r.name, r.searchname, uncompress(nfo) AS textstring FROM releases r INNER JOIN releasenfo 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.prehashid = 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) {
/** * */ public function processReleases() { $results = $this->pdo->queryDirect(sprintf("SELECT id, searchname, rageid, anidbid, seriesfull, season, episode, tvtitle FROM releases WHERE episodeinfoid IS NULL AND categoryid IN ( SELECT id FROM category WHERE parentid = %d ) LIMIT 150", Category::CAT_PARENT_TV)); if ($this->pdo->getNumRows($results) > 0) { if ($this->echooutput) { echo "TheTVDB : Looking up last " . $this->pdo->getNumRows($results) . " releases\n"; } while ($arr = $this->pdo->getAssocArray($results)) { unset($TheTVDBAPIArray, $episodeArray, $fullep, $epabsolute, $additionalSql); $seriesName = ''; if ($arr['rageid'] > 0) { $seriesName = $this->pdo->queryOneRow(sprintf('SELECT releasetitle AS seriesName FROM tvrage WHERE rageid = %d', $arr['rageid'])); } elseif ($arr['anidbid'] > 0) { $seriesName = $this->pdo->queryOneRow(sprintf('SELECT title AS seriesName FROM anidb WHERE anidbid = %d', $arr['anidbid'])); } if (empty($seriesName) || !$seriesName) { $this->notFound($seriesName, "", $arr['id'], false); continue; } $seriesName = str_replace('`', '\'', $seriesName['seriesName']); if (!preg_match('/[21]\\d{3}\\/\\d{2}\\/\\d{2}/', $arr['seriesfull'])) { $fullep = str_pad(str_replace('S', '', $arr['season']), 2, '0', STR_PAD_LEFT) . 'x' . str_pad(str_replace('E', '', $arr['episode']), 2, '0', STR_PAD_LEFT); } else { $fullep = str_replace('/', '-', $arr['seriesfull']); } $TheTVDBAPIArray = $this->getSeriesInfoByName($seriesName); if (!$TheTVDBAPIArray) { $seriesid = $this->lookupSeriesID($seriesName); if ($seriesid > 0) { $TheTVDBAPIArray = $this->TheTVDBAPI($seriesid, $seriesName); if ($TheTVDBAPIArray) { $this->addSeries($TheTVDBAPIArray); $this->addEpisodes($TheTVDBAPIArray); } else { $this->addEmptySeries($seriesName); $this->notFound($seriesName, $fullep, $arr['id']); continue; } } else { $this->addEmptySeries($seriesName); $this->notFound($seriesName, $fullep, $arr['id']); continue; } } else { if ($TheTVDBAPIArray['tvdbid'] > 0 && time() - strtotime($TheTVDBAPIArray['createddate']) > 604800) { $TheTVDBAPIArray = $this->TheTVDBAPI($TheTVDBAPIArray['tvdbid'], $seriesName); $this->updateSeries($TheTVDBAPIArray['tvdbid'], $TheTVDBAPIArray['actors'], $TheTVDBAPIArray['airsday'], $TheTVDBAPIArray['airstime'], $TheTVDBAPIArray['contentrating'], $TheTVDBAPIArray['firstaired'], $TheTVDBAPIArray['genre'], $TheTVDBAPIArray['imdbid'], $TheTVDBAPIArray['network'], $TheTVDBAPIArray['overview'], $TheTVDBAPIArray['rating'], $TheTVDBAPIArray['ratingcount'], $TheTVDBAPIArray['runtime'], $TheTVDBAPIArray['seriesname'], $TheTVDBAPIArray['status']); $this->addEpisodes($TheTVDBAPIArray); } } if ($TheTVDBAPIArray['tvdbid'] > 0) { $epabsolute = '0'; if ($arr['anidbid'] > 0) { if (preg_match('/S(?P<season>\\d+)[ED](?P<episode>\\d+)/', $arr['episode'], $seasonEpisode)) { $arr['season'] = $seasonEpisode['season']; $arr['episode'] = $seasonEpisode['episode']; } else { $epabsolute = $arr['episode']; } } $Episode = new Episode(); $episodeArray = $Episode->getEpisodeInfoByName($seriesName, $fullep, (string) $epabsolute); if (!$episodeArray) { $this->notFound($seriesName, $fullep, $arr['id']); continue; } } else { $this->notFound($seriesName, $fullep, $arr['id']); continue; } $additionalSql = ''; if ($arr['anidbid'] > 0 && $episodeArray['epabsolute'] > 0) { $additionalSql = sprintf(', season = NULL, episode = %d, tvtitle = %s, tvairdate = %s', $episodeArray['epabsolute'], $this->pdo->escapeString($episodeArray['epabsolute'] . ' - ' . str_replace('\'', '`', $episodeArray['eptitle'])), $this->pdo->escapeString($episodeArray['airdate'])); } $this->pdo->queryExec(sprintf('UPDATE releases SET tvdbid = %d, episodeinfoid = %d %s WHERE id = %d', $TheTVDBAPIArray['tvdbid'], $episodeArray['id'], $additionalSql, $arr['id'])); if ($this->echooutput) { echo 'TheTVDB : ' . $seriesName . ' ' . $fullep . " returned " . $episodeArray['tvdbid'] . "\n"; } } } }
system($command); } } $pdo->queryExec("SET FOREIGN_KEY_CHECKS=1"); } else { if (isset($argv[1]) && $argv[1] == "all" && (isset($argv[2]) && $argv[2] == "outfile") && (isset($argv[3]) && file_exists($argv[3]))) { $sql = "SHOW tables"; $tables = $pdo->query($sql); foreach ($tables as $row) { $tbl = $row['tables_in_' . DB_NAME]; $filename = $argv[3] . $tbl . ".csv"; echo $pdo->log->header("Dumping {$tbl}."); if (file_exists($filename)) { newname($filename); } $pdo->queryDirect(sprintf("SELECT * INTO OUTFILE %s FROM %s", $pdo->escapeString($filename), $tbl)); } } else { if (isset($argv[1]) && $argv[1] == "all" && (isset($argv[2]) && $argv[2] == "infile") && (isset($argv[3]) && is_dir($argv[3]))) { $sql = "SHOW tables"; $tables = $pdo->query($sql); $pdo->queryExec("SET FOREIGN_KEY_CHECKS=0"); foreach ($tables as $row) { $tbl = $row['tables_in_' . DB_NAME]; $filename = $argv[3] . $tbl . ".csv"; if (file_exists($filename)) { echo $pdo->log->header("Restoring {$tbl}."); $pdo->queryExec(sprintf("LOAD DATA INFILE %s INTO TABLE %s", $pdo->escapeString($filename), $tbl)); } } $pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
$splitqry = $newOldqry = ''; $splitqry = $tRun->proc_query(4, $runVar['settings']['book_reqids'], $runVar['settings']['request_hours'], $db_name); $newOldqry = $tRun->proc_query(6, $runVar['settings']['book_reqids'], $runVar['settings']['request_hours'], $db_name); $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;
use newznab\processing\PProcess; $c = new ColorCLI(); if (!isset($argv[1])) { exit($c->error("This script is not intended to be run manually, it is called from fixreleasenames_threaded.py.")); } else { if (isset($argv[1])) { $db = new Settings(); $namefixer = new \NameFixer(['Settings' => $pdo]); $pieces = explode(' ', $argv[1]); if (isset($pieces[1]) && $pieces[0] == 'nfo') { $release = $pieces[1]; if ($res = $db->queryOneRow(sprintf('SELECT rel.guid AS guid, nfo.releaseid AS nfoid, rel.groupid, rel.categoryid, rel.name, rel.searchname, uncompress(nfo) AS textstring, rel.id AS releaseid FROM releases rel INNER JOIN releasenfo nfo ON (nfo.releaseid = rel.id) WHERE rel.id = %d', $release))) { //ignore encrypted nfos if (preg_match('/^=newz\\[NZB\\]=\\w+/', $res['textstring'])) { $namefixer->done = $namefixer->matched = false; $db->queryDirect(sprintf('UPDATE releases SET proc_nfo = 1 WHERE id = %d', $res['releaseid'])); $namefixer->checked++; echo '.'; } else { //echo $res['textstring']."\n"; $namefixer->done = $namefixer->matched = false; if ($namefixer->checkName($res, true, 'NFO, ', 1, 1) !== true) { echo '.'; } $namefixer->checked++; } } } else { if (isset($pieces[1]) && $pieces[0] == 'filename') { $release = $pieces[1]; if ($res = $db->queryOneRow(sprintf('SELECT relfiles.name AS textstring, rel.categoryid, rel.searchname, ' . 'rel.groupid, relfiles.releaseid AS fileid, rel.id AS releaseid, rel.name FROM releases rel ' . 'INNER JOIN releasefiles relfiles ON (relfiles.releaseid = rel.id) WHERE rel.id = %d', $release))) {
/** * 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; }
<?php require_once dirname(__FILE__) . '/../../../www/config.php'; use newznab\db\Settings; $pdo = new Settings(); if ($argc === 1 || !is_numeric($argv[1])) { exit($pdo->log->error("\nThis script will show table data, index and free space used. The argument needed is numeric.\n\n" . "php {$argv['0']} 1 ...: To show all tables with data + index space used greater than 1MB or free space greater than 1MB.\n" . "php {$argv['0']} .01 ...: To show all tables with data + index space used greater than .01MB or free space greater than .01MB.\n")); } passthru('clear'); $data = $index = $total = $free = 0; $table_data = "SELECT TABLE_NAME AS 'Table', TABLE_ROWS AS 'Rows', " . "ENGINE AS 'engine', " . "CREATE_OPTIONS AS 'format', " . "((DATA_LENGTH) / POWER(1024,2)) AS 'data', " . "((INDEX_LENGTH) / POWER(1024,2)) AS 'index', " . "((DATA_FREE) / POWER(1024,2)) AS 'free', " . "((DATA_LENGTH + INDEX_LENGTH) / POWER(1024,2)) AS 'total' " . "FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema = '" . DB_NAME . "' " . "ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC"; $run = $pdo->queryDirect($table_data); $mask = $pdo->log->headerOver("%-25.25s ") . $pdo->log->primaryOver("%7.7s %10.10s %15.15s %15.15s %15.15s %15.15s\n"); printf($mask, 'Table Name', 'Engine', 'Row_Format', 'Data Size', 'Index Size', 'Free Space', 'Total Size'); printf($mask, '=========================', '=======', '==========', '===============', '===============', '===============', '==============='); if ($run instanceof \Traversable) { foreach ($run as $table) { if ($table['total'] > $argv[1] || $table['free'] > $argv[1]) { printf($mask, $table['table'], $table['engine'], str_replace('row_format=', '', $table['format']), number_format($table['data'], 2) . " MB", number_format($table['index'], 2) . " MB", number_format($table['free'], 2) . " MB", number_format($table['total'], 2) . " MB"); } $data += $table['data']; $index += $table['index']; $free += $table['free']; $total += $table['total']; } } printf($mask, '=========================', '=======', '==========', '===============', '===============', '===============', '==============='); printf($mask, 'Table Name', 'Engine', 'Row_Format', 'Data Size', 'Index Size', 'Free Space', 'Total Size'); printf($mask, '', '', '', number_format($data, 2) . " MB", number_format($index, 2) . " MB", number_format($free, 2) . " MB", number_format($total, 2) . " MB"); $myisam = $pdo->queryOneRow("SELECT CONCAT(ROUND(KBS/POWER(1024,IF(pw<0,0,IF(pw>3,0,pw)))+0.49999), " . "SUBSTR(' KMG',IF(pw<0,0,IF(pw>3,0,pw))+1,1)) recommended_key_buffer_size " . "FROM (SELECT SUM(index_length) KBS " . "FROM information_schema.tables " . "WHERE engine='MyISAM' AND table_schema NOT IN ('information_schema','mysql')) A, (SELECT 3 pw) B;", false); $innodb = $pdo->queryOneRow("SELECT CONCAT(ROUND(KBS/POWER(1024,IF(pw<0,0,IF(pw>3,0,pw)))+0.49999), " . "SUBSTR(' KMG',IF(pw<0,0,IF(pw>3,0,pw))+1,1)) recommended_innodb_buffer_pool_size " . "FROM (SELECT SUM(index_length) KBS " . "FROM information_schema.tables " . "WHERE engine='InnoDB') A,(SELECT 3 pw) B;", false);
<?php //This script will update all records in the movieinfo table require_once dirname(__FILE__) . '/../../../www/config.php'; use newznab\db\Settings; $pdo = new Settings(); $c = new ColorCLI(); $movie = new Movie(['Echo' => true, 'Settings' => $pdo]); $movies = $pdo->queryDirect("SELECT imdbid FROM movieinfo WHERE tmdbid = 0 ORDER BY id ASC"); if ($movies instanceof \Traversable) { echo $pdo->log->header("Updating movie info for " . number_format($movies->rowCount()) . " movies."); foreach ($movies as $mov) { $starttime = microtime(true); $mov = $movie->updateMovieInfo($mov['imdbid']); // tmdb limits are 30 per 10 sec, not certain for imdb $diff = floor((microtime(true) - $starttime) * 1000000); if (333333 - $diff > 0) { echo "sleeping\n"; usleep(333333 - $diff); } } echo "\n"; }