diff --git a/lib/DB/patches/0083~site.sql b/lib/DB/patches/0083~site.sql new file mode 100644 index 000000000..c93de7984 --- /dev/null +++ b/lib/DB/patches/0083~site.sql @@ -0,0 +1,6 @@ +INSERT IGNORE INTO `site` (`setting`, `value`) VALUES + ('lookup_reqids', '1'), + ('reqidthreads', '1'), +('request_hours', '1'), +('request_url', 'http://reqid.nzedb.com/index.php'); +UPDATE `tmux` SET `value` = '83' WHERE `setting` = 'sqlpatch'; \ No newline at end of file diff --git a/lib/copy_this/www/lib/RequestID.php b/lib/copy_this/www/lib/RequestID.php new file mode 100644 index 000000000..574668db7 --- /dev/null +++ b/lib/copy_this/www/lib/RequestID.php @@ -0,0 +1,226 @@ + true, + 'Categorize' => null, + 'ConsoleTools' => null, + 'Groups' => null, + 'Settings' => null, + 'SphinxSearch' => null, + ]; + $options += $defaults; + + $this->echoOutput = ($options['Echo'] && NN_ECHOCLI); + $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->category = ($options['Categorize'] instanceof \Categorize ? $options['Categorize'] : new \Categorize(['Settings' => $this->pdo])); + $this->groups = ($options['Groups'] instanceof \Groups ? $options['Groups'] : new \Groups(['Settings' => $this->pdo])); + $this->consoleTools = ($options['ConsoleTools'] instanceof \ConsoleTools ? $options['ConsoleTools'] : new \ConsoleTools(['ColorCLI' => $this->pdo->log])); + $this->sphinx = ($options['SphinxSearch'] instanceof \SphinxSearch ? $options['SphinxSearch'] : new \SphinxSearch()); + } + + /** + * 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 = array()) + { + $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; + } + + /** + * Fetch releases with requestID's from MySQL. + */ + protected function _getReleases() { } + + /** + * Process releases for requestID's. + * + * @return int How many did we rename? + */ + protected function _processReleases() { } + + /** + * No request ID was found, update the release. + * + * @param int $releaseID + * @param int $status + */ + protected function _requestIdNotFound($releaseID, $status) + { + if ($releaseID == 0) { + return; + } + + $this->pdo->queryExec( + sprintf(' + UPDATE releases SET reqidstatus = %d WHERE ID = %d', + $status, $releaseID + ) + ); + } + + /** + * Get a new title / pre ID for a release. + * + * @return array|bool + */ + protected function _getNewTitle() { } + + /** + * Find a RequestID in a usenet subject. + * + * @return int + */ + protected function _siftReqId() + { + $requestID = array(); + switch (true) { + case preg_match('/\[\s*#?scnzb@?efnet\s*\]\[(\d+)\]/', $this->_release['name'], $requestID): + case preg_match('/\[\s*(\d+)\s*\]/', $this->_release['name'], $requestID): + case preg_match('/^REQ\s*(\d{4,6})/i', $this->_release['name'], $requestID): + case preg_match('/^(\d{4,6})-\d{1}\[/', $this->_release['name'], $requestID): + case preg_match('/(\d{4,6}) -/',$this->_release['name'], $requestID): + if ((int) $requestID[1] > 0) { + return (int) $requestID[1]; + } + } + return self::REQID_ZERO; + } + + /** + * @var bool Echo to CLI? + */ + protected $echoOutput; + + /** + * @var Categorize + */ + protected $category; + + /** + * @var DB + */ + protected $pdo; + + /** + * @var ConsoleTools + */ + protected $consoleTools; + + /** + * @var ColorCLI + */ + protected $colorCLI; + + /** + * The found request ID for the release. + * @var int + */ + protected $_requestID = self::REQID_ZERO; + + /** + * The title found from a request ID lookup. + * @var bool|string|array + */ + protected $_newTitle = false; + + /** + * Releases with potential Request ID's we can work on. + * @var \PDOStatement|bool + */ + protected $_releases; + + /** + * Total amount of releases we will be working on. + * @var int + */ + protected $_totalReleases; + + /** + * Release we are currently working on. + * @var array + */ + protected $_release; + + /** + * @var int To show the result or not. + */ + protected $_show = 0; + + /** + * GroupID, which is optional, to limit query results. + * @var string + */ + protected $_groupID; + + /** + * First character of a release GUID, which is optional, to limit query results. + * @var string + */ + protected $_charGUID; + + protected $_limit; + + protected $_maxTime; +} \ No newline at end of file diff --git a/lib/copy_this/www/lib/RequestIDLocal.php b/lib/copy_this/www/lib/RequestIDLocal.php new file mode 100644 index 000000000..4193e5992 --- /dev/null +++ b/lib/copy_this/www/lib/RequestIDLocal.php @@ -0,0 +1,304 @@ +_charGUID === '' ? '' : ' AND r.guid ' . $this->pdo->likeString($this->_charGUID, false, true)); + $query .= ($this->_groupID === '' ? '' : ' AND r.groupID = ' . $this->_groupID); + $query .= ($this->_maxTime === 0 ? '' : sprintf(' AND r.adddate > NOW() - INTERVAL %d HOUR', $this->_maxTime)); + + switch ($this->_limit) { + case 'full': + $query .= sprintf( + " AND r.isrenamed = 0 AND r.reqidstatus in (%d, %d, %d)", + self::REQID_UPROC, + self::REQID_NOLL, + self::REQID_NONE + ); + break; + case is_numeric($this->_limit): + $query .= sprintf( + " AND r.isrenamed = 0 AND r.reqidstatus in (%d, %d, %d) ORDER BY r.postdate DESC LIMIT %d", + self::REQID_UPROC, + self::REQID_NOLL, + self::REQID_NONE, + $this->_limit + ); + break; + case 'all': + default: + break; + } + $this->_releases = $this->pdo->queryDirect($query); + } + + /** + * Process releases for requestID's. + * + * @return int How many did we rename? + */ + protected function _processReleases() + { + $renamed = $checked = 0; + if ($this->_releases instanceof \Traversable) { + foreach ($this->_releases as $this->_release) { + $this->_requestID = $this->_siftReqId(); + + // Do a local lookup using multiple possible methods + $this->_newTitle = $this->_getNewTitle(); + + if ($this->_newTitle !== false && isset($this->_newTitle['title'])) { + $this->_updateRelease(); + $renamed++; + } else { + $this->_requestIdNotFound($this->_release['ID'], ($this->_release['reqidstatus'] == self::REQID_UPROC ? self::REQID_NOLL : self::REQID_NONE)); + } + + if ($this->echoOutput && $this->_show === 0) { + $this->consoleTools->overWritePrimary( + "Checked Releases: [" . number_format($checked) . "] " . + $this->consoleTools->percentString(++$checked, $this->_totalReleases) + ); + } + + } + } + + return $renamed; + } + + /** + * Get a new title / pre ID for a release. + * + * @return array|bool + */ + protected function _getNewTitle() + { + if ($this->_requestID === -2) { + return $this->_multiLookup(); + } + + $check = $this->pdo->queryDirect( + sprintf( + 'SELECT ID, title FROM prehash WHERE requestID = %d AND groupID = %d', + $this->_requestID, + $this->_release['gid'] + ) + ); + + if ($check instanceof \Traversable) { + if ($check->rowCount() == 1) { + foreach ($check as $row) { + if (preg_match('/s\d+/i', $row['title']) && !preg_match('/s\d+e\d+/i', $row['title'])) { + return false; + } + return array('title' => $row['title'], 'id' => $row['ID']); + } + } else { + //Prevents multiple releases with the same request id/group from being renamed to the same Pre. + return $this->_multiLookup(); + } + } else { + $result = $this->_singleAltLookup(); + if (is_array($result) && is_numeric($result['ID']) && $result['title'] !== '') { + return $result; + } else { + return $this->_multiLookup(); + } + } + return false; + } + + /** + * Sub function that attempts to match RequestID Releases + * by preg_matching the title from the usenet name + * + * @return array|bool + */ + protected function _multiLookup() + { + $regex1 = + '/^\[\s*\d+\s*\][ -]+(\[(ISO|FULL|PART|MP3|0DAY|android)\][ -]+)?\[(alt-?bin| ?#?a[a-z0-9. -]+)((@?ef{1,2})?net)? ?\]' . + '[ -]+(\[(ISO|FULL|PART|MP3|0DAY|android)\][ -]+)?(\[\s*\d+\s*\][ -]+)?(\[\d+\/\d+\][ -]+)?(\"|\[)\s*' . + '(?P.+?)(\.+(vol\d+\+\d+\.)?(-cd\d\.)?(avi|jpg|nzb|m3u|mkv|par2|part\d+|nfo|sample|sfv|rar|r?\d{1,3}|\d+|zip)*)?\s*(\"|\])' . + '[ -]*(\[\d+\/\d+\][ -]*)?((\"\s*(?P<filename1>.+?)([-.]sample)?([-.]cd(\d|[ab]))?(\.+(vol\d+\+\d+\.)?([-.]d\d\.)?([-.]part\d+)?' . + '(avi|jpg|nzb|m3u|mkv|par2|nfo|sample|sfv|rar|r?\d{1,3}|\d+|zip)*)?\s*\")| - (?P<filename2>.+?) (yEnc|\(\d+\/\d+\)))?.*/i' + ; + + $regex2 = + '/^\[\s*\d+\s*\].*' . + '\"\s*(?P<title>.+?)(\.+(vol\d+\+\d+\.)?(-cd\d\.)?' . + '(avi|jpg|nzb|m3u|mkv|par2|part\d+|nfo|sample|sfv|rar|r?\d{1,3}|\d+|zip)*)\s*\".*/i' + ; + + $matches = array(); + switch (true) { + case preg_match($regex1, $this->_release['name'], $matches): + case preg_match($regex2, $this->_release['name'], $matches): + $check = $this->pdo->queryOneRow( + sprintf( + "SELECT ID, title FROM prehash WHERE title = %s OR filename = %s %s", + $this->pdo->escapeString($matches['title']), + $this->pdo->escapeString($matches['title']), + ( + isset($matches['filename1']) && $matches['filename1'] !== '' + ? 'OR filename = ' . $this->pdo->escapeString($matches['filename1']) + : + ( + isset($matches['filename2']) && $matches['filename2'] !== '' + ? 'OR filename = ' . $this->pdo->escapeString($matches['filename2']) + : '' + ) + ) + ) + ); + if ($check !== false) { + return array('title' => $check['title'], 'id' => $check['ID']); + } + continue; + default: + return false; + } + return false; + } + + private $groupIDCache = array(); + + /** + * Attempts to remap the release groupID by extracting the new group name from the release usenet name. + * + * @return array|bool + */ + protected function _singleAltLookup() + { + switch (true) { + case $this->_release['name'] == 'alt.binaries.etc': + $groupName = 'alt.binaries.teevee'; + break; + case strpos($this->_release['name'], 'teevee') !== false: + $groupName = 'alt.binaries.teevee'; + break; + case strpos($this->_release['name'], 'moovee') !== false: + $groupName = 'alt.binaries.moovee'; + break; + case strpos($this->_release['name'], 'erotica') !== false: + $groupName = 'alt.binaries.erotica'; + break; + case strpos($this->_release['name'], 'foreign') !== false: + $groupName = 'alt.binaries.mom'; + break; + case strpos($this->_release['name'], 'inner-sanctum') !== false: + $groupName = 'alt.binaries.inner-sanctum'; + break; + case strpos($this->_release['name'], 'sounds.flac') !== false: + $groupName = 'alt.binaries.sounds.flac'; + break; + case strpos($this->_release['name'], 'scnzb') !== false: + $groupName = 'alt.binaries.boneless'; + break; + case strpos($this->_release['name'], 'hdtv.x264') !== false: + $groupName = 'alt.binaries.hdtv.x264'; + break; + default: + return false; + } + if (isset($this->groupIDCache[$groupName])) { + $groupID = $this->groupIDCache[$groupName]; + } else { + $groupID = $this->groups->getIDByName($groupName); + } + $check = $this->pdo->queryOneRow( + sprintf(" + SELECT ID, title FROM prehash WHERE requestID = %d AND groupID = %d", + $this->_requestID, + ($groupID === '' ? 0 : $groupID) + ) + ); + if ($check !== false) { + return array('title' => $check['title'], 'id' => $check['ID']); + } + return false; + } + + /** + * 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->updateReleaseSearchName($this->_release['id'], $newTitle); + } 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->updateReleaseSearchName($this->_release['ID'], $newTitle); + } + + 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' + ) + ); + } + } +} \ No newline at end of file diff --git a/lib/copy_this/www/lib/RequestIDWeb.php b/lib/copy_this/www/lib/RequestIDWeb.php new file mode 100644 index 000000000..7d62e9471 --- /dev/null +++ b/lib/copy_this/www/lib/RequestIDWeb.php @@ -0,0 +1,320 @@ +<?php + +require_once NN_LIB . 'util.php'; + +/** + * Attempts to find a PRE name for a release using a request ID from our local pre database, + * or internet request id database. + * + * Class RequestIDWeb + */ +class RequestIDWeb extends RequestID +{ + const MAX_WEB_LOOKUPS = 100; // Please don't exceed this, not to be to harsh on the Request ID server. + + /** + * The ID of the PRE entry the found request ID belongs to. + * @var bool|int + */ + protected $_preDbID = false; + + /** + * @var int + */ + protected $_request_hours; + + /** + * Construct. + * + * @param array $options Class instances / Echo to cli? + */ + public function __construct(array $options = array()) + { + parent::__construct($options); + $s = new Sites(); + $this->site = $s->get(); + $this->_request_hours = ($this->site->request_hours != '') ? (int)$this->site->request_hours : 1; + } + + /** + * Get all results from the releases table that have request ID's to be processed. + */ + protected function _getReleases() + { + $this->_releases = $this->pdo->queryDirect( + sprintf (' + SELECT r.ID, r.name, r.searchname, g.name AS groupname, r.groupID, r.categoryID + FROM releases r + INNER JOIN groups g ON r.groupID = g.ID + WHERE r.nzbstatus = 1 + AND r.prehashID = 0 + AND r.isrequestID = 1 + AND ( + r.reqidstatus = %d + OR (r.reqidstatus = %d AND r.adddate < NOW() - INTERVAL %d HOUR) + ) + %s %s %s + ORDER BY r.postdate DESC + LIMIT %d', + self::REQID_NOLL, + self::REQID_NONE, + $this->_request_hours, + (empty($this->_groupID) ? '' : ('AND r.groupID = ' . $this->_groupID)), + $this->_getReqIdGroups(), + ($this->_maxTime === '' ? '' : sprintf(' AND r.adddate > NOW() - INTERVAL %d HOUR', $this->_maxTime)), + $this->_limit + ) + ); + } + + /** + * Create "AND" part of query for request ID groups. + * Less load on the request ID web server, by limiting results. + * + * @return string + */ + protected function _getReqIdGroups() + { + return ( + "AND g.name IN ( + 'alt.binaries.boneless', + 'alt.binaries.cd.image', + 'alt.binaries.console.ps3', + 'alt.binaries.erotica', + 'alt.binaries.games.nintendods', + 'alt.binaries.games.wii', + 'alt.binaries.games.xbox360', + 'alt.binaries.inner-sanctum', + 'alt.binaries.mom', + 'alt.binaries.moovee', + 'alt.binaries.movies.divx', + 'alt.binaries.sony.psp', + 'alt.binaries.sounds.mp3.complete_cd', + 'alt.binaries.sounds.flac', + 'alt.binaries.teevee', + 'alt.binaries.warez'," . + + // Extra groups we will need to remap later, etc is teevee for example. + "'alt.binaries.etc' + )" + ); + } + + /** + * Process releases for requestID's. + * + * @return int How many did we rename? + */ + protected function _processReleases() + { + // Array to store results. + $requestArray = array(); + + if ($this->_releases instanceof \Traversable) { + // Loop all the results. + foreach($this->_releases as $release) { + + $this->_release['name'] = $release['name']; + // Try to find a request ID for the release. + $requestId = $this->_siftReqId(); + + // If there's none, update the release and continue. + if ($requestId === self::REQID_ZERO) { + $this->_requestIdNotFound($release['ID'], self::REQID_NONE); + if ($this->echoOutput) { + echo '-'; + } + continue; + } + + // Change etc to teevee. + if ($release['groupname'] === 'alt.binaries.etc') { + $release['groupname'] = 'alt.binaries.teevee'; + } + + // Send the release ID so we can track the return data. + $requestArray[$release['ID']] = array( + 'reqid' => $requestId, + 'ident' => $release['ID'], + 'group' => $release['groupname'], + 'sname' => $release['searchname'] + ); + } + } + + // Check if we requests to send to the web. + if (count($requestArray) < 1) { + return 0; + } + + // Mock array for isset check on server. + $requestArray[0] = ['ident' => 0, 'group' => 'none', 'reqid' => 0]; + + // Do a web lookup. + $returnXml = Utility::getUrl([ + 'url' => $this->site->request_url, + 'method' => 'post', + 'postdata' => 'data=' . serialize($requestArray), + 'verifycert' => false, + ] + ); + + $renamed = 0; + // Change the release titles and insert the PRE's if they don't exist. + if ($returnXml !== false) { + $returnXml = @simplexml_load_string($returnXml); + if ($returnXml !== false) { + + // Store the returned identifiers so we can check which releases we didn't find a request id. + $returnedIdentifiers = []; + + $groupIDArray = []; + foreach($returnXml->request as $result) { + if (isset($result['name']) && isset($result['ident']) && (int)$result['ident'] > 0) { + $this->_newTitle['title'] = (string)$result['name']; + $this->_requestID = (int)$result['reqid']; + $this->_release['ID'] = (int)$result['ident']; + + // Buffer groupID queries. + $this->_release['groupname'] = $requestArray[(int)$result['ident']]['group']; + if (isset($groupIDarray[$this->_release['groupname']])) { + $this->_release['groupID'] = $groupIDArray[$this->_release['groupname']]; + } else { + $this->_release['groupID'] = $this->groups->getIDByName($this->_release['groupname']); + $groupIDArray[$this->_release['groupname']] = $this->_release['groupID']; + } + $this->_release['gid'] = $this->_release['groupID']; + + $this->_release['searchname'] = $requestArray[(int)$result['ident']]['sname']; + $this->_insertIntoPreDB(); + if ($this->_preDbID === false) { + $this->_preDbID = 0; + } + $this->_newTitle['ID'] = $this->_preDbID; + $this->_updateRelease(); + $renamed++; + if ($this->echoOutput) { + echo '+'; + } + $returnedIdentifiers[] = (string)$result['ident']; + } + } + + // Check if the WEB didn't send back some titles, update the release. + if (count($returnedIdentifiers) > 0) { + foreach ($returnedIdentifiers as $identifier) { + if (array_key_exists($identifier, $requestArray)) { + unset($requestArray[$identifier]); + } + } + } + + unset($requestArray[0]); + foreach ($requestArray as $request) { + + $addDate = $this->pdo->queryOneRow( + sprintf( + 'SELECT UNIX_TIMESTAMP(adddate) AS adddate FROM releases WHERE ID = %d', $request['ident'] + ) + ); + + $status = self::REQID_NONE; + if ($addDate !== false && !empty($addDate['adddate'])) { + if ((bool) (intval((time() - (int)$addDate['adddate']) / 3600) > $this->_request_hours)) { + $status = self::REQID_OLD; + } + } else { + $status = self::REQID_OLD; + } + + $this->_requestIdNotFound( + $request['ident'], + $status + ); + if ($this->echoOutput) { + echo '-'; + } + } + } + } + return $renamed; + } + + /** + * If we found a request ID on the internet, check if our PRE database has it, insert it if not. + */ + protected function _insertIntoPreDB() + { + $dupeCheck = $this->pdo->queryOneRow( + sprintf(' + SELECT ID AS prehashID, requestID, groupID + FROM prehash + WHERE title = %s', + $this->pdo->escapeString($this->_newTitle['title']) + ) + ); + + if ($dupeCheck === false) { + $this->_preDbID = (int)$this->pdo->queryInsert( + sprintf(" + INSERT INTO prehash (title, source, requestID, groupID, predate) + VALUES (%s, %s, %d, %d, NOW())", + $this->pdo->escapeString($this->_newTitle['title']), + $this->pdo->escapeString('requestWEB'), + $this->_requestID, + $this->_release['groupID'] + ) + ); + } else { + $this->_preDbID = $dupeCheck['prehashID']; + $this->pdo->queryExec( + sprintf(' + UPDATE prehash + SET requestID = %d, groupID = %d + WHERE ID = %d', + $this->_requestID, + $this->_release['groupID'], + $this->_preDbID + ) + ); + } + } + + /** + * If we found a PRE name, update the releases name and reset post processing. + */ + protected function _updateRelease() + { + $determinedCategory = $this->category->determineCategory($this->_release['groupID'], $this->_newTitle['title']); + $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, + prehashID = %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>' + ) + ); + } + } +} \ No newline at end of file diff --git a/lib/copy_this/www/templates/nntmux/views/admin/site-edit.tpl b/lib/copy_this/www/templates/nntmux/views/admin/site-edit.tpl index 01797bc2d..9c9b593e9 100644 --- a/lib/copy_this/www/templates/nntmux/views/admin/site-edit.tpl +++ b/lib/copy_this/www/templates/nntmux/views/admin/site-edit.tpl @@ -1066,6 +1066,35 @@ </table> </fieldset> +<fieldset id="site_requidset"> + <legend>RequestID Settings</legend> + <table class="input"> + <tr> + <td style="width:180px;"><label for="lookup_reqids">Lookup Request IDs:</label></td> + <td> + {html_options style="width:180px;" id="lookup_reqids" name='lookup_reqids' values=$lookup_reqids_ids output=$lookup_reqids_names selected=$site->lookup_reqids} + <div class="hint">Whether to attempt to lookup Request IDs using the Request ID link below. This will rename your releases to proper PreDB names.</div> + </td> + </tr> + <tr> + <td style="width:180px;"><label for="request_url">Request ID Link:</label></td> + <td> + <input id="request_url" class="long" name="request_url" type="text" value="{$site->request_url}"/> + <div class="hint">Optional URL to lookup Request IDs. [REQUEST_ID] gets replaced with the request ID from the + post. [GROUP_NM] Gets replaced with the group name. + </div> + </td> + </tr> + <tr> + <td style="width:180px;"><label for="request_hours">Max hours to recheck Request IDs:</label></td> + <td> + <input id="request_hours" class="short" name="request_hours" type="text" value="{$site->request_hours}"/> + <div class="hint">The maximum hours after a release is added to recheck for a Request ID match.</div> + </td> + </tr> + </table> +</fieldset> + <fieldset> <legend>Advanced - Postprocessing Settings</legend> <table class="input"> diff --git a/lib/requestid.php b/lib/requestid.php new file mode 100644 index 000000000..ab5c3a1ec --- /dev/null +++ b/lib/requestid.php @@ -0,0 +1,33 @@ +<?php +require_once(dirname(__FILE__)."/../bin/config.php"); +require_once NN_LIB . 'ColorCLI.php'; +require_once NN_LIB . 'RequestIDWeb.php'; +require_once NN_LIB . 'RequestIDLocal.php'; + +$cli = new \ColorCLI(); + +if (!isset($argv[1]) || ($argv[1] != "all" && $argv[1] != "full" && $argv[1] != "web" && !is_numeric($argv[1])) || !isset($argv[2]) || !in_array($argv[2], ['true', 'false'])) { + exit ($cli->error( + PHP_EOL + . "This script tries to match a release request ID by group to a PreDB request ID by group doing local lookup only." . PHP_EOL + . "In addition an optional final argument is time, in minutes, to check releases that have previously been checked." . PHP_EOL . PHP_EOL + . "Argument 1: full|all|number|web => (mandatory)" . PHP_EOL + . "all does only requestid releases, full does full database, number limits to x amount of releases, web does web requestID's" . PHP_EOL + . "Argument 2: true|false => (mandatory) Display full info on how the release was renamed or not." . PHP_EOL + . "Argument 3: number => (optional) This is to limit how old the releases to work on (in hours)." . PHP_EOL + . "php requestid.php 1000 true => to limit to 1000 sorted by newest postdate and show renaming." . PHP_EOL . PHP_EOL + . "php requestid.php full true => to run on full database and show renaming." . PHP_EOL + . "php requestid.php all true => to run on all requestid releases (including previously renamed) and show renaming." . PHP_EOL + ) + ); +} + +if ($argv[1] === 'web') { + (new \RequestIDWeb())->lookupRequestIDs( + ['limit' => $argv[1], 'show' => $argv[2], 'time' => (isset($argv[3]) && is_numeric($argv[3]) && $argv[3] > 0 ? $argv[3] : 0)] + ); +} else { + (new \RequestIDLocal())->lookupRequestIDs( + ['limit' => $argv[1], 'show' => $argv[2], 'time' => (isset($argv[3]) && is_numeric($argv[3]) && $argv[3] > 0 ? $argv[3] : 0)] + ); +} diff --git a/python/requestid_threaded.py b/python/requestid_threaded.py index 7b9400468..68764a501 100644 --- a/python/requestid_threaded.py +++ b/python/requestid_threaded.py @@ -44,10 +44,10 @@ except: print(bcolors.HEADER + "\n\nRequestID Threaded Started at {}".format(datetime.datetime.now().strftime("%H:%M:%S")) + bcolors.ENDC) -cur[0].execute("SELECT value FROM tmux WHERE setting = 'request_hours'") +cur[0].execute("SELECT value FROM site WHERE setting = 'request_hours'") dbgrab = cur[0].fetchone() request_hours = str(dbgrab[0]) -cur[0].execute("SELECT r.ID, r.name, g.name AS groupname FROM releases r LEFT JOIN groups g ON r.groupID = g.ID WHERE nzbstatus = 1 AND isrenamed = 0 AND isrequestid = 1 AND reqidstatus in (0, -1) OR (reqidstatus = -3 AND adddate > NOW() - INTERVAL " + request_hours + " HOUR) LIMIT 100000") +cur[0].execute("SELECT DISTINCT(g.ID) FROM releases r INNER JOIN groups g ON r.groupID = g.ID WHERE r.nzbstatus = 1 AND r.prehashID = 0 AND r.isrequestid = 1 AND r.reqidstatus in (0, -1) OR (r.reqidstatus = -3 AND r.adddate > NOW() - INTERVAL " + request_hours + " HOUR)") datas = cur[0].fetchall() #close connection to mysql