function getPreName($argv) { global $pdo; $timestart = time(); $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); $namefixer = new NameFixer(['Settings' => $pdo, 'ConsoleTools' => $consoletools]); $res = false; if (isset($argv[1]) && $argv[1] === "all") { $res = $pdo->queryDirect('SELECT id AS releaseid, name, searchname, group_id, categoryid, dehashstatus FROM releases WHERE preid = 0 AND ishashed = 1'); } else { if (isset($argv[1]) && $argv[1] === "full") { $res = $pdo->queryDirect('SELECT id AS releaseid, name, searchname, group_id, categoryid, dehashstatus FROM releases WHERE categoryid = 7020 AND ishashed = 1 AND dehashstatus BETWEEN -6 AND 0'); } else { if (isset($argv[1]) && is_numeric($argv[1])) { $res = $pdo->queryDirect('SELECT id AS releaseid, name, searchname, group_id, categoryid, dehashstatus FROM releases WHERE categoryid = 7020 AND ishashed = 1 AND dehashstatus BETWEEN -6 AND 0 ORDER BY postdate DESC LIMIT ' . $argv[1]); } } } $counter = $counted = $total = 0; if ($res !== false) { $total = $res->rowCount(); } $show = !isset($argv[2]) || $argv[2] !== 'show' ? 0 : 1; if ($total > 0) { echo $pdo->log->header("\n" . number_format($total) . ' releases to process.'); sleep(2); foreach ($res as $row) { $success = 0; if (preg_match('/[a-fA-F0-9]{32,40}/i', $row['name'], $matches)) { $success = $namefixer->matchPredbHash($matches[0], $row, 1, 1, true, $show); } else { if (preg_match('/[a-fA-F0-9]{32,40}/i', $row['searchname'], $matches)) { $success = $namefixer->matchPredbHash($matches[0], $row, 1, 1, true, $show); } } if ($success === 0) { $pdo->queryDirect(sprintf('UPDATE releases SET dehashstatus = dehashstatus - 1 WHERE id = %d', $row['releaseid'])); } else { $counted++; } if ($show === 0) { $consoletools->overWritePrimary("Renamed Releases: [" . number_format($counted) . "] " . $consoletools->percentString(++$counter, $total)); } } } if ($total > 0) { echo $pdo->log->header("\nRenamed " . $counted . " releases in " . $consoletools->convertTime(TIME() - $timestart) . "."); } else { echo $pdo->log->info("\nNothing to do."); } }
function reCategorize($argv) { global $pdo; $where = ''; $othercats = Category::getCategoryOthersGroup(); $update = true; if (isset($argv[1]) && is_numeric($argv[1])) { $where = ' AND group_id = ' . $argv[1]; } else { if (isset($argv[1]) && preg_match('/\\([\\d, ]+\\)/', $argv[1])) { $where = ' AND group_id IN ' . $argv[1]; } else { if (isset($argv[1]) && $argv[1] === 'misc') { $where = sprintf(' AND categoryid IN (%s)', $othercats); } } } if (isset($argv[2]) && $argv[2] === 'test') { $update = false; } if (isset($argv[1]) && (is_numeric($argv[1]) || preg_match('/\\([\\d, ]+\\)/', $argv[1]))) { echo $pdo->log->header("Categorizing all releases in {$argv[1]} using searchname. This can take a while, be patient."); } else { if (isset($argv[1]) && $argv[1] == "misc") { echo $pdo->log->header("Categorizing all releases in misc categories using searchname. This can take a while, be patient."); } else { echo $pdo->log->header("Categorizing all releases using searchname. This can take a while, be patient."); } } $timestart = TIME(); if (isset($argv[1]) && (is_numeric($argv[1]) || preg_match('/\\([\\d, ]+\\)/', $argv[1])) || $argv[1] === 'misc') { $chgcount = categorizeRelease(str_replace(" AND", "WHERE", $where), $update, true); } else { $chgcount = categorizeRelease('', $update, true); } $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); $time = $consoletools->convertTime(TIME() - $timestart); if ($update === true) { echo $pdo->log->header("Finished re-categorizing " . number_format($chgcount) . " releases in " . $time . " , using the searchname.\n"); } else { echo $pdo->log->header("Finished re-categorizing in " . $time . " , using the searchname.\n" . "This would have changed " . number_format($chgcount) . " releases but no updates were done.\n"); } }
/** * Look up request ID's for releases. * * @param array $options * * @return int Quantity of releases matched to a request ID. */ public function lookupRequestIDs(array $options = []) { $curOptions = ['charGUID' => '', 'GroupID' => '', 'limit' => '', 'show' => 1, 'time' => 0]; $curOptions = array_replace($curOptions, $options); $startTime = time(); $renamed = 0; $this->_charGUID = $curOptions['charGUID']; $this->_groupID = $curOptions['GroupID']; $this->_show = $curOptions['show']; $this->_maxTime = $curOptions['time']; $this->_limit = $curOptions['limit']; $this->_getReleases(); if ($this->_releases !== false && $this->_releases->rowCount() > 0) { $this->_totalReleases = $this->_releases->rowCount(); $this->pdo->log->doEcho($this->pdo->log->primary('Processing ' . $this->_totalReleases . " releases for RequestID's.")); $renamed = $this->_processReleases(); if ($this->echoOutput) { echo $this->pdo->log->header("\nRenamed " . number_format($renamed) . " releases in " . $this->consoleTools->convertTime(time() - $startTime) . "."); } } elseif ($this->echoOutput) { $this->pdo->log->doEcho($this->pdo->log->primary("No RequestID's to process.")); } return $renamed; }
if ($titles instanceof \Traversable) { foreach ($titles as $row) { $matched = 0; $searched = 0; $matched = $namefixer->matchPredbFT($row, 1, 1, true, $show); //echo "Pre Title " . $row['title'] . " is translated to search string: "; //echo $pdo->log->header($matched); if ($matched > 0) { $searched = 1; $counted++; } elseif ($matched < 0) { $searched = -6; echo "*"; } else { $searched = $row['searched'] - 1; echo "."; } $pdo->queryExec(sprintf("UPDATE predb SET searched = %d WHERE id = %d", $searched, $row['preid'])); if (!isset($argv[2]) || $argv[2] !== 'show') { $consoletools->overWritePrimary("Renamed Releases: [" . number_format($counted) . "] " . $consoletools->percentString(++$counter, $total)); } } } if ($total > 0) { echo $pdo->log->header("\nRenamed " . number_format($counted) . " releases in " . $consoletools->convertTime(TIME() - $timestart) . "."); } else { echo $pdo->log->info("\nNothing to do."); } } else { echo $pdo->log->info("No work to process.\n"); }
@$todo($file); } } } catch (UnexpectedValueException $e) { echo $pdo->log->error($e->getMessage()); } echo $pdo->log->header("Deleting all images, previews and samples that still remain."); try { $dirItr = new \RecursiveDirectoryIterator(nZEDb_COVERS); $itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY); foreach ($itr as $filePath) { if (basename($filePath) != '.gitignore' && basename($filePath) != 'no-cover.jpg' && basename($filePath) != 'no-backdrop.jpg') { @unlink($filePath); } } } catch (UnexpectedValueException $e) { echo $pdo->log->error($e->getMessage()); } echo $pdo->log->header("Getting Updated List of TV Shows from TVRage."); $tvshows = @simplexml_load_file('http://services.tvrage.com/feeds/show_list.php'); if ($tvshows !== false) { foreach ($tvshows->show as $rage) { if (isset($rage->id) && isset($rage->name) && !empty($rage->id) && !empty($rage->name)) { $pdo->queryInsert(sprintf('INSERT INTO tvrage_titles (rageid, releasetitle, country) VALUES (%s, %s, %s)', $pdo->escapeString($rage->id), $pdo->escapeString($rage->name), $pdo->escapeString($rage->country))); } } } else { echo $pdo->log->error("TVRage site has a hard limit of 400 concurrent api requests. At the moment, they have reached that limit. Please wait before retrying again."); } echo $pdo->log->header("Deleted all releases, images, previews and samples. This script ran for " . $consoletools->convertTime(TIME() - $timestart));
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."); } } }
$time = $consoletools->convertTime(TIME() - $timestart); echo $pdo->log->primary("\n" . 'Finished categorizing ' . $relcount . ' releases in ' . $time . " seconds, using the usenet subject."); } else { if ($argv[1] == 6 && $argv[2] == 'true') { echo $pdo->log->header("Categorizing releases in all sections using the searchname. This can take a while, be patient."); $timestart = TIME(); $relcount = $releases->categorizeRelease('searchname', ''); $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); $time = $consoletools->convertTime(TIME() - $timestart); echo $pdo->log->primary("\n" . 'Finished categorizing ' . $relcount . ' releases in ' . $time . " seconds, using the search name."); } else { if ($argv[1] == 6 && $argv[2] == 'false') { echo $pdo->log->header("Categorizing releases in misc sections using the searchname. This can take a while, be patient."); $timestart = TIME(); $relcount = $releases->categorizeRelease('searchname', 'WHERE categoryID IN (1090, 2020, 3050, 5050, 6050, 7010)'); $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); $time = $consoletools->convertTime(TIME() - $timestart); echo $pdo->log->primary("\n" . 'Finished categorizing ' . $relcount . ' releases in ' . $time . " seconds, using the search name."); } else { exit($pdo->log->error("Wrong argument, type php update_releases.php to see a list of valid arguments.")); } } } } } } } } } else { exit($pdo->log->error("\nWrong set of arguments.\n" . "php update_releases.php 1 true\t\t\t...: Creates releases and attempts to categorize new releases\n" . "php update_releases.php 2 true\t\t\t...: Creates releases and leaves new releases in other -> misc\n" . "\nYou must pass a second argument whether to post process or not, true or false\n" . "You can pass a third optional argument, a group name (ex.: alt.binaries.multimedia).\n" . "\nExtra commands::\n" . "php update_releases.php 4 true\t\t\t...: Puts all releases in other-> misc (also resets to look like they have never been categorized)\n" . "php update_releases.php 5 true\t\t\t...: Categorizes all releases in other-> misc (which have not been categorized already)\n" . "php update_releases.php 6 false\t\t\t...: Categorizes releases in misc sections using the search name\n" . "php update_releases.php 6 true\t\t\t...: Categorizes releases in all sections using the search name\n")); }
$ccount = 1; $gdone = 1; $actgroups = $groups->getActive(); $glen = count($actgroups); $newtables = $glen * 3; $begintime = time(); echo "Creating new collections, binaries, and parts tables for each active group...\n"; foreach ($actgroups as $group) { if ($groups->createNewTPGTables($group['id']) === false) { exit($pdo->log->error("There is a problem creating new parts/files tables for group {$group['name']}.")); } $consoletools->overWrite("Tables Created: " . $consoletools->percentString($gdone * 3, $newtables)); $gdone++; } $endtime = time(); echo "\nTable creation took " . $consoletools->convertTime($endtime - $begintime) . ".\n"; $starttime = time(); echo "\nNew tables created, moving data from old tables to new tables.\nThis will take awhile....\n\n"; while ($cdone < $clen['total']) { // Only load 1000 collections per loop to not overload memory. $collections = $pdo->queryAssoc('select * from collections limit ' . $cdone . ',1000;'); if ($collections instanceof \Traversable) { foreach ($collections as $collection) { $collection['subject'] = $pdo->escapeString($collection['subject']); $collection['fromname'] = $pdo->escapeString($collection['fromname']); $collection['date'] = $pdo->escapeString($collection['date']); $collection['collectionhash'] = $pdo->escapeString($collection['collectionhash']); $collection['dateadded'] = $pdo->escapeString($collection['dateadded']); $collection['xref'] = $pdo->escapeString($collection['xref']); $collection['releaseid'] = $pdo->escapeString($collection['releaseid']); $oldcid = array_shift($collection);
function preName($argv, $argc) { global $pdo; $groups = new Groups(['Settings' => $pdo]); $category = new Categorize(['Settings' => $pdo]); $internal = $external = $pre = 0; $show = 2; if ($argv[$argc - 1] === 'show') { $show = 1; } else { if ($argv[$argc - 1] === 'bad') { $show = 3; } } $counter = 0; $pdo->log = new ColorCLI(); $full = $all = $usepre = false; $what = $where = ''; if ($argv[1] === 'full') { $full = true; } else { if ($argv[1] === 'all') { $all = true; } else { if ($argv[1] === 'preid') { $usepre = true; } else { if (is_numeric($argv[1])) { $what = ' AND adddate > NOW() - INTERVAL ' . $argv[1] . ' HOUR'; } } } } if ($usepre === true) { $where = ''; $why = ' WHERE preid = 0 AND nzbstatus = 1'; } else { if (isset($argv[1]) && is_numeric($argv[1])) { $where = ''; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if (isset($argv[2]) && is_numeric($argv[2]) && $full === true) { $where = ' AND group_id = ' . $argv[2]; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $full === true) { $where = ' AND group_id IN ' . $argv[2]; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $all === true) { $where = ' AND group_id IN ' . $argv[2]; $why = ' WHERE nzbstatus = 1'; } else { if (isset($argv[2]) && is_numeric($argv[2]) && $all === true) { $where = ' AND group_id = ' . $argv[2]; $why = ' WHERE nzbstatus = 1 and preid = 0'; } else { if (isset($argv[2]) && is_numeric($argv[2])) { $where = ' AND group_id = ' . $argv[2]; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if ($full === true) { $why = ' WHERE nzbstatus = 1 AND (isrenamed = 0 OR categoryid between 7000 AND 7999)'; } else { if ($all === true) { $why = ' WHERE nzbstatus = 1'; } else { $why = ' WHERE 1=1'; } } } } } } } } } resetSearchnames(); echo $pdo->log->header("SELECT id, name, searchname, fromname, size, group_id, categoryid FROM releases" . $why . $what . $where . ";\n"); $res = $pdo->queryDirect("SELECT id, name, searchname, fromname, size, group_id, categoryid FROM releases" . $why . $what . $where); $total = $res->rowCount(); if ($total > 0) { $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); foreach ($res as $row) { $groupname = $groups->getByNameByID($row['group_id']); $cleanerName = releaseCleaner($row['name'], $row['fromname'], $row['size'], $groupname, $usepre); $preid = 0; $predb = $predbfile = $increment = false; if (!is_array($cleanerName)) { $cleanName = trim((string) $cleanerName); $propername = $increment = true; if ($cleanName != '' && $cleanerName != false) { $run = $pdo->queryOneRow("SELECT id FROM predb WHERE title = " . $pdo->escapeString($cleanName)); if (isset($run['id'])) { $preid = $run['id']; $predb = true; } } } else { $cleanName = trim($cleanerName["cleansubject"]); $propername = $cleanerName["properlynamed"]; if (isset($cleanerName["increment"])) { $increment = $cleanerName["increment"]; } if (isset($cleanerName["predb"])) { $preid = $cleanerName["predb"]; $predb = true; } } if ($cleanName != '') { if (preg_match('/alt\\.binaries\\.e\\-?book(\\.[a-z]+)?/', $groupname)) { if (preg_match('/^[0-9]{1,6}-[0-9]{1,6}-[0-9]{1,6}$/', $cleanName, $match)) { $rf = new ReleaseFiles($pdo); $files = $rf->get($row['id']); foreach ($files as $f) { if (preg_match('/^(?P<title>.+?)(\\[\\w\\[\\]\\(\\). -]+)?\\.(pdf|htm(l)?|epub|mobi|azw|tif|doc(x)?|lit|txt|rtf|opf|fb2|prc|djvu|cb[rz])/', $f["name"], $match)) { $cleanName = $match['title']; break; } } } } //try to match clean name against predb filename $prefile = $pdo->queryOneRow("SELECT id, title FROM predb WHERE filename = " . $pdo->escapeString($cleanName)); if (isset($prefile['id'])) { $preid = $prefile['id']; $cleanName = $prefile['title']; $predbfile = true; $propername = true; } if ($cleanName != $row['name'] && $cleanName != $row['searchname']) { if (strlen(utf8_decode($cleanName)) <= 3) { } else { $determinedcat = $category->determineCategory($row["group_id"], $cleanName); if ($propername == true) { $pdo->queryExec(sprintf("UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, " . "iscategorized = 1, isrenamed = 1, searchname = %s, categoryid = %d, preid = " . $preid . " WHERE id = %d", $pdo->escapeString($cleanName), $determinedcat, $row['id'])); } else { $pdo->queryExec(sprintf("UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, " . "iscategorized = 1, searchname = %s, categoryid = %d, preid = " . $preid . " WHERE id = %d", $pdo->escapeString($cleanName), $determinedcat, $row['id'])); } if ($increment === true) { $internal++; } else { if ($predb === true) { $pre++; } else { if ($predbfile === true) { $pre++; } else { if ($propername === true) { $external++; } } } } if ($show === 1) { $oldcatname = $category->getNameByID($row["categoryid"]); $newcatname = $category->getNameByID($determinedcat); NameFixer::echoChangedReleaseName(['new_name' => $cleanName, 'old_name' => $row["searchname"], 'new_category' => $newcatname, 'old_category' => $oldcatname, 'group' => $groupname, 'release_id' => $row["id"], 'method' => 'misc/testing/Various/renametopre.php']); } } } else { if ($show === 3 && preg_match('/^\\[?\\d*\\].+?yEnc/i', $row['name'])) { echo $pdo->log->primary($row['name']); } } } if ($cleanName == $row['name']) { $pdo->queryExec(sprintf("UPDATE releases SET isrenamed = 1, iscategorized = 1 WHERE id = %d", $row['id'])); } if ($show === 2 && $usepre === false) { $consoletools->overWritePrimary("Renamed Releases: [Internal=" . number_format($internal) . "][External=" . number_format($external) . "][Predb=" . number_format($pre) . "] " . $consoletools->percentString(++$counter, $total)); } else { if ($show === 2 && $usepre === true) { $consoletools->overWritePrimary("Renamed Releases: [" . number_format($pre) . "] " . $consoletools->percentString(++$counter, $total)); } } } } echo $pdo->log->header("\n" . number_format($pre) . " renamed using preDB Match\n" . number_format($external) . " renamed using ReleaseCleaning.php\n" . number_format($internal) . " using renametopre.php\nout of " . number_format($total) . " releases.\n"); if (isset($argv[1]) && is_numeric($argv[1]) && !isset($argv[2])) { echo $pdo->log->header("Categorizing all releases using searchname from the last {$argv[1]} hours. This can take a while, be patient."); } else { if (isset($argv[1]) && $argv[1] !== "all" && isset($argv[2]) && !is_numeric($argv[2]) && !preg_match('/\\([\\d, ]+\\)/', $argv[2])) { echo $pdo->log->header("Categorizing all non-categorized releases in other->misc using searchname. This can take a while, be patient."); } else { if (isset($argv[1]) && isset($argv[2]) && (is_numeric($argv[2]) || preg_match('/\\([\\d, ]+\\)/', $argv[2]))) { echo $pdo->log->header("Categorizing all non-categorized releases in {$argv[2]} using searchname. This can take a while, be patient."); } else { echo $pdo->log->header("Categorizing all releases using searchname. This can take a while, be patient."); } } } $timestart = TIME(); if (isset($argv[1]) && is_numeric($argv[1])) { $relcount = catRelease("searchname", "WHERE (iscategorized = 0 OR categoryID = 0010) AND adddate > NOW() - INTERVAL " . $argv[1] . " HOUR", true); } else { if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $full === true) { $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where) . " AND iscategorized = 0 ", true); } else { if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $all === true) { $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where), true); } else { if (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == "full") { $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where) . " AND iscategorized = 0 ", true); } else { if (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == "all") { $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where), true); } else { if (isset($argv[1]) && $argv[1] == "full") { $relcount = catRelease("searchname", "WHERE categoryID = 0010 OR iscategorized = 0", true); } else { if (isset($argv[1]) && $argv[1] == "all") { $relcount = catRelease("searchname", "", true); } else { if (isset($argv[1]) && $argv[1] == "preid") { $relcount = catRelease("searchname", "WHERE preid = 0 AND nzbstatus = 1", true); } else { $relcount = catRelease("searchname", "WHERE (iscategorized = 0 OR categoryID = 0010) AND adddate > NOW() - INTERVAL " . $argv[1] . " HOUR", true); } } } } } } } } $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); $time = $consoletools->convertTime(TIME() - $timestart); echo $pdo->log->header("Finished categorizing " . number_format($relcount) . " releases in " . $time . " seconds, using the usenet subject.\n"); resetSearchnames(); }
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 = 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.")); } }
/** * Delete crap releases. * * @param bool $delete Delete the release or just show the result? * @param int|string $time Time in hours (to select old releases) or 'full' for no time limit. * @param string $type Type of query to run [blacklist, executable, gibberish, hashed, installbin, passworded, * passwordurl, sample, scr, short, size, ''] ('' runs against all types) * @param string $blacklistID * * @return string|bool */ public function removeCrap($delete, $time, $type = '', $blacklistID = '') { $this->timeStart = time(); $this->delete = $delete; $this->blacklistID = ''; if (isset($blacklistID) && is_numeric($blacklistID)) { $this->blacklistID = sprintf("AND id = %d", $blacklistID); } $time = trim($time); $this->crapTime = ''; $type = strtolower(trim($type)); switch ($time) { case 'full': if ($this->echoCLI) { echo $this->pdo->log->header("Removing " . ($type == '' ? "All crap releases " : $type . " crap releases") . " - no time limit.\n"); } break; default: if (!is_numeric($time)) { $this->error = 'Error, time must be a number or full.'; return $this->returnError(); } if ($this->echoCLI) { echo $this->pdo->log->header("Removing " . ($type == '' ? "All crap releases " : $type . " crap releases") . " from the past " . $time . " hour(s).\n"); } $this->crapTime = ' AND r.adddate > (NOW() - INTERVAL ' . $time . ' HOUR)'; break; } $this->deletedCount = 0; switch ($type) { case 'blacklist': $this->removeBlacklist(); break; case 'blfiles': $this->removeBlacklistFiles(); break; case 'executable': $this->removeExecutable(); break; case 'gibberish': $this->removeGibberish(); break; case 'hashed': $this->removeHashed(); break; case 'installbin': $this->removeInstallBin(); break; case 'passworded': $this->removePassworded(); break; case 'passwordurl': $this->removePasswordURL(); break; case 'sample': $this->removeSample(); break; case 'scr': $this->removeSCR(); break; case 'short': $this->removeShort(); break; case 'size': $this->removeSize(); break; case 'huge': $this->removeHuge(); break; case 'codec': $this->removeCodecPoster(); break; case 'wmv_all': $this->removeWMV(); break; case '': $this->removeBlacklist(); $this->removeBlacklistFiles(); $this->removeExecutable(); $this->removeGibberish(); $this->removeHashed(); $this->removeInstallBin(); $this->removePassworded(); $this->removeSample(); $this->removeSCR(); $this->removeShort(); $this->removeSize(); $this->removeHuge(); $this->removeCodecPoster(); break; default: $this->error = 'Wrong type: ' . $type; return $this->returnError(); } if ($this->echoCLI) { echo $this->pdo->log->headerOver(($this->delete ? "Deleted " : "Would have deleted ") . $this->deletedCount . " release(s). This script ran for "); echo $this->pdo->log->header($this->consoleTools->convertTime(TIME() - $this->timeStart)); } return $this->browser ? 'Success! ' . ($this->delete ? "Deleted " : "Would have deleted ") . $this->deletedCount . ' release(s) in ' . $this->consoleTools->convertTime(TIME() - $this->timeStart) : true; }
/** * Delete releases using admin settings. * This deletes releases, regardless of group. * * @void * @access public */ public function deleteReleases() { $startTime = time(); $category = new Category(['Settings' => $this->pdo]); $genres = new Genres(['Settings' => $this->pdo]); $passwordDeleted = $duplicateDeleted = $retentionDeleted = $completionDeleted = $disabledCategoryDeleted = 0; $disabledGenreDeleted = $miscRetentionDeleted = $miscHashedDeleted = $categoryMinSizeDeleted = 0; // Delete old releases and finished collections. if ($this->echoCLI) { $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Delete old releases and passworded releases.")); } // Releases past retention. if ($this->pdo->getSetting('releaseretentiondays') != 0) { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE postdate < (NOW() - INTERVAL %d DAY)', $this->pdo->getSetting('releaseretentiondays'))); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $retentionDeleted++; } } } // Passworded releases. if ($this->pdo->getSetting('deletepasswordedrelease') == 1) { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE passwordstatus = %d', Releases::PASSWD_RAR)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $passwordDeleted++; } } } // Possibly passworded releases. if ($this->pdo->getSetting('deletepossiblerelease') == 1) { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE passwordstatus = %d', Releases::PASSWD_POTENTIAL)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $passwordDeleted++; } } } if ($this->crossPostTime != 0) { // Crossposted releases. do { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE adddate > (NOW() - INTERVAL %d HOUR) GROUP BY name HAVING COUNT(name) > 1', $this->crossPostTime)); $total = 0; if ($releases && $releases->rowCount()) { $total = $releases->rowCount(); foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $duplicateDeleted++; } } } while ($total > 0); } if ($this->completion > 0) { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE completion < %d AND completion > 0', $this->completion)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $completionDeleted++; } } } // Disabled categories. $disabledCategories = $category->getDisabledIDs(); if (count($disabledCategories) > 0) { foreach ($disabledCategories as $disabledCategory) { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE categoryid = %d', $disabledCategory['id'])); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $disabledCategoryDeleted++; $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); } } } } // Delete smaller than category minimum sizes. $categories = $this->pdo->queryDirect(' SELECT SQL_NO_CACHE c.id AS id, CASE WHEN c.minsize = 0 THEN cp.minsize ELSE c.minsize END AS minsize FROM category c INNER JOIN category cp ON cp.id = c.parentid WHERE c.parentid IS NOT NULL'); if ($categories instanceof \Traversable) { foreach ($categories as $category) { if ($category['minsize'] > 0) { $releases = $this->pdo->queryDirect(sprintf(' SELECT SQL_NO_CACHE r.id, r.guid FROM releases r WHERE r.categoryid = %d AND r.size < %d LIMIT 1000', $category['id'], $category['minsize'])); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $categoryMinSizeDeleted++; } } } } } // Disabled music genres. $genrelist = $genres->getDisabledIDs(); if (count($genrelist) > 0) { foreach ($genrelist as $genre) { $releases = $this->pdo->queryDirect(sprintf(' SELECT SQL_NO_CACHE id, guid FROM releases INNER JOIN (SELECT id AS mid FROM musicinfo WHERE musicinfo.genre_id = %d) mi ON musicinfoid = mid', $genre['id'])); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $disabledGenreDeleted++; $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); } } } } // Misc other. if ($this->pdo->getSetting('miscotherretentionhours') > 0) { $releases = $this->pdo->queryDirect(sprintf(' SELECT SQL_NO_CACHE id, guid FROM releases WHERE categoryid = %d AND adddate <= NOW() - INTERVAL %d HOUR', Category::CAT_OTHER_MISC, $this->pdo->getSetting('miscotherretentionhours'))); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $miscRetentionDeleted++; } } } // Misc hashed. if ($this->pdo->getSetting('mischashedretentionhours') > 0) { $releases = $this->pdo->queryDirect(sprintf(' SELECT SQL_NO_CACHE id, guid FROM releases WHERE categoryid = %d AND adddate <= NOW() - INTERVAL %d HOUR', Category::CAT_OTHER_HASHED, $this->pdo->getSetting('mischashedretentionhours'))); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $miscHashedDeleted++; } } } if ($this->echoCLI) { $this->pdo->log->doEcho($this->pdo->log->primary('Removed releases: ' . number_format($retentionDeleted) . ' past retention, ' . number_format($passwordDeleted) . ' passworded, ' . number_format($duplicateDeleted) . ' crossposted, ' . number_format($disabledCategoryDeleted) . ' from disabled categories, ' . number_format($categoryMinSizeDeleted) . ' smaller than category settings, ' . number_format($disabledGenreDeleted) . ' from disabled music genres, ' . number_format($miscRetentionDeleted) . ' from misc->other' . number_format($miscHashedDeleted) . ' from misc->hashed' . ($this->completion > 0 ? ', ' . number_format($completionDeleted) . ' under ' . $this->completion . '% completion.' : '.'))); $totalDeleted = $retentionDeleted + $passwordDeleted + $duplicateDeleted + $disabledCategoryDeleted + $disabledGenreDeleted + $miscRetentionDeleted + $miscHashedDeleted + $completionDeleted + $categoryMinSizeDeleted; if ($totalDeleted > 0) { $this->pdo->log->doEcho($this->pdo->log->primary("Removed " . number_format($totalDeleted) . ' releases in ' . $this->consoleTools->convertTime(time() - $startTime))); } } }