/** * Retrieve alternate release with same or similar searchname * * @param string $guid * @param string $searchname * @param string $userid * @return string */ public function getAlternate($guid, $searchname, $userid) { $rel = $this->pdo->queryOneRow(sprintf(' SELECT id, categoryid FROM releases WHERE guid = %s', $this->pdo->escapeString($guid))); // Specifying LAST_INSERT_ID on releaseid will return the releaseid // if the row was actually inserted and not updated $insert = $this->pdo->queryInsert(sprintf(' INSERT INTO dnzb_failures (release_id, userid, failed) VALUES (LAST_INSERT_ID(%d), %d, 1) ON DUPLICATE KEY UPDATE failed = failed + 1', $rel['id'], $userid)); // If we didn't actually insert the row, don't add a comment if ((int) $insert > 0) { $this->postComment($rel['id'], $userid); } $alternate = $this->pdo->queryOneRow(sprintf(' SELECT r.* FROM releases r LEFT JOIN dnzb_failures df ON r.id = df.release_id WHERE r.searchname %s AND df.release_id IS NULL AND r.categoryid = %d', $this->pdo->likeString($searchname, true, true), $rel['categoryid'], $userid)); return $alternate; }
/** * Retrieve alternate release with same or similar searchname * * @param string $guid * @param string $userid * @return string */ public function getAlternate($guid, $userid) { $rel = $this->pdo->queryOneRow(sprintf(' SELECT id, searchname, categoryid FROM releases WHERE guid = %s', $this->pdo->escapeString($guid))); if ($rel === false) { return false; } $insert = $this->pdo->queryInsert(sprintf(' INSERT IGNORE INTO dnzb_failures (release_id, userid, failed) VALUES (%d, %d, 1)', $rel['id'], $userid)); // If we didn't actually insert the row, don't add a comment if (is_numeric($insert) && $insert > 0) { $this->postComment($rel['id'], $userid); } $alternate = $this->pdo->queryOneRow(sprintf(' SELECT r.guid FROM releases r LEFT JOIN dnzb_failures df ON r.id = df.release_id WHERE r.searchname %s AND df.release_id IS NULL AND r.categoryid = %d AND r.id != %d ORDER BY r.postdate DESC', $this->pdo->likeString($rel['searchname'], true, true), $rel['categoryid'], $rel['id'])); return $alternate; }
/** * Retrieve alternate release with same or similar searchname * * @param string $guid * @param string $searchname * @param string $userid * @return string */ public function getAlternate($guid, $searchname, $userid) { $this->pdo->queryInsert(sprintf("INSERT IGNORE INTO dnzb_failures (userid, guid) VALUES (%d, %s)", $userid, $this->pdo->escapeString($guid))); $rel = $this->pdo->queryOneRow(sprintf('SELECT id FROM releases WHERE guid = %s', $this->pdo->escapeString($guid))); $this->postComment($rel['id'], $userid); $alternate = $this->pdo->queryOneRow(sprintf('SELECT * FROM releases r WHERE r.searchname %s AND r.guid NOT IN (SELECT guid FROM dnzb_failures WHERE userid = %d)', $this->pdo->likeString($searchname), $userid)); return $alternate; }
/** * Add new files for a release ID. * * @param int $id The ID of the release. * @param string $name Name of the file. * @param int $size Size of the file. * @param int $createdTime Unix time the file was created. * @param int $hasPassword Does it have a password (see Releases class constants)? * * @return mixed */ public function add($id, $name, $size, $createdTime, $hasPassword) { $duplicateCheck = $this->pdo->queryOneRow(sprintf(' SELECT id FROM release_files WHERE releaseid = %d AND name = %s', $id, $this->pdo->escapeString(utf8_encode($name)))); if ($duplicateCheck === false) { return $this->pdo->queryInsert(sprintf("\n\t\t\t\t\tINSERT INTO release_files\n\t\t\t\t\t(releaseid, name, size, createddate, passworded)\n\t\t\t\t\tVALUES\n\t\t\t\t\t(%d, %s, %s, %s, %d)", $id, $this->pdo->escapeString(utf8_encode($name)), $this->pdo->escapeString($size), $this->pdo->from_unixtime($createdTime), $hasPassword)); } return 0; }
public function addComment($id, $text, $userid, $host) { if ($this->pdo->getSetting('storeuserips') != "1") { $host = ""; } $username = $this->pdo->queryOneRow(sprintf('SELECT username FROM users WHERE id = %d', $userid)); $username = $username === false ? 'ANON' : $username['username']; $comid = $this->pdo->queryInsert(sprintf("\n\t\t\t\tINSERT INTO release_comments (releaseid, text, user_id, createddate, host, username)\n\t\t\t\tVALUES (%d, %s, %d, NOW(), %s, %s)", $id, $this->pdo->escapeString($text), $userid, $this->pdo->escapeString($host), $this->pdo->escapeString($username))); $this->updateReleaseCommentCount($id); return $comid; }
public function add($parentid, $userid, $subject, $message, $locked = 0, $sticky = 0, $replies = 0) { if ($message == "") { return -1; } if ($parentid != 0) { $par = $this->getParent($parentid); if ($par == false) { return -1; } $this->pdo->queryExec(sprintf("UPDATE forumpost SET replies = replies + 1, updateddate = NOW() WHERE id = %d", $parentid)); } return $this->pdo->queryInsert(sprintf("\n\t\t\t\tINSERT INTO forumpost (forumid, parentid, user_id, subject, message, locked, sticky, replies, createddate, updateddate)\n\t\t\t\tVALUES (1, %d, %d, %s, %s, %d, %d, %d, NOW(), NOW())", $parentid, $userid, $this->pdo->escapeString($subject), $this->pdo->escapeString($message), $locked, $sticky, $replies)); }
/** * Update the list of newsgroups and return an array of messages. * * @param string $groupList * @param int $active * @param int $backfill * * @return array */ public function addBulk($groupList, $active = 1, $backfill = 1) { if (preg_match('/^\\s*$/m', $groupList)) { $ret = "No group list provided."; } else { $nntp = new NNTP(['Echo' => false]); if ($nntp->doConnect() !== true) { return 'Problem connecting to usenet.'; } $groups = $nntp->getGroups(); $nntp->doQuit(); if ($nntp->isError($groups)) { return 'Problem fetching groups from usenet.'; } $regFilter = '/' . $groupList . '/i'; $ret = []; foreach ($groups as $group) { if (preg_match($regFilter, $group['group']) > 0) { $res = $this->pdo->queryOneRow(sprintf('SELECT id FROM groups WHERE name = %s', $this->pdo->escapeString($group['group']))); if ($res === false) { $this->pdo->queryInsert(sprintf('INSERT INTO groups (name, active, backfill) VALUES (%s, %d, %d)', $this->pdo->escapeString($group['group']), $active, $backfill)); $ret[] = ['group' => $group['group'], 'msg' => 'Created']; } } } if (count($ret) === 0) { $ret = 'No groups found with your regex, try again!'; } } return $ret; }
public function addFull($id, $xml) { $ckid = $this->pdo->queryOneRow(sprintf('SELECT releaseid FROM releaseextrafull WHERE releaseid = %s', $id)); if (!isset($ckid['releaseid'])) { return $this->pdo->queryExec(sprintf('INSERT INTO releaseextrafull (releaseid, mediainfo) VALUES (%d, %s)', $id, $this->pdo->escapeString($xml))); } }
/** * Inserts Genre and returns last affected row (Genre ID) * * @param $genre * * @return bool */ private function insertGenre($genre) { if (isset($genre)) { $res = $this->pdo->queryInsert(sprintf("INSERT INTO genres (title, type, disabled) VALUES (%s ,%d ,%d)", $this->pdo->escapeString($genre), 6000, 0)); return $res; } }
/** * Fetch a comment and insert it. * * @param string $messageID Message-ID for the article. * @param string $siteID ID of the site. * * @return bool * * @access protected */ protected function insertNewComment(&$messageID, &$siteID) { // Get the article body. $body = $this->nntp->getMessages(self::group, $messageID); // Check if there's an error. if ($this->nntp->isError($body)) { return false; } // Decompress the body. $body = @gzinflate($body); if ($body === false) { return false; } // JSON Decode the body. $body = json_decode($body, true); if ($body === false) { return false; } // Just in case. if (!isset($body['USER']) || !isset($body['SID']) || !isset($body['RID']) || !isset($body['TIME']) | !isset($body['BODY'])) { return false; } // Insert the comment. if ($this->pdo->queryExec(sprintf(' INSERT INTO release_comments (text, createddate, shareid, nzb_guid, siteid, username, user_id, releaseid, shared, host) VALUES (%s, %s, %s, UNHEX(%s), %s, %s, 0, 0, 2, "")', $this->pdo->escapeString($body['BODY']), $this->pdo->from_unixtime($body['TIME'] > time() ? time() : $body['TIME']), $this->pdo->escapeString($body['SID']), $this->pdo->escapeString($body['RID']), $this->pdo->escapeString($siteID), $this->pdo->escapeString(substr($body['USER'], 0, 3) === 'sn-' ? 'SH_ANON' : 'SH_' . $body['USER'])))) { return true; } return false; }
/** This function updates a single variable column in releases * The first parameter is the column to update, the second is the value * The final parameter is the ID of the release to update * * @param string $column * @param integer $status * @param integer $id */ private function _updateSingleColumn($column = '', $status = 0, $id = 0) { if ($column !== '' && $id !== 0) { $this->pdo->queryExec(sprintf(' UPDATE releases SET %s = %s WHERE id = %d', $column, is_numeric($status) ? $status : $this->pdo->escapeString($status), $id)); } }
/** * Retrieve alternate release with same or similar searchname * * @param string $guid * @param string $searchname * @param string $userid * @return string */ public function getAlternate($guid, $searchname, $userid) { //status values // 0/false = successfully downloaded // 1/true = failed download $this->pdo->queryInsert(sprintf("INSERT IGNORE INTO dnzb_failures (userid, guid) VALUES (%d, %s)", $userid, $this->pdo->escapeString($guid))); $alternate = $this->pdo->queryOneRow(sprintf('SELECT * FROM releases r WHERE r.searchname %s AND r.guid NOT IN (SELECT guid FROM failed_downloads WHERE userid = %d)', $this->pdo->likeString($searchname), $userid)); return $alternate; }
/** * Get the regex from the DB, cache them locally for 15 mins. * Cache them also in the cache server, as this script might be terminated. * * @param string $groupName */ protected function _fetchRegex($groupName) { // Check if we need to do an initial cache or refresh our cache. if (isset($this->_regexCache[$groupName]['ttl']) && time() - $this->_regexCache[$groupName]['ttl'] < 900) { return; } // Get all regex from DB which match the current group name. Cache them for 15 minutes. #CACHEDQUERY# $this->_regexCache[$groupName]['regex'] = $this->pdo->query(sprintf('SELECT r.regex%s FROM %s r WHERE %s REGEXP r.group_regex AND r.status = 1 ORDER BY r.ordinal ASC, r.group_regex ASC', $this->tableName === 'category_regexes' ? ', r.category_id' : '', $this->tableName, $this->pdo->escapeString($groupName)), true, 900); // Set the TTL. $this->_regexCache[$groupName]['ttl'] = time(); }
/** * Retrieves a list of Anime titles, optionally filtered by starting character and title * * @param string $letter * @param string $animetitle * @return array|bool */ public function getAnimeList($letter = '', $animetitle = '') { $regex = 'REGEXP'; $rsql = ''; if ($letter != '') { if ($letter == '0-9') { $letter = '[0-9]'; } $rsql .= sprintf('AND at.title %s %s', $regex, $this->pdo->escapeString('^' . $letter)); } $tsql = ''; if ($animetitle != '') { $tsql .= sprintf('AND at.title %s', $this->pdo->likeString($animetitle, true, true)); } return $this->pdo->queryDirect(sprintf('SELECT at.anidbid, at.title, ai.type, ai.categories, ai.rating, ai.startdate, ai.enddate FROM anidb_titles AS at LEFT JOIN anidb_info AS ai USING (anidbid) WHERE at.anidbid > 0 %s %s GROUP BY at.anidbid ORDER BY at.title ASC', $rsql, $tsql)); }
/** * Updates existing anime info in anidb info/episodes tables * * @param array $AniDBInfoArray * * @return string */ private function updateAniDBInfoEps($AniDBInfoArray = []) { $this->pdo->queryExec(sprintf(' UPDATE anidb_info SET type = %s, startdate = %s, enddate = %s, related = %s, similar = %s, creators = %s, description = %s, rating = %s, picture = %s, categories = %s, characters = %s, updated = NOW() WHERE anidbid = %d', $this->pdo->escapeString($AniDBInfoArray['type']), $this->pdo->escapeString($AniDBInfoArray['startdate']), $this->pdo->escapeString($AniDBInfoArray['enddate']), $this->pdo->escapeString($AniDBInfoArray['related']), $this->pdo->escapeString($AniDBInfoArray['similar']), $this->pdo->escapeString($AniDBInfoArray['creators']), $this->pdo->escapeString($AniDBInfoArray['description']), $this->pdo->escapeString($AniDBInfoArray['rating']), $this->pdo->escapeString($AniDBInfoArray['picture']), $this->pdo->escapeString($AniDBInfoArray['categories']), $this->pdo->escapeString($AniDBInfoArray['characters']), $this->anidbId)); $this->insertAniDBEpisodes($AniDBInfoArray['epsarr']); return $AniDBInfoArray['picture']; }
/** * Checks if a user is a specific role. * * @notes Uses type of $user to denote identifier. if string: username, if int: userid * @param int $roleID * @param string|int $user * @return bool */ public function roleCheck($roleID, $user) { if (is_string($user) && strlen($user) > 0) { $user = $this->pdo->escapeString($user); $querySuffix = "username = {$user}"; } elseif (is_int($user) && $user >= 0) { $querySuffix = "id = {$user}"; } else { return false; } $result = $this->pdo->queryOneRow(sprintf("SELECT role FROM users WHERE %s", $querySuffix)); return (int) $result['role'] == (int) $roleID ? true : false; }
/** * Delete release from Sphinx RT tables. * @param array $identifiers ['g' => Release GUID(mandatory), 'id' => ReleaseID(optional, pass false)] * @param \nzedb\db\Settings $pdo */ public function deleteRelease($identifiers, Settings $pdo) { if (!is_null($this->sphinxQL)) { if ($identifiers['i'] === false) { $identifiers['i'] = $pdo->queryOneRow(sprintf('SELECT id FROM releases WHERE guid = %s', $pdo->escapeString($identifiers['g']))); if ($identifiers['i'] !== false) { $identifiers['i'] = $identifiers['i']['id']; } } if ($identifiers['i'] !== false) { $this->sphinxQL->queryExec(sprintf('DELETE FROM releases_rt WHERE id = %d', $identifiers['i'])); } } }
public function proc_query($qry, $bookreqids, $request_hours, $db_name) { switch ((int) $qry) { case 1: return sprintf("SELECT\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid BETWEEN 5000 AND 5999 AND rageid = -1,1,0)) AS processtvrage,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid = 5070 AND anidbid IS NULL,1,0)) AS processanime,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid BETWEEN 2000 AND 2999 AND imdbid IS NULL,1,0)) AS processmovies,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid IN (3010, 3040, 3050) AND musicinfoid IS NULL,1,0)) AS processmusic,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid BETWEEN 1000 AND 1999 AND consoleinfoid IS NULL,1,0)) AS processconsole,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid IN (%s) AND bookinfoid IS NULL,1,0)) AS processbooks,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid = 4050 AND gamesinfo_id = 0,1,0)) AS processgames,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND categoryid BETWEEN 6000 AND 6040 AND xxxinfo_id = 0,1,0)) AS processxxx,\n\t\t\t\t\tSUM(IF(1=1 %s,1,0)) AS processnfo,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND nfostatus = 1,1,0)) AS nfo,\n\t\t\t\t\tSUM(IF(nzbstatus = 1 AND isrequestid = 1 AND preid = 0 AND\n\t\t\t\t\t\t((reqidstatus = 0) OR (reqidstatus = -1) OR (reqidstatus = -3 AND adddate > NOW() - INTERVAL %s HOUR)),1,0)) AS requestid_inprogress,\n\t\t\t\t\tSUM(IF(preid > 0 AND nzbstatus = 1 AND isrequestid = 1 AND reqidstatus = 1,1,0)) AS requestid_matched,\n\t\t\t\t\tSUM(IF(preid > 0 AND searchname IS NOT NULL,1,0)) AS predb_matched,\n\t\t\t\t\tCOUNT(DISTINCT(preid)) AS distinct_predb_matched\n\t\t\t\t\tFROM releases r", $bookreqids, Nfo::NfoQueryString($this->pdo), $request_hours); case 2: return "SELECT\n\t\t\t\t\t(SELECT COUNT(*) FROM releases r\n\t\t\t\t\t\tINNER JOIN category c ON c.id = r.categoryid\n\t\t\t\t\t\tWHERE r.nzbstatus = 1\n\t\t\t\t\t\tAND r.passwordstatus BETWEEN -6 AND -1 AND r.haspreview = -1 AND c.disablepreview = 0\n\t\t\t\t\t) AS work,\n\t\t\t\t\t(SELECT COUNT(*) FROM groups WHERE active = 1) AS active_groups,\n\t\t\t\t\t(SELECT COUNT(*) FROM groups WHERE name IS NOT NULL) AS all_groups"; case 4: return sprintf("\n\t\t\t\t\tSELECT\n\t\t\t\t\t(SELECT TABLE_ROWS FROM information_schema.TABLES WHERE table_name = 'predb' AND TABLE_SCHEMA = %1\$s) AS predb,\n\t\t\t\t\t(SELECT TABLE_ROWS FROM information_schema.TABLES WHERE table_name = 'missed_parts' AND TABLE_SCHEMA = %1\$s) AS missed_parts_table,\n\t\t\t\t\t(SELECT TABLE_ROWS FROM information_schema.TABLES WHERE table_name = 'parts' AND TABLE_SCHEMA = %1\$s) AS parts_table,\n\t\t\t\t\t(SELECT TABLE_ROWS FROM information_schema.TABLES WHERE table_name = 'binaries' AND TABLE_SCHEMA = %1\$s) AS binaries_table,\n\t\t\t\t\t(SELECT TABLE_ROWS FROM information_schema.TABLES WHERE table_name = 'collections' AND TABLE_SCHEMA = %1\$s) AS collections_table,\n\t\t\t\t\t(SELECT TABLE_ROWS FROM information_schema.TABLES WHERE table_name = 'releases' AND TABLE_SCHEMA = %1\$s) AS releases,\n\t\t\t\t\t(SELECT COUNT(*) FROM groups WHERE first_record IS NOT NULL AND backfill = 1\n\t\t\t\t\t\tAND (now() - INTERVAL backfill_target DAY) < first_record_postdate\n\t\t\t\t\t) AS backfill_groups_days,\n\t\t\t\t\t(SELECT COUNT(*) FROM groups WHERE first_record IS NOT NULL AND backfill = 1 AND (now() - INTERVAL datediff(curdate(),\n\t\t\t\t\t(SELECT VALUE FROM settings WHERE setting = 'safebackfilldate')) DAY) < first_record_postdate) AS backfill_groups_date", $this->pdo->escapeString($db_name)); case 6: return "SELECT\n\t\t\t\t\t(SELECT searchname FROM releases ORDER BY id DESC LIMIT 1) AS newestrelname,\n\t\t\t\t\t(SELECT UNIX_TIMESTAMP(MIN(dateadded)) FROM collections) AS oldestcollection,\n\t\t\t\t\t(SELECT UNIX_TIMESTAMP(MAX(predate)) FROM predb) AS newestpre,\n\t\t\t\t\t(SELECT UNIX_TIMESTAMP(adddate) FROM releases ORDER BY id DESC LIMIT 1) AS newestrelease"; default: return false; } }
/** * Retrieves all aliases for given VideoID or VideoID for a given alias * * @param int $videoId * @param string $alias * * @return \PDOStatement|false */ public function getAliases($videoId = 0, $alias = '') { $return = false; $sql = ''; if ($videoId > 0) { $sql = 'videos_id = ' . $videoId; } else { if ($alias !== '') { $sql = 'title = ' . $this->pdo->escapeString($alias); } } if ($sql !== '') { $return = $this->pdo->query(' SELECT * FROM videos_aliases WHERE ' . $sql, true, nZEDb_CACHE_EXPIRY_MEDIUM); } return empty($return) ? false : $return; }
/** * 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($newName, $this->_release['group_id']); $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, preid = 0, searchname = %s, isrenamed = 1, iscategorized = 1, proc_files = 1, categoryid = %d WHERE id = %d', $newTitle, $newCategory, $this->_release['id'])); $this->sphinx->updateReleaseSearchName($this->_release['id'], $newTitle); // Echo the changed name to CLI. if ($this->_echoCLI) { \NameFixer::echoChangedReleaseName(array('new_name' => $newName, 'old_name' => $this->_release['searchname'], 'new_category' => $newCategory, 'old_category' => $this->_release['categoryid'], 'group' => $this->_release['group_id'], 'release_id' => $this->_release['id'], 'method' => 'ProcessAdditional->_processU4ETitle')); } // Break out of the loop. break; } } // Close the file. fclose($handle); } // Delete the file. @unlink($fileLocation); }
/** * @param array $con * * @return false|int|string */ protected function _updateConsoleTable($con = []) { $ri = new ReleaseImage($this->pdo); $check = $this->pdo->queryOneRow(sprintf(' SELECT id FROM consoleinfo WHERE asin = %s', $this->pdo->escapeString($con['asin']))); if ($check === false) { $consoleId = $this->pdo->queryInsert(sprintf("INSERT INTO consoleinfo (title, asin, url, salesrank, platform, publisher, genre_id, esrb, releasedate, review, cover, createddate, updateddate)\n\t\t\t\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, NOW(), NOW())", $this->pdo->escapeString($con['title']), $this->pdo->escapeString($con['asin']), $this->pdo->escapeString($con['url']), $con['salesrank'], $this->pdo->escapeString($con['platform']), $this->pdo->escapeString($con['publisher']), $con['consolegenreID'] == -1 ? "null" : $con['consolegenreID'], $this->pdo->escapeString($con['esrb']), $con['releasedate'] != "" ? $this->pdo->escapeString($con['releasedate']) : "null", $this->pdo->escapeString(substr($con['review'], 0, 3000)), $con['cover'])); if ($con['cover'] === 1) { $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250); } } else { $consoleId = $check['id']; if ($con['cover'] === 1) { $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250); } $this->update($consoleId, $con['title'], $con['asin'], $con['url'], $con['salesrank'], $con['platform'], $con['publisher'], isset($con['releasedate']) ? $con['releasedate'] : null, $con['esrb'], $con['cover'], $con['consolegenreID'], isset($con['review']) ? $con['review'] : null); } return $consoleId; }
/** * Insert the NZB details into the database. * * @param $nzbDetails * * @return bool * * @access protected */ protected function insertNZB($nzbDetails) { // Make up a GUID for the release. $this->relGuid = $this->releases->createGUID(); // Remove part count from subject. $partLess = preg_replace('/(\\(\\d+\\/\\d+\\))*$/', 'yEnc', $nzbDetails['subject']); // Remove added yEnc from above and anything after. $subject = utf8_encode(trim(preg_replace('/yEnc.*$/i', 'yEnc', $partLess))); $renamed = 0; if ($nzbDetails['useFName']) { // If the user wants to use the file name.. use it. $cleanName = $nzbDetails['useFName']; $renamed = 1; } else { // Pass the subject through release cleaner to get a nicer name. $cleanName = $this->releaseCleaner->releaseCleaner($subject, $nzbDetails['from'], $nzbDetails['totalSize'], $nzbDetails['groupName']); if (isset($cleanName['properlynamed'])) { $cleanName = $cleanName['cleansubject']; $renamed = isset($cleanName['properlynamed']) && $cleanName['properlynamed'] === true ? 1 : 0; } } $escapedSubject = $this->pdo->escapeString($subject); $escapedFromName = $this->pdo->escapeString($nzbDetails['from']); // Look for a duplicate on name, poster and size. $dupeCheck = $this->pdo->queryOneRow(sprintf('SELECT id FROM releases WHERE name = %s AND fromname = %s AND size BETWEEN %s AND %s', $escapedSubject, $escapedFromName, $this->pdo->escapeString($nzbDetails['totalSize'] * 0.99), $this->pdo->escapeString($nzbDetails['totalSize'] * 1.01))); if ($dupeCheck === false) { $escapedSearchName = $this->pdo->escapeString($cleanName); // Insert the release into the DB. $relID = $this->releases->insertRelease(['name' => $escapedSubject, 'searchname' => $escapedSearchName, 'totalpart' => $nzbDetails['totalFiles'], 'group_id' => $nzbDetails['group_id'], 'guid' => $this->pdo->escapeString($this->relGuid), 'postdate' => $this->pdo->escapeString($nzbDetails['postDate']), 'fromname' => $escapedFromName, 'size' => $this->pdo->escapeString($nzbDetails['totalSize']), 'categoryid' => $this->category->determineCategory($nzbDetails['group_id'], $cleanName), 'isrenamed' => $renamed, 'reqidstatus' => 0, 'preid' => 0, 'nzbstatus' => NZB::NZB_ADDED]); } else { //$this->echoOut('This release is already in our DB so skipping: ' . $subject); return false; } if (isset($relID) && $relID === false) { $this->echoOut('ERROR: Problem inserting: ' . $subject); return false; } return true; }
/** * Update a category. * @param $id * @param $status * @param $desc * @param $disablepreview * @param $minsize * * @return bool */ public function update($id, $status, $desc, $disablepreview, $minsize) { return $this->pdo->queryExec(sprintf("UPDATE category SET disablepreview = %d, status = %d, description = %s, minsize = %d\n\t\t\t\tWHERE id = %d", $disablepreview, $status, $this->pdo->escapeString($desc), $minsize, $id)); }
/** * Process each game, updating game information from Giantbomb * * @param $gameInfo * * @return bool */ public function updateGamesInfo($gameInfo) { $gen = new Genres(['Settings' => $this->pdo]); $ri = new ReleaseImage($this->pdo); $con = []; // Process Steam first before giantbomb // Steam has more details $this->_gameResults = []; $this->_getGame = new Steam(); $this->_classUsed = "steam"; $this->_getGame->cookie = $this->cookie; $this->_getGame->searchTerm = $gameInfo['title']; if ($this->_getGame->search() !== false) { $this->_gameResults = $this->_getGame->getAll(); } if (count($this->_gameResults) < 1) { $this->_getGame = new Desura(); $this->_classUsed = "desura"; $this->_getGame->cookie = $this->cookie; $this->_getGame->searchTerm = $gameInfo['title']; if ($this->_getGame->search() !== false) { $this->_gameResults = $this->_getGame->getAll(); } } if (count($this->_gameResults) < 1) { $this->_getGame = new Greenlight(); $this->_classUsed = "gl"; $this->_getGame->cookie = $this->cookie; $this->_getGame->searchTerm = $gameInfo['title']; if ($this->_getGame->search() !== false) { $this->_gameResults = $this->_getGame->getAll(); } } if (count($this->_gameResults) < 1) { $this->_gameResults = (array) $this->fetchGiantBombID($gameInfo['title']); if ($this->maxHitRequest === true) { return false; } } if (empty($this->_gameResults['title'])) { return false; } if (!is_array($this->_gameResults)) { return false; } if (count($this->_gameResults) > 1) { $genreName = ''; switch ($this->_classUsed) { case "desura": if (isset($this->_gameResults['cover'])) { $con['coverurl'] = (string) $this->_gameResults['cover']; } if (isset($this->_gameResults['backdrop'])) { $con['backdropurl'] = (string) $this->_gameResults['backdrop']; } $con['title'] = (string) $this->_gameResults['title']; $con['asin'] = $this->_gameResults['desuragameid']; $con['url'] = (string) $this->_gameResults['directurl']; if (isset($this->_gameResults['gamedetails']['Publisher'])) { $con['publisher'] = (string) $this->_gameResults['gamedetails']['Publisher']; } else { $con['publisher'] = "Unknown"; } if (isset($this->_gameResults['rating'])) { $con['esrb'] = (string) $this->_gameResults['rating']; } else { $con['esrb'] = "Not Rated"; } if (isset($this->_gameResults['description'])) { $con['review'] = trim(strip_tags((string) $this->_gameResults['description'])); } if (isset($this->_gameResults['trailer'])) { $con['trailer'] = (string) $this->_gameResults['trailer']; } if (isset($this->_gameResults['gamedetails']['Genre'])) { $genres = (string) $this->_gameResults['gamedetails']['Genre']; $genreName = $this->_matchGenre($genres); } break; case "gb": $con['coverurl'] = (string) $this->_gameResults['image']['super_url']; $con['title'] = (string) $this->_gameResults['name']; $con['asin'] = $this->_gameID; $con['url'] = (string) $this->_gameResults['site_detail_url']; if (is_array($this->_gameResults['publishers'])) { while (list($key) = each($this->_gameResults['publishers'])) { if ($key == 0) { $con['publisher'] = (string) $this->_gameResults['publishers'][$key]['name']; } } } else { $con['publisher'] = "Unknown"; } if (is_array($this->_gameResults['original_game_rating'])) { $con['esrb'] = (string) $this->_gameResults['original_game_rating'][0]['name']; } else { $con['esrb'] = (string) $this->_gameResults['original_game_rating']['name']; } $con['releasedate'] = (string) $this->_gameResults['original_release_date']; if (isset($this->_gameResults['description'])) { $con['review'] = trim(strip_tags((string) $this->_gameResults['description'])); } if (isset($this->_gameResults['genres'][0]['name'])) { $genres = (string) $this->_gameResults['genres'][0]['name']; $genreName = $this->_matchGenre($genres); } break; case "gl": if (isset($this->_gameResults['cover'])) { $con['coverurl'] = (string) $this->_gameResults['cover']; } if (isset($this->_gameResults['backdrop'])) { $con['backdropurl'] = (string) $this->_gameResults['backdrop']; } $con['title'] = (string) $this->_gameResults['title']; $con['asin'] = $this->_gameResults['greenlightgameid']; $con['url'] = (string) $this->_gameResults['directurl']; $con['publisher'] = "Unknown"; $con['esrb'] = "Not Rated"; if (isset($this->_gameResults['description'])) { $con['review'] = trim(strip_tags((string) $this->_gameResults['description'])); } if (isset($this->_gameResults['trailer'])) { $con['trailer'] = (string) $this->_gameResults['trailer']; } if (isset($this->_gameResults['gamedetails']['Genre'])) { $genres = (string) $this->_gameResults['gamedetails']['Genre']; $genreName = $this->_matchGenre($genres); } break; case "steam": if (isset($this->_gameResults['cover'])) { $con['coverurl'] = (string) $this->_gameResults['cover']; } if (isset($this->_gameResults['backdrop'])) { $con['backdropurl'] = (string) $this->_gameResults['backdrop']; } $con['title'] = (string) $this->_gameResults['title']; $con['asin'] = $this->_gameResults['steamgameid']; $con['url'] = (string) $this->_gameResults['directurl']; if (isset($this->_gameResults['gamedetails']['Publisher'])) { $con['publisher'] = (string) $this->_gameResults['gamedetails']['Publisher']; } else { $con['publisher'] = "Unknown"; } if (isset($this->_gameResults['rating'])) { $con['esrb'] = (string) $this->_gameResults['rating']; } else { $con['esrb'] = "Not Rated"; } if (!empty($this->_gameResults['gamedetails']['Release Date'])) { $dateReleased = $this->_gameResults['gamedetails']['Release Date']; if (!preg_match('#^\\s*(?P<month>\\w+)\\s+(?P<day>\\d{1,2}),?\\s+(?P<year>\\d{4})\\s*$#', $dateReleased)) { if (preg_match('#^\\s*(?P<month>\\w+)\\s+(?P<year>\\d{4})\\s*$#', $dateReleased, $matches)) { $dateReleased = "{$matches['month']} 1, {$matches['year']}"; } } $date = \DateTime::createFromFormat('M/j/Y', $dateReleased); if ($date instanceof \DateTime) { $con['releasedate'] = (string) $date->format('Y-m-d'); } } if (isset($this->_gameResults['description'])) { $con['review'] = trim(strip_tags((string) $this->_gameResults['description'])); } if (isset($this->_gameResults['trailer'])) { $con['trailer'] = (string) $this->_gameResults['trailer']; } if (isset($this->_gameResults['gamedetails']['Genre'])) { $genres = (string) $this->_gameResults['gamedetails']['Genre']; $genreName = $this->_matchGenre($genres); } break; default: return false; } } else { return false; } // Load genres. $defaultGenres = $gen->getGenres(Genres::GAME_TYPE); $genreassoc = []; foreach ($defaultGenres as $dg) { $genreassoc[$dg['id']] = strtolower($dg['title']); } // Prepare database values. if (isset($con['coverurl'])) { $con['cover'] = 1; } else { $con['cover'] = 0; } if (isset($con['backdropurl'])) { $con['backdrop'] = 1; } else { $con['backdrop'] = 0; } if (!isset($con['trailer'])) { $con['trailer'] = 0; } if (empty($con['title'])) { $con['title'] = $gameInfo['title']; } if (!isset($con['releasedate'])) { $con['releasedate'] = ""; } if ($con['releasedate'] == "''") { $con['releasedate'] = ""; } if (!isset($con['review'])) { $con['review'] = 'No Review'; } $con['classused'] = $this->_classUsed; if (empty($genreName)) { $genreName = 'Unknown'; } if (in_array(strtolower($genreName), $genreassoc)) { $genreKey = array_search(strtolower($genreName), $genreassoc); } else { $genreKey = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\tINSERT INTO genres (title, type)\n\t\t\t\t\tVALUES (%s, %d)", $this->pdo->escapeString($genreName), Genres::GAME_TYPE)); } $con['gamesgenre'] = $genreName; $con['gamesgenreID'] = $genreKey; $check = $this->pdo->queryOneRow(sprintf(' SELECT id FROM gamesinfo WHERE asin = %s', $this->pdo->escapeString($con['asin']))); if ($check === false) { $gamesId = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\tINSERT INTO gamesinfo\n\t\t\t\t\t\t(title, asin, url, publisher, genre_id, esrb, releasedate, review, cover, backdrop, trailer, classused, createddate, updateddate)\n\t\t\t\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %d, %d, %s, %s, NOW(), NOW())", $this->pdo->escapeString($con['title']), $this->pdo->escapeString($con['asin']), $this->pdo->escapeString($con['url']), $this->pdo->escapeString($con['publisher']), $con['gamesgenreID'] == -1 ? "null" : $con['gamesgenreID'], $this->pdo->escapeString($con['esrb']), $con['releasedate'] != "" ? $this->pdo->escapeString($con['releasedate']) : "null", $this->pdo->escapeString(substr($con['review'], 0, 3000)), $con['cover'], $con['backdrop'], $this->pdo->escapeString($con['trailer']), $this->pdo->escapeString($con['classused']))); } else { $gamesId = $check['id']; $this->pdo->queryExec(sprintf(' UPDATE gamesinfo SET title = %s, asin = %s, url = %s, publisher = %s, genre_id = %s, esrb = %s, releasedate = %s, review = %s, cover = %d, backdrop = %d, trailer = %s, classused = %s, updateddate = NOW() WHERE id = %d', $this->pdo->escapeString($con['title']), $this->pdo->escapeString($con['asin']), $this->pdo->escapeString($con['url']), $this->pdo->escapeString($con['publisher']), $con['gamesgenreID'] == -1 ? "null" : $con['gamesgenreID'], $this->pdo->escapeString($con['esrb']), $con['releasedate'] != "" ? $this->pdo->escapeString($con['releasedate']) : "null", $this->pdo->escapeString(substr($con['review'], 0, 3000)), $con['cover'], $con['backdrop'], $this->pdo->escapeString($con['trailer']), $this->pdo->escapeString($con['classused']), $gamesId)); } if ($gamesId) { if ($this->echoOutput) { $this->pdo->log->doEcho($this->pdo->log->header("Added/updated game from " . $this->_classUsed . ": ") . $this->pdo->log->alternateOver(" Title: ") . $this->pdo->log->primary($con['title'])); } if ($con['cover'] === 1) { $con['cover'] = $ri->saveImage($gamesId, $con['coverurl'], $this->imgSavePath, 250, 250); } if ($con['backdrop'] === 1) { $con['backdrop'] = $ri->saveImage($gamesId . '-backdrop', $con['backdropurl'], $this->imgSavePath, 1920, 1024); } } else { if ($this->echoOutput) { $this->pdo->log->doEcho($this->pdo->log->headerOver("Nothing to update: ") . $this->pdo->log->primary($con['title'] . ' (PC)')); } } return $gamesId; }
public function data_add($content) { return $this->pdo->queryInsert(sprintf("INSERT INTO content (role, title, url, body, metadescription, metakeywords, contenttype, showinmenu, status, ordinal) values (%d, %s, %s, %s, %s, %s, %d, %d, %d, %d )", $content->role, $this->pdo->escapeString($content->title), $this->pdo->escapeString($content->url), $this->pdo->escapeString($content->body), $this->pdo->escapeString($content->metadescription), $this->pdo->escapeString($content->metakeywords), $content->contenttype, $content->showinmenu, $content->status, $content->ordinal)); }
/** * Update upcoming table. * * @param string $source * @param $type * @param string|false $info * * @return boolean|int */ protected function updateInsUpcoming($source, $type, $info) { return $this->pdo->queryExec(sprintf("\n\t\t\t\tINSERT INTO upcoming_releases (source, typeid, info, updateddate)\n\t\t\t\tVALUES (%s, %d, %s, NOW())\n\t\t\t\tON DUPLICATE KEY UPDATE info = %s", $this->pdo->escapeString($source), $type, $this->pdo->escapeString($info), $this->pdo->escapeString($info))); }
/** * @param $title * @param $year * @param object|null $amazdata * * @return bool */ public function updateMusicInfo($title, $year, $amazdata = null) { $gen = new Genres(['Settings' => $this->pdo]); $ri = new ReleaseImage($this->pdo); $titlepercent = 0; $mus = []; if ($title != '') { $amaz = $this->fetchAmazonProperties($title); } else { if ($amazdata != null) { $amaz = $amazdata; } else { $amaz = false; } } if (!$amaz) { return false; } if (isset($amaz->Items->Item->ItemAttributes->Title)) { $mus['title'] = (string) $amaz->Items->Item->ItemAttributes->Title; if (empty($mus['title'])) { return false; } } else { return false; } // Load genres. $defaultGenres = $gen->getGenres(Genres::MUSIC_TYPE); $genreassoc = []; foreach ($defaultGenres as $dg) { $genreassoc[$dg['id']] = strtolower($dg['title']); } // Get album properties. $mus['coverurl'] = (string) $amaz->Items->Item->LargeImage->URL; if ($mus['coverurl'] != "") { $mus['cover'] = 1; } else { $mus['cover'] = 0; } $mus['asin'] = (string) $amaz->Items->Item->ASIN; $mus['url'] = (string) $amaz->Items->Item->DetailPageURL; $mus['url'] = str_replace("%26tag%3Dws", "%26tag%3Dopensourceins%2D21", $mus['url']); $mus['salesrank'] = (string) $amaz->Items->Item->SalesRank; if ($mus['salesrank'] == "") { $mus['salesrank'] = 'null'; } $mus['artist'] = (string) $amaz->Items->Item->ItemAttributes->Artist; if (empty($mus['artist'])) { $mus['artist'] = (string) $amaz->Items->Item->ItemAttributes->Creator; if (empty($mus['artist'])) { $mus['artist'] = ""; } } $mus['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher; $mus['releasedate'] = $this->pdo->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate); if ($mus['releasedate'] == "''") { $mus['releasedate'] = 'null'; } $mus['review'] = ""; if (isset($amaz->Items->Item->EditorialReviews)) { $mus['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content)); } $mus['year'] = $year; if ($mus['year'] == "") { $mus['year'] = $mus['releasedate'] != 'null' ? substr($mus['releasedate'], 1, 4) : date("Y"); } $mus['tracks'] = ""; if (isset($amaz->Items->Item->Tracks)) { $tmpTracks = (array) $amaz->Items->Item->Tracks->Disc; $tracks = $tmpTracks['Track']; $mus['tracks'] = is_array($tracks) && !empty($tracks) ? implode('|', $tracks) : ''; } similar_text($mus['artist'] . " " . $mus['title'], $title, $titlepercent); if ($titlepercent < 60) { return false; } $genreKey = -1; $genreName = ''; if (isset($amaz->Items->Item->BrowseNodes)) { // Had issues getting this out of the browsenodes obj. // Workaround is to get the xml and load that into its own obj. $amazGenresXml = $amaz->Items->Item->BrowseNodes->asXml(); $amazGenresObj = simplexml_load_string($amazGenresXml); $amazGenres = $amazGenresObj->xpath("//BrowseNodeId"); foreach ($amazGenres as $amazGenre) { $currNode = trim($amazGenre[0]); if (empty($genreName)) { $genreMatch = $this->matchBrowseNode($currNode); if ($genreMatch !== false) { $genreName = $genreMatch; break; } } } if (in_array(strtolower($genreName), $genreassoc)) { $genreKey = array_search(strtolower($genreName), $genreassoc); } else { $genreKey = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\t\t\t\t\t\tINSERT INTO genres (title, type)\n\t\t\t\t\t\t\t\t\t\tVALUES (%s, %d)", $this->pdo->escapeString($genreName), Genres::MUSIC_TYPE)); } } $mus['musicgenre'] = $genreName; $mus['musicgenreid'] = $genreKey; $check = $this->pdo->queryOneRow(sprintf(' SELECT id FROM musicinfo WHERE asin = %s', $this->pdo->escapeString($mus['asin']))); if ($check === false) { $musicId = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\tINSERT INTO musicinfo\n\t\t\t\t\t\t(title, asin, url, salesrank, artist, publisher,\n\t\t\t\t\t\treleasedate, review, year, genre_id, tracks, cover, createddate, updateddate)\n\t\t\t\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, now(), now())", $this->pdo->escapeString($mus['title']), $this->pdo->escapeString($mus['asin']), $this->pdo->escapeString($mus['url']), $mus['salesrank'], $this->pdo->escapeString($mus['artist']), $this->pdo->escapeString($mus['publisher']), $mus['releasedate'], $this->pdo->escapeString($mus['review']), $this->pdo->escapeString($mus['year']), $mus['musicgenreid'] == -1 ? "null" : $mus['musicgenreid'], $this->pdo->escapeString($mus['tracks']), $mus['cover'])); } else { $musicId = $check['id']; $this->pdo->queryExec(sprintf(' UPDATE musicinfo SET title = %s, asin = %s, url = %s, salesrank = %s, artist = %s, publisher = %s, releasedate = %s, review = %s, year = %s, genre_id = %s, tracks = %s, cover = %s, updateddate = NOW() WHERE id = %d', $this->pdo->escapeString($mus['title']), $this->pdo->escapeString($mus['asin']), $this->pdo->escapeString($mus['url']), $mus['salesrank'], $this->pdo->escapeString($mus['artist']), $this->pdo->escapeString($mus['publisher']), $mus['releasedate'], $this->pdo->escapeString($mus['review']), $this->pdo->escapeString($mus['year']), $mus['musicgenreid'] == -1 ? "null" : $mus['musicgenreid'], $this->pdo->escapeString($mus['tracks']), $mus['cover'], $musicId)); } if ($musicId) { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header("\nAdded/updated album: ") . $this->pdo->log->alternateOver(" Artist: ") . $this->pdo->log->primary($mus['artist']) . $this->pdo->log->alternateOver(" Title: ") . $this->pdo->log->primary($mus['title']) . $this->pdo->log->alternateOver(" Year: ") . $this->pdo->log->primary($mus['year'])); } $mus['cover'] = $ri->saveImage($musicId, $mus['coverurl'], $this->imgSavePath, 250, 250); } else { if ($this->echooutput) { if ($mus["artist"] == "") { $artist = ""; } else { $artist = "Artist: " . $mus['artist'] . ", Album: "; } $this->pdo->log->doEcho($this->pdo->log->headerOver("Nothing to update: ") . $this->pdo->log->primary($artist . $mus['title'] . " (" . $mus['year'] . ")")); } } return $musicId; }
/** * Update a TV show category ID for a user's "my show" TV show. * @param int $uID ID of the user. * @param int $rageID ID of the TV show. * @param array $catID List of category ID's. */ public function updateShow($uID, $rageID, $catID = array()) { $this->pdo->queryExec(sprintf("UPDATE userseries SET categoryid = %s WHERE user_id = %d AND rageid = %d", !empty($catID) ? $this->pdo->escapeString(implode('|', $catID)) : "NULL", $uID, $rageID)); }
$todo = $file->isDir() ? 'rmdir' : 'unlink'; @$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));
/** * Attempt to find NFO files inside the NZB's of releases. * * @param object $nntp Instance of class NNTP. * @param string $groupID (optional) Group ID. * @param string $guidChar (optional) First character of the release GUID (used for multi-processing). * @param int $processImdb (optional) Attempt to find IMDB id's in the NZB? * @param int $processTvrage (optional) Attempt to find TvRage id's in the NZB? * * @return int How many NFO's were processed? * * @access public */ public function processNfoFiles($nntp, $groupID = '', $guidChar = '', $processImdb = 1, $processTvrage = 1) { $ret = 0; $guidCharQuery = $guidChar === '' ? '' : 'AND r.guid ' . $this->pdo->likeString($guidChar, false, true); $groupIDQuery = $groupID === '' ? '' : 'AND r.group_id = ' . $groupID; $optionsQuery = self::NfoQueryString($this->pdo); $res = $this->pdo->query(sprintf(' SELECT r.id, r.guid, r.group_id, r.name FROM releases r WHERE 1=1 %s %s %s ORDER BY r.nfostatus ASC, r.postdate DESC LIMIT %d', $optionsQuery, $guidCharQuery, $groupIDQuery, $this->nzbs)); $nfoCount = count($res); if ($nfoCount > 0) { $this->pdo->log->doEcho($this->pdo->log->primary(PHP_EOL . ($guidChar === '' ? '' : '[' . $guidChar . '] ') . ($groupID === '' ? '' : '[' . $groupID . '] ') . 'Processing ' . $nfoCount . ' NFO(s), starting at ' . $this->nzbs . ' * = hidden NFO, + = NFO, - = no NFO, f = download failed.')); if ($this->echo) { // Get count of releases per nfo status $nfoStats = $this->pdo->queryDirect(sprintf(' SELECT r.nfostatus AS status, COUNT(*) AS count FROM releases r WHERE 1=1 %s %s %s GROUP BY r.nfostatus ORDER BY r.nfostatus ASC', $optionsQuery, $guidCharQuery, $groupIDQuery)); if ($nfoStats instanceof \Traversable) { $outString = PHP_EOL . 'Available to process'; foreach ($nfoStats as $row) { $outString .= ', ' . $row['status'] . ' = ' . number_format($row['count']); } $this->pdo->log->doEcho($this->pdo->log->header($outString . '.')); } } $groups = new Groups(['Settings' => $this->pdo]); $nzbContents = new NZBContents(['Echo' => $this->echo, 'NNTP' => $nntp, 'Nfo' => $this, 'Settings' => $this->pdo, 'PostProcess' => new PostProcess(['Echo' => $this->echo, 'Nfo' => $this, 'Settings' => $this->pdo])]); $movie = new Movie(['Echo' => $this->echo, 'Settings' => $this->pdo]); foreach ($res as $arr) { $fetchedBinary = $nzbContents->getNFOfromNZB($arr['guid'], $arr['id'], $arr['group_id'], $groups->getByNameByID($arr['group_id'])); if ($fetchedBinary !== false) { // Insert nfo into database. $cp = 'COMPRESS(%s)'; $nc = $this->pdo->escapeString($fetchedBinary); $ckreleaseid = $this->pdo->queryOneRow(sprintf('SELECT releaseid FROM release_nfos WHERE releaseid = %d', $arr['id'])); if (!isset($ckreleaseid['releaseid'])) { $this->pdo->queryInsert(sprintf('INSERT INTO release_nfos (nfo, releaseid) VALUES (' . $cp . ', %d)', $nc, $arr['id'])); } $this->pdo->queryExec(sprintf('UPDATE releases SET nfostatus = %d WHERE id = %d', self::NFO_FOUND, $arr['id'])); $ret++; $movie->doMovieUpdate($fetchedBinary, 'nfo', $arr['id'], $processImdb); // If set scan for tvrage info. Disabled for now while TvRage is down. TODO: Add Other Scraper Checks if ($processTvrage == 1) { /*$tvRage = new TvRage(['Echo' => $this->echo, 'Settings' => $this->pdo]); $showId = $this->parseShowId($fetchedBinary); if ($showId !== false) { $show = $tvRage->parseNameEpSeason($arr['name']); if (is_array($show) && $show['name'] != '') { // Update release with season, ep, and air date info (if available) from release title. $tvRage->updateEpInfo($show, $arr['id']); $rid = $tvRage->getByRageID($rageId); if (!$rid) { $tvrShow = $tvRage->getRageInfoFromService($rageId); $tvRage->updateRageInfo($rageId, $show, $tvrShow, $arr['id']); } } }*/ } } } } // Remove nfo that we cant fetch after 5 attempts. $releases = $this->pdo->queryDirect(sprintf('SELECT r.id FROM releases r WHERE r.nzbstatus = %d AND r.nfostatus < %d AND r.nfostatus > %d %s %s', NZB::NZB_ADDED, $this->maxRetries, self::NFO_FAILED, $groupIDQuery, $guidCharQuery)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { // remove any release_nfos for failed $this->pdo->queryExec(sprintf(' DELETE FROM release_nfos WHERE nfo IS NULL AND releaseid = %d', $release['id'])); // set release.nfostatus to failed $this->pdo->queryExec(sprintf(' UPDATE releases r SET r.nfostatus = %d WHERE r.id = %d', self::NFO_FAILED, $release['id'])); } } if ($this->echo) { if ($nfoCount > 0) { echo PHP_EOL; } if ($ret > 0) { $this->pdo->log->doEcho($ret . ' NFO file(s) found/processed.', true); } } return $ret; }