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."); } }
/** * Attempt to get a better name from a par2 file and categorize the release. * * @note Called from NZBContents.php * * @param string $messageID MessageID from NZB file. * @param int $relID id of the release. * @param int $groupID Group id of the release. * @param \NNTP $nntp Class NNTP * @param int $show Only show result or apply iy. * * @return bool */ public function parsePAR2($messageID, $relID, $groupID, &$nntp, $show) { if ($messageID === '') { return false; } $query = $this->pdo->queryOneRow(sprintf(' SELECT id, groupid, categoryid, name, searchname, UNIX_TIMESTAMP(postdate) AS post_date, id AS releaseid FROM releases WHERE isrenamed = 0 AND id = %d', $relID)); if ($query === false) { return false; } // Only get a new name if the category is OTHER. $foundName = true; if (!in_array((int) $query['categoryid'], array(\Category::CAT_BOOK_OTHER, \Category::CAT_GAME_OTHER, \Category::CAT_MOVIE_OTHER, \Category::CAT_MUSIC_OTHER, \Category::CAT_PC_MOBILEOTHER, \Category::CAT_TV_OTHER, \Category::CAT_MISC_HASHED, \Category::CAT_XXX_OTHER, \Category::CAT_MISC_OTHER))) { $foundName = false; } // Get the PAR2 file. $par2 = $nntp->getMessages($this->groups->getByNameByID($groupID), $messageID, $this->alternateNNTP); if ($nntp->isError($par2)) { return false; } // Put the PAR2 into Par2Info, check if there's an error. $this->_par2Info->setData($par2); if ($this->_par2Info->error) { return false; } // Get the file list from Par2Info. $files = $this->_par2Info->getFileList(); if ($files !== false && count($files) > 0) { $filesAdded = 0; // Loop through the files. foreach ($files as $file) { if (!isset($file['name'])) { continue; } // If we found a name and added 10 files, stop. if ($foundName === true && $filesAdded > 10) { break; } if ($this->addpar2) { // Add to release files. if ($filesAdded < 11 && $this->pdo->queryOneRow(sprintf(' SELECT id FROM releasefiles WHERE releaseid = %d AND name = %s', $relID, $this->pdo->escapeString($file['name']))) === false) { // Try to add the files to the DB. if ($this->releaseFiles->add($relID, $file['name'], $file['size'], $query['post_date'], 0)) { $filesAdded++; } } } else { $filesAdded++; } // Try to get a new name. if ($foundName === false) { $query['textstring'] = $file['name']; if ($this->nameFixer->checkName($query, 1, 'PAR2, ', 1, $show) === true) { $foundName = true; } } } // If we found some files. if ($filesAdded > 0) { $this->debugging->log(get_class(), __FUNCTION__, 'Added ' . $filesAdded . ' releasefiles from PAR2 for ' . $query['searchname'], \Logger::LOG_INFO); // Update the file count with the new file count + old file count. $this->pdo->queryExec(sprintf(' UPDATE releases SET rarinnerfilecount = rarinnerfilecount + %d WHERE id = %d', $filesAdded, $relID)); } if ($foundName === true) { return true; } } return false; }
<?php /* * This script attemps to clean release names using the NFO, file name and release name, Par2 file. * A good way to use this script is to use it in this order: php fixReleaseNames.php 3 true other yes * php fixReleaseNames.php 5 true other yes * If you used the 4th argument yes, but you want to reset the status, * there is another script called resetRelnameStatus.php */ require_once dirname(__FILE__) . '/../../../www/config.php'; $n = "\n"; $pdo = new nzedb\db\Settings(); $namefixer = new NameFixer(['Settings' => $pdo]); $predb = new PreDb(['Echo' => true, 'Settings' => $pdo]); if (isset($argv[1]) && isset($argv[2]) && isset($argv[3]) && isset($argv[4])) { $update = $argv[2] == "true" ? 1 : 2; $other = 1; if ($argv[3] === 'all') { $other = 2; } else { if ($argv[3] === 'preid') { $other = 3; } } $setStatus = $argv[4] == "yes" ? 1 : 2; $show = 2; if (isset($argv[5]) && $argv[5] === 'show') { $show = 1; } $nntp = null; if ($argv[1] == 7 || $argv[1] == 8) {
/** * 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; }
<?php require_once dirname(__FILE__) . "/config.php"; use newznab\db\Settings; 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++; } }
/** * Try to get a title from a Linux_2rename.sh file for alt.binaries.u4e group. * * @param $fileLocation */ protected function _processU4ETitle($fileLocation) { // Open the file for reading. $handle = @fopen($fileLocation, 'r'); // Check if it failed. if ($handle) { // Loop over the file line by line. while (($buffer = fgets($handle, 16384)) !== false) { // Check if we find the word if (stripos($buffer, 'mkdir') !== false) { // Get a new name. $newName = trim(str_replace('mkdir ', '', $buffer)); // Check if it's a empty string or not. if (empty($newName)) { continue; } // Get a new category id. $newCategory = $this->_categorize->determineCategory($this->_release['groupid'], $newName); $newTitle = $this->pdo->escapeString(substr($newName, 0, 255)); // Update the release with the data. $this->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, prehashid = 0, searchname = %s, isrenamed = 1, iscategorized = 1, proc_files = 1, categoryid = %d WHERE id = %d', $newTitle, $newCategory, $this->_release['id'])); $this->sphinx->updateRelease($this->_release['id'], $this->pdo); // Echo the changed name to CLI. if ($this->_echoCLI) { \NameFixer::echoChangedReleaseName(['new_name' => $newName, 'old_name' => $this->_release['searchname'], 'new_category' => $newCategory, 'old_category' => $this->_release['categoryid'], 'group' => $this->_release['groupid'], 'release_id' => $this->_release['id'], 'method' => 'ProcessAdditional->_processU4ETitle']); } // Break out of the loop. break; } } // Close the file. fclose($handle); } // Delete the file. @unlink($fileLocation); }
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 prehashid = 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 groupid = ' . $argv[2]; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $full === true) { $where = ' AND groupid IN ' . $argv[2]; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $all === true) { $where = ' AND groupid IN ' . $argv[2]; $why = ' WHERE nzbstatus = 1'; } else { if (isset($argv[2]) && is_numeric($argv[2]) && $all === true) { $where = ' AND groupid = ' . $argv[2]; $why = ' WHERE nzbstatus = 1 and prehashid = 0'; } else { if (isset($argv[2]) && is_numeric($argv[2])) { $where = ' AND groupid = ' . $argv[2]; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if ($full === true) { $why = ' WHERE nzbstatus = 1 AND (isrenamed = 0 OR categoryid between 8000 AND 8999)'; } else { if ($all === true) { $why = ' WHERE nzbstatus = 1'; } else { $why = ' WHERE 1=1'; } } } } } } } } } resetSearchnames(); echo $pdo->log->header("SELECT id, name, searchname, fromname, size, groupid, categoryid FROM releases" . $why . $what . $where . ";\n"); $res = $pdo->queryDirect("SELECT id, name, searchname, fromname, size, groupid, 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['groupid']); $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 prehash 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 prehash 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["groupid"], $cleanName); 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, prehashid = " . $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, prehashid = " . $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' => 'lib/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 = 8010) 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 = 8010 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 prehashid = 0 AND nzbstatus = 1", true); } else { $relcount = catRelease("searchname", "WHERE (iscategorized = 0 OR categoryid = 8010) 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(); }
/** * Updates release information when a proper Request id match is found. */ protected function _updateRelease() { $determinedCat = $this->category->determineCategory($this->_release['gid'], $this->_newTitle['title']); if ($determinedCat == $this->_release['categoryid']) { $newTitle = $this->pdo->escapeString($this->_newTitle['title']); $this->pdo->queryExec(sprintf(' UPDATE releases SET prehashid = %d, reqidstatus = %d, isrenamed = 1, iscategorized = 1, searchname = %s WHERE id = %d', $this->_newTitle['id'], self::REQID_FOUND, $newTitle, $this->_release['id'])); $this->sphinx->updateRelease($this->_release['id'], $this->pdo); } else { $newTitle = $this->pdo->escapeString($this->_newTitle['title']); $this->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, prehashid = %d, reqidstatus = %d, isrenamed = 1, iscategorized = 1, searchname = %s, categoryid = %d WHERE id = %d', $this->_newTitle['id'], self::REQID_FOUND, $newTitle, $determinedCat, $this->_release['id'])); $this->sphinx->updateRelease($this->_release['id'], $this->pdo); } if ($this->_release['name'] !== $this->_newTitle['title'] && $this->_show == 1) { \NameFixer::echoChangedReleaseName(array('new_name' => $this->_newTitle['title'], 'old_name' => $this->_release['name'], 'new_category' => $this->category->getNameByID($determinedCat), 'old_category' => $this->category->getNameByID($this->_release['categoryid']), 'group' => $this->_release['groupname'], 'release_id' => $this->_release['id'], 'method' => 'RequestIDLocal')); } }
$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 . ".\nNow the releases will be recategorized."); $releases = new ProcessReleases(['Settings' => $pdo, 'ConsoleTools' => $consoletools, 'ReleaseCleaning' => $rc]); $releases->resetCategorize("WHERE isrenamed = 0"); $categorized = $releases->categorizeRelease("name", "WHERE isrenamed = 0"); $timecat = $consoletools->convertTime(time() - $timestart); echo $pdo->log->header("Finished categorizing " . $categorized . " releases in " . $timecat . ".\nFinally, the releases will be fixed using the NFO/filenames."); $namefixer = new NameFixer(['Settings' => $pdo, 'ConsoleTools' => $consoletools]); $namefixer->fixNamesWithNfo(2, 1, 1, 1, $show); $namefixer->fixNamesWithFiles(2, 1, 1, 1, $show); $timetotal = $consoletools->convertTime(time() - $timestart); echo $pdo->log->header("Finished recreating search names / recategorizing / refixing names in " . $timetotal); } else { 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();
/** * If we found a PRE name, update the releases name and reset post processing. */ protected function _updateRelease() { $determinedCategory = $this->category->determineCategory($this->_newTitle['title'], $this->_release['group_id']); $newTitle = $this->pdo->escapeString($this->_newTitle['title']); $this->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, reqidstatus = %d, isrenamed = 1, proc_files = 1, searchname = %s, categoryid = %d, preid = %d WHERE id = %d', self::REQID_FOUND, $newTitle, $determinedCategory, $this->_preDbID, $this->_release['id'])); $this->sphinx->updateReleaseSearchName($this->_release['id'], $newTitle); if ($this->echoOutput) { NameFixer::echoChangedReleaseName(array('new_name' => $this->_newTitle['title'], 'old_name' => $this->_release['searchname'], 'new_category' => $this->category->getNameByID($determinedCategory), 'old_category' => '', 'group' => $this->_release['groupname'], 'release_id' => $this->_release['id'], 'method' => 'RequestID->updateRelease<web>')); } }
<?php require_once dirname(__FILE__) . '/../../www/config.php'; $cli = new ColorCLI(); if (!isset($argv[1]) && ($argv[1] !== 'full' || !is_numeric($argv[1]))) { exit($cli->error(PHP_EOL . "This script tries to match release filenames to PreDB filenames." . PHP_EOL . "To display the changes, use 'show' as the second argument. The optional third argument will limit the amount of filenames to attempt to match." . PHP_EOL . PHP_EOL . "php match_prefiles.php full show\t...: to run on full database and show renames." . PHP_EOL . "php match_prefiles.php 2000 show\t...: to run against 2000 distinct releases and show renames." . PHP_EOL)); } $nameFixer = new NameFixer(); $nameFixer->getPreFileNames($argv);
continue; } $newName = ''; $handle = @fopen($tmpPath . $fileName, 'r'); if ($handle) { while (($buffer = fgets($handle, 16384)) !== false) { if (stripos($buffer, 'mkdir') !== false) { $newName = trim(str_replace('mkdir', '', $buffer)); break; } } fclose($handle); } @unlink($tmpPath . $fileName); if ($newName === '') { echo 'ERROR: New name is empty!' . PHP_EOL; continue; } $determinedCat = $categorize->determineCategory($newName, $release['group_id']); NameFixer::echoChangedReleaseName(array('new_name' => $newName, 'old_name' => $release['oldname'], 'new_category' => $categorize->getNameByid($determinedCat), 'old_category' => $categorize->getNameByid($release['categoryid']), 'group' => $release['groupname'], 'release_id' => $release['id'], 'method' => 'misc/testing/Dev/rename_u4e.php')); $newName = $pdo->escapeString(substr($newName, 0, 255)); $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, preid = 0, searchname = %s, isrenamed = 1, iscategorized = 1, proc_files = 1, categoryid = %d WHERE id = %d', $newName, $determinedCat, $release['id'])); $sphinx->updateReleaseSearchName($release['id'], $newName); } }
<?php require_once dirname(__FILE__) . '/config.php'; use nzedb\db\Settings; $pdo = new Settings(); if (!isset($argv[1]) || $argv[1] != "all" && $argv[1] != "full" && !is_numeric($argv[1])) { exit($pdo->log->error(" This script tries to match a release name or searchname to a PreDB title by using Full Text Search Matching.\n" . "It will first parse PreDB titles to match, order by oldest to newest pre.\n\n" . "php predbftmatch.php 1000 show 1000\t...: to limit to 1000 presently unsearched PreDB titles ordered by oldest to newest predate and show renaming offset title return by 1000.\n" . "php predbftmatch.php full show\t\t...: to run on all unmatched PreDB titles and show renaming.\n" . "php predbftmatch.php all show\t\t...: to run on all PreDB titles (Around 2-3 seconds per pre runtime).\n\n" . "Doing a limited search (first example) is recommended for testing. As you match more PreDB IDs to your releases and search existing pres, the loops will get smaller and smaller.\n\n")); } $namefixer = new NameFixer(['Settings' => $pdo]); $offset = ''; $timestart = time(); $counter = $counted = 0; if (isset($argv[3]) && is_numeric($argv[3])) { $offset = " OFFSET " . $argv[3]; } $titles = false; //Selects all PreDB Titles to Match Against if (isset($argv[1]) && $argv[1] === "all") { $titles = $pdo->queryDirect("SELECT id AS preid, title, source, searched FROM predb\n\t\t\t\t\tWHERE LENGTH(title) >= 15 AND title NOT REGEXP '[\"\\<\\> ]'\n\t\t\t\t\tORDER BY predate ASC"); //Selects all PreDB Titles that don't have a current match in releases (slower intial query but less loop time) } else { if (isset($argv[1]) && $argv[1] === "full") { $titles = $pdo->queryDirect("SELECT id AS preid, title, source, searched FROM predb\n\t\t\t\t\tWHERE LENGTH(title) >= 15 AND searched = 0\n\t\t\t\t\tAND title NOT REGEXP '[\"\\<\\> ]' ORDER BY predate ASC"); //Selects PreDB Titles where predate is greater than the past user selected number of hours } else { if (isset($argv[1]) && is_numeric($argv[1])) { $titles = $pdo->queryDirect(sprintf("SELECT id AS preid, title, source, searched FROM predb\n\t\t\t\t\t\t WHERE LENGTH(title) >= 15 AND searched = 0\n\t\t\t\t\t\t AND title NOT REGEXP '[\"\\<\\> ]' ORDER BY predate ASC LIMIT %d %s", $argv[1], $offset)); } } } if (isset($argv[2]) && $argv[2] === "show") {