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, groupid, categoryid, dehashstatus FROM releases WHERE prehashid = 0 AND ishashed = 1'); } else { if (isset($argv[1]) && $argv[1] === "full") { $res = $pdo->queryDirect('SELECT id AS releaseid, name, searchname, groupid, categoryid, dehashstatus FROM releases WHERE categoryid = 8020 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, groupid, categoryid, dehashstatus FROM releases WHERE categoryid = 8020 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."); } }
/** * 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, group_id FROM releases %s', $type, $where)); if ($releases && $releases->rowCount()) { $total = $releases->rowCount(); foreach ($releases as $release) { $catId = $cat->determineCategory($release[$type], $release['group_id']); $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; }
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.")); } }
/** * 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, 7010, 8050)'; } 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.group_id, ' . '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 preid = 0 %s', $regex); } else { $query = sprintf('SELECT r.id AS releaseid, r.name, r.searchname, r.categoryid, r.group_id, ' . '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; }
} 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")); } } } if ($releases->deleteSingle(['g' => $rowrel['guid'], 'i' => $rowrel['idx']], $nzb, $ri) !== false) { $consoleTools->overWritePrimary('Deleted: ' . number_format(++$count) . " Duplicate Releases"); } } } $all += $count; $count = 0; echo "\n\n"; } while ($total > 0); echo $pdo->log->header("\nDeleted " . number_format($all) . " Duplicate Releases");
function catRelease($type, $where, $echooutput = false) { global $pdo; $cat = new \Categorize(['Settings' => $pdo]); $consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]); $relcount = 0; echo $pdo->log->primary("SELECT id, " . $type . ", groupid FROM releases " . $where); $resrel = $pdo->queryDirect("SELECT id, " . $type . ", groupid FROM releases " . $where); $total = $resrel->rowCount(); if ($total > 0) { foreach ($resrel as $rowrel) { $catId = $cat->determineCategory($rowrel['groupid'], $rowrel[$type]); $pdo->queryExec(sprintf("UPDATE releases SET iscategorized = 1, categoryid = %d WHERE id = %d", $catId, $rowrel['id'])); $relcount++; if ($echooutput) { $consoletools->overWritePrimary("Categorizing: " . $consoletools->percentString($relcount, $total)); } } } if ($echooutput !== false && $relcount > 0) { echo "\n"; } return $relcount; }
exit($pdo->log->info("You have no releases in the DB.")); } } else { if (isset($argv[1]) && $argv[1] == "reset") { $pdo = new Settings(); $res = $pdo->query("SELECT releases.id, releases.name, releases.fromname, releases.size, groups.name AS gname FROM releases INNER JOIN groups ON releases.group_id = groups.id"); if (count($res) > 0) { echo $pdo->log->header("Going to reset search names, this can take a while."); $done = 0; $timestart = time(); $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); foreach ($res as $row) { $rc = new ReleaseCleaning($pdo); $newname = $rc->releaseCleaner($row['name'], $row['fromname'], $row['size'], $row['gname']); if (is_array($newname)) { $newname = $newname['cleansubject']; } $newname = $pdo->escapeString($newname); $pdo->queryExec(sprintf("UPDATE releases SET searchname = %s where id = %d", $newname, $row['id'])); $sphinx->updateReleaseSearchName($newname, $row['id']); $done++; $consoletools->overWritePrimary("Renaming:" . $consoletools->percentString($done, count($res))); } $timenc = $consoletools->convertTime(TIME() - $timestart); echo $pdo->log->header($done . " releases renamed in " . $timenc); } } else { exit($pdo->log->error("\nThis script runs the subject names through namecleaner to create a clean search name, it also recategorizes and runs the releases through namefixer.\n" . "php resetSearchname.php full ...: To run this, recategorize and refix release names on all releases.\n" . "php resetSearchname.php limited ...: To run this on releases that have not had their names fixed, then categorizing them.\n" . "php resetSearchname.php reset ...: To just reset searchnames.\n")); } } }
$deleted++; } } else { if (isset($res)) { $pdo->queryExec(sprintf("UPDATE releases SET nzbstatus = 1 WHERE id = %s", $res['id'])); } } } else { if ($argv[1] === "delete") { @copy($filePath, nZEDb_ROOT . "pooped/" . $guid[1] . ".nzb.gz"); unlink($filePath); $deleted++; } } $time = $consoletools->convertTime(time() - $timestart); $consoletools->overWritePrimary('Checking NZBs: ' . $deleted . ' nzbs of ' . ++$checked . ' releases checked ' . $couldbe . 'deleted from disk, Running time: ' . $time); } } echo $pdo->log->header("\n" . number_format($checked) . ' nzbs checked, ' . number_format($deleted) . ' nzbs ' . $couldbe . 'deleted.'); $timestart = time(); $checked = $deleted = 0; echo $pdo->log->header("Getting List of releases to check against nzbs."); $res = $pdo->queryDirect('SELECT id, guid FROM releases'); if ($res instanceof Traversable) { foreach ($res as $row) { $nzbpath = $nzb->getNZBPath($row["guid"]); if (!file_exists($nzbpath)) { if ($argv[1] === "delete") { @copy($nzbpath, nZEDb_ROOT . "pooped/" . $row["guid"] . ".nzb.gz"); $releases->deleteSingle(['g' => $row['guid'], 'i' => $row['id']], $nzb, $releaseImage); }
$pdo->queryExec("TRUNCATE TABLE movieinfo"); $pdo->queryExec("TRUNCATE TABLE releasevideo"); $pdo->queryExec("TRUNCATE TABLE musicinfo"); $pdo->queryExec("TRUNCATE TABLE bookinfo"); $pdo->queryExec("TRUNCATE TABLE releasenfo"); $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"); } if (isset($argv[2]) && $argv[2] === "true") { echo $pdo->log->header("Resetting all Console postprocessing"); $where = ' WHERE consoleinfoid IS NOT NULL'; } else { echo $pdo->log->header("Resetting all failed Console postprocessing"); $where = " WHERE consoleinfoid IN (-2, 0) AND categoryid BETWEEN 1000 AND 1999";
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($cleanName, $row["group_id"]); if ($propername == true) { $pdo->queryExec(sprintf("UPDATE releases SET rageid = -1, seriesfull = NULL, season = NULL, episode = NULL, tvtitle = NULL, tvairdate = NULL, 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 rageid = -1, seriesfull = NULL, season = NULL, episode = NULL, tvtitle = NULL, tvairdate = NULL, 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(array('new_name' => $cleanName, 'old_name' => $row["searchname"], 'new_category' => $newcatname, 'old_category' => $oldcatname, 'group' => $groupname, 'release_id' => $row["id"], 'method' => 'misc/testing/Dev/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 = 7010) 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 = 7010 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 = 7010) 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(); }
$seconds = TIME() - $time; $nzbsperhour = number_format(round($nzbCount / $seconds * 3600), 0); } if ($nzbCount >= $maxtoprocess && $maxtoprocess != 0) { $nzbsperhour = number_format(round($nzbCount / $seconds * 3600), 0); exit($pdo->log->header("\nProcessed " . number_format($nzbCount) . " nzbs in " . relativeTime($time) . "\nAveraged " . $nzbsperhour . " imports per hour from " . $path)); } @unlink($nzbFile); } else { $pdo->queryExec(sprintf("DELETE FROM releases WHERE guid = %s AND postdate = %s AND size = %d", $pdo->escapeString($relguid), $pdo->escapeString($totalsize))); echo $pdo->log->error("\nFailed copying NZB, deleting release from DB.\n"); @unlink($nzbFile); flush(); $importfailed = true; } $consoleTools->overWritePrimary('Imported ' . "[" . number_format($nzbSkipped) . "] " . number_format($nzbCount) . " NZBs (" . $nzbsperhour . "iph) in " . relativeTime($time)); } } } exit($pdo->log->header("\nRunning Time: " . relativeTime($time) . "\n" . "Processed: " . number_format($nzbCount + $nzbSkipped) . "\n" . "Imported: " . number_format($nzbCount) . "\n" . "Duplicates: " . number_format($nzbSkipped))); /** * Compress an imported NZB and store it inside the nzbfiles folder. * * @param string $relguid The guid of the release. * @param string $nzb String containing the imported NZB. * @param NZB $NZB * @param object $site * * @return bool * */