/** * Deletes stored AniDB entries in the database * * @param int $anidbID */ public function deleteTitle($anidbID) { $this->pdo->queryExec(sprintf(' DELETE at, ai, ae FROM anidb_titles AS at LEFT OUTER JOIN anidb_info ai USING (anidbid) LEFT OUTER JOIN anidb_episodes ae USING (anidbid) WHERE anidbid = %d', $anidbID)); }
public function processGamesReleases() { $res = $this->pdo->queryDirect(sprintf(' SELECT searchname, id FROM releases WHERE nzbstatus = 1 %s AND gamesinfo_id = 0 AND categoryid = 4050 ORDER BY postdate DESC LIMIT %d', $this->renamed, $this->gameQty)); if ($res instanceof \Traversable && $res->rowCount() > 0) { if ($this->echoOutput) { $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $res->rowCount() . ' games release(s).')); } foreach ($res as $arr) { // Reset maxhitrequest $this->maxHitRequest = false; $startTime = microtime(true); $usedgb = false; $gameInfo = $this->parseTitle($arr['searchname']); if ($gameInfo !== false) { if ($this->echoOutput) { $this->pdo->log->doEcho($this->pdo->log->headerOver('Looking up: ') . $this->pdo->log->primary($gameInfo['title'] . ' (PC)')); } // Check for existing games entry. $gameCheck = $this->getGamesInfoByName($gameInfo['title']); if ($gameCheck === false) { $gameId = $this->updateGamesInfo($gameInfo); $usedgb = true; if ($gameId === false) { $gameId = -2; // Leave gamesinfo_id 0 to parse again if ($this->maxHitRequest === true) { $gameId = 0; } } } else { $gameId = $gameCheck['id']; } // Update release. $this->pdo->queryExec(sprintf('UPDATE releases SET gamesinfo_id = %d WHERE id = %d', $gameId, $arr['id'])); } else { // Could not parse release title. $this->pdo->queryExec(sprintf('UPDATE releases SET gamesinfo_id = %d WHERE id = %d', -2, $arr['id'])); if ($this->echoOutput) { echo '.'; } } // Sleep to not flood giantbomb. $diff = floor((microtime(true) - $startTime) * 1000000); if ($this->sleepTime * 1000 - $diff > 0 && $usedgb === true) { usleep($this->sleepTime * 1000 - $diff); } } } else { if ($this->echoOutput) { $this->pdo->log->doEcho($this->pdo->log->header('No games releases to process.')); } } }
function releases_rt() { $pdo = new Settings(); $rows = $pdo->queryExec('SELECT id, guid, name, searchname, fromname FROM releases'); if ($rows !== false && $rows->rowCount()) { $sphinx = new \SphinxSearch(); $total = $rows->rowCount(); $string = 'REPLACE INTO releases_rt (id, guid, name, searchname, fromname) VALUES '; $tempString = ''; $i = 0; echo '[Starting to populate sphinx RT indexes with ' . $total . ' releases.] '; foreach ($rows as $row) { $i++; $tempString .= sprintf('(%d, %s, %s, %s, %s),', $row['id'], $sphinx->sphinxQL->escapeString($row['guid']), $sphinx->sphinxQL->escapeString($row['name']), $sphinx->sphinxQL->escapeString($row['searchname']), $sphinx->sphinxQL->escapeString($row['fromname'])); if ($i === 1000 || $i >= $total) { $sphinx->sphinxQL->queryExec($string . rtrim($tempString, ',')); $tempString = ''; $total -= $i; $i = 0; echo '.'; } } echo ' [Done.]' . PHP_EOL; } else { echo 'No releases in your DB or an error occurred. This will need to be resolved before you can use the search.' . PHP_EOL; } }
public function updateMovie($uid, $imdbid, $catid = array()) { $db = new Settings(); $catid = !empty($catid) ? $db->escapeString(implode('|', $catid)) : "null"; $sql = sprintf("update usermovies set categoryid = %s where userid = %d and imdbid = %d", $catid, $uid, $imdbid); $db->queryExec($sql); }
function categorizeRelease($update = true, $where, $echooutput = false) { $pdo = new Settings(); $cat = new Categorize(); $consoletools = new consoleTools(); $relcount = $chgcount = 0; $c = new ColorCLI(); echo $c->primary("SELECT id, searchname, groupid, categoryid FROM releases " . $where); $resrel = $pdo->queryDirect("SELECT id, searchname, groupid, categoryid FROM releases " . $where); $total = $resrel->rowCount(); if ($total > 0) { foreach ($resrel as $rowrel) { $catId = $cat->determineCategory($rowrel['groupid'], $rowrel['searchname']); if ($rowrel['categoryid'] != $catId) { if ($update === true) { $pdo->queryExec(sprintf("\n\t\t\t\t\t\t\tUPDATE releases\n\t\t\t\t\t\t\tSET iscategorized = 1,\n\t\t\t\t\t\t\t\trageid = -1,\n\t\t\t\t\t\t\t\tseriesfull = NULL,\n\t\t\t\t\t\t\t\tseason = NULL,\n\t\t\t\t\t\t\t\tepisode = NULL,\n\t\t\t\t\t\t\t\ttvtitle = NULL,\n\t\t\t\t\t\t\t\ttvairdate = NULL,\n\t\t\t\t\t\t\t\timdbid = NULL,\n\t\t\t\t\t\t\t\tmusicinfoid = NULL,\n\t\t\t\t\t\t\t\tconsoleinfoid = NULL,\n\t\t\t\t\t\t\t\tgamesinfo_id = 0,\n\t\t\t\t\t\t\t\txxxinfo_id = 0,\n\t\t\t\t\t\t\t\tbookinfoid = NULL,\n\t\t\t\t\t\t\t\tanidbid = NULL,\n\t\t\t\t\t\t\t\tcategoryid = %d\n\t\t\t\t\t\t\tWHERE id = %d", $catId, $rowrel['id'])); } $chgcount++; } $relcount++; if ($echooutput) { $consoletools->overWritePrimary("Re-Categorized: [" . number_format($chgcount) . "] " . $consoletools->percentString($relcount, $total)); } } } if ($echooutput !== false && $relcount > 0) { echo "\n"; } return $chgcount; }
/** * Fetch a comment and insert it. * * @param string $messageID Message-ID for the article. * @param string $siteID id of the site. * * @return bool */ 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; } $cid = md5($body['SID'] . $body['USER'] . $body['TIME'] . $siteID); // Insert the comment. if ($this->pdo->queryExec(sprintf(' INSERT IGNORE INTO releasecomment (text, createddate, issynced, shareid, cid, gid, nzb_guid, siteid, username, userid, releaseid, shared, host, sourceID) VALUES (%s, %s, 1, %s, %s, %s, %s, %s, %s, 0, 0, 2, "", 999)', $this->pdo->escapeString($body['BODY']), $this->pdo->from_unixtime($body['TIME'] > time() ? time() : $body['TIME']), $this->pdo->escapeString($body['SID']), $this->pdo->escapeString($cid), $this->pdo->escapeString($body['RID']), $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; }
/** * Updates PRE data in the DB. * * @access protected */ protected function _updatePre() { if (empty($this->_curPre['title'])) { return; } $query = 'UPDATE prehash SET '; $query .= !empty($this->_curPre['size']) ? 'size = ' . $this->_pdo->escapeString($this->_curPre['size']) . ', ' : ''; $query .= !empty($this->_curPre['source']) ? 'source = ' . $this->_pdo->escapeString($this->_curPre['source']) . ', ' : ''; $query .= !empty($this->_curPre['files']) ? 'files = ' . $this->_pdo->escapeString($this->_curPre['files']) . ', ' : ''; $query .= !empty($this->_curPre['reason']) ? 'nukereason = ' . $this->_pdo->escapeString($this->_curPre['reason']) . ', ' : ''; $query .= !empty($this->_curPre['reqid']) ? 'requestid = ' . $this->_curPre['reqid'] . ', ' : ''; $query .= !empty($this->_curPre['group_id']) ? 'groupid = ' . $this->_curPre['group_id'] . ', ' : ''; $query .= !empty($this->_curPre['predate']) ? 'predate = ' . $this->_curPre['predate'] . ', ' : ''; $query .= !empty($this->_curPre['nuked']) ? 'nuked = ' . $this->_curPre['nuked'] . ', ' : ''; $query .= !empty($this->_curPre['filename']) ? 'filename = ' . $this->_pdo->escapeString($this->_curPre['filename']) . ', ' : ''; $query .= empty($this->_oldPre['category']) && !empty($this->_curPre['category']) ? 'category = ' . $this->_pdo->escapeString($this->_curPre['category']) . ', ' : ''; if ($query === 'UPDATE prehash SET ') { return; } $query .= 'title = ' . $this->_pdo->escapeString($this->_curPre['title']); $query .= ' WHERE title = ' . $this->_pdo->escapeString($this->_curPre['title']); $this->_pdo->ping(true); $this->_pdo->queryExec($query); $this->_doEcho(false); }
public function startRunning() { if (!$this->isRunning()) { return $this->pdo->queryExec("UPDATE tmux SET value = '1' WHERE setting = 'running'"); } return true; }
/** * Process all untagged movies to link them to a movieinfo row. */ public function processMovieReleases() { $ret = 0; $nfo = new Nfo(); $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where imdbid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 100", Category::CAT_PARENT_MOVIE)); if ($this->pdo->getNumRows($res) > 0) { if ($this->echooutput) { echo "MovProc : Processing " . $this->pdo->getNumRows($res) . " movie releases\n"; } while ($arr = $this->pdo->getAssocArray($res)) { $imdbID = false; /* Preliminary IMDB id Detection from NFO file */ $rawnfo = ''; if ($nfo->getNfo($arr['id'], $rawnfo)) { $imdbID = $this->parseImdbFromNfo($rawnfo); } if ($imdbID !== false) { // Set IMDB (if found in nfo) and move along $this->pdo->queryExec(sprintf("update releases set imdbid = %s where id = %d", $this->pdo->escapeString($imdbID), $arr["id"])); //check for existing movie entry $movCheck = $this->getMovieInfo($imdbID); if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) { $movieId = $this->updateMovieInfo($imdbID); } continue; } $moviename = $this->parseMovieName($arr['searchname']); if ($moviename !== false) { if ($this->echooutput) { echo 'MovProc : ' . $moviename . ' [' . $arr['searchname'] . ']' . "\n"; } //$buffer = getUrl("https://www.google.com/search?source=ig&hl=en&rlz=&btnG=Google+Search&aq=f&oq=&q=".urlencode($moviename.' site:imdb.com')); $buffer = Utility::getUrl(['url' => 'http://www.bing.com/search?&q=' . urlencode($moviename . ' site:imdb.com')]); // make sure we got some data if ($buffer !== false && strlen($buffer)) { $imdbId = $this->parseImdbFromNfo($buffer); if ($imdbId !== false) { //update release with imdb id $this->pdo->queryExec(sprintf("update releases SET imdbid = %s WHERE id = %d", $this->pdo->escapeString($imdbId), $arr["id"])); //check for existing movie entry $movCheck = $this->getMovieInfo($imdbId); if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) { $movieId = $this->updateMovieInfo($imdbId); } } else { //no imdb id found, set to all zeros so we dont process again $this->pdo->queryExec(sprintf("update releases SET imdbid = %d WHERE id = %d", 0, $arr["id"])); } } else { //url fetch failed, will try next run } } else { //no valid movie name found, set to all zeros so we dont process again $this->pdo->queryExec(sprintf("update releases SET imdbid = %d WHERE id = %d", 0, $arr["id"])); } } } }
/** * */ public function processMusicReleases($local = false) { $res = $this->pdo->queryDirect(sprintf('SELECT searchname, id FROM releases ' . 'WHERE musicinfoid IS NULL AND nzbstatus = 1 %s AND categoryid IN (3010, 3040, 3050) ' . 'ORDER BY postdate DESC LIMIT %d', $this->renamed, $this->musicqty)); if ($res instanceof \Traversable && $res->rowCount() > 0) { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $res->rowCount() . ' music release(s).')); } foreach ($res as $arr) { $startTime = microtime(true); $usedAmazon = false; $album = $this->parseArtist($arr['searchname']); if ($album !== false) { $newname = $album["name"] . ' (' . $album["year"] . ')'; if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->headerOver('Looking up: ') . $this->pdo->log->primary($newname)); } // Do a local lookup first $musicCheck = $this->getMusicInfoByName('', $album["name"]); if ($musicCheck === false && in_array($album['name'] . $album['year'], $this->failCache)) { // Lookup recently failed, no point trying again if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->headerOver('Cached previous failure. Skipping.') . PHP_EOL); } $albumId = -2; } else { if ($musicCheck === false && $local === false) { $albumId = $this->updateMusicInfo($album['name'], $album['year']); $usedAmazon = true; if ($albumId === false) { $albumId = -2; $this->failCache[] = $album['name'] . $album['year']; } } else { $albumId = $musicCheck['id']; } } // Update release. $this->pdo->queryExec(sprintf("UPDATE releases SET musicinfoid = %d WHERE id = %d", $albumId, $arr["id"])); } else { $this->pdo->queryExec(sprintf("UPDATE releases SET musicinfoid = %d WHERE id = %d", -2, $arr["id"])); echo '.'; } // Sleep to not flood amazon. $diff = floor((microtime(true) - $startTime) * 1000000); if ($this->sleeptime * 1000 - $diff > 0 && $usedAmazon === true) { usleep($this->sleeptime * 1000 - $diff); } } if ($this->echooutput) { echo "\n"; } } else { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header('No music releases to process.')); } } }
/** * update a release name * * @param Settings $pdo * @param $id * @param $oldname * @param $newname */ private function updateName(Settings $pdo, $id, $oldname, $newname) { if ($this->verbose) { echo sprintf("OLD : %s\nNEW : %s\n\n", $oldname, $newname); } if (!$this->echoonly) { $this->pdo->queryExec(sprintf("update releases set name=%s, searchname = %s WHERE id = %d", $this->pdo->escapeString($newname), $this->pdo->escapeString($newname), $id)); } }
/** 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 string|int $status * @param int $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)); } }
private function setRageNotFound($Id) { if ($Id) { $this->pdo->queryExec(sprintf(' UPDATE releases SET rageid = -2 WHERE %s AND id = %d', $this->catWhere, $Id)); } }
/** * Updates existing anime info in anidb info/episodes tables * * @param array $AniDBInfoArray * * @return string */ private function updateAniDBInfoEps($AniDBInfoArray = array()) { $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']; }
/** * Attempts to match PreDB titles to releases. * * @param $dateLimit */ public function checkPre($dateLimit = false) { $this->dateLimit = $dateLimit; $consoleTools = new ConsoleTools(['ColorCLI' => $this->pdo->log]); $updated = 0; $datesql = ''; if ($this->echooutput) { echo $this->pdo->log->header('Querying DB for release search names not matched with PreDB titles.'); } if ($this->dateLimit !== false && is_numeric($this->dateLimit)) { $datesql = sprintf('AND DATEDIFF(NOW(), adddate) <= %d', $this->dateLimit); } $res = $this->pdo->queryDirect(sprintf(' SELECT p.id AS prehashid, r.id AS releaseid FROM prehash p INNER JOIN releases r ON p.title = r.searchname WHERE r.prehashid < 1 %s', $datesql)); if ($res !== false) { $total = $res->rowCount(); echo $this->pdo->log->primary(number_format($total) . ' releases to match.'); if ($res instanceof Traversable) { foreach ($res as $row) { $this->pdo->queryExec(sprintf('UPDATE releases SET prehashid = %d WHERE id = %d', $row['prehashid'], $row['releaseid'])); if ($this->echooutput) { $consoleTools->overWritePrimary('Matching up preDB titles with release searchnames: ' . $consoleTools->percentString(++$updated, $total)); } } if ($this->echooutput) { echo PHP_EOL; } } if ($this->echooutput) { echo $this->pdo->log->header('Matched ' . number_format($updated > 0 ? $updated : 0) . ' PreDB titles to release search names.'); } } }
/** * Attempts to get the releasename from a par2 file * * @param string $guid * @param int $relID * @param int $groupID * @param int $nameStatus * @param int $show * * @return bool * * @access public */ public function checkPAR2($guid, $relID, $groupID, $nameStatus, $show) { $nzbFile = $this->LoadNZB($guid); if ($nzbFile !== false) { foreach ($nzbFile->file as $nzbContents) { if (preg_match('/\\.(par[2" ]|\\d{2,3}").+\\(1\\/1\\)$/i', (string) $nzbContents->attributes()->subject)) { if ($this->pp->parsePAR2((string) $nzbContents->segments->segment, $relID, $groupID, $this->nntp, $show) === true && $nameStatus === 1) { $this->pdo->queryExec(sprintf('UPDATE releases SET proc_par2 = 1 WHERE id = %d', $relID)); return true; } } } } if ($nameStatus === 1) { $this->pdo->queryExec(sprintf('UPDATE releases SET proc_par2 = 1 WHERE id = %d', $relID)); } return false; }
/** * Process all releases tagged as musicinfoid -2 to attempt to retrieve properties from mediainfo xml. */ public function processMusicReleaseFromMediaInfo() { $res = $this->pdo->query("SELECT r.searchname, ref.releaseid, ref.mediainfo FROM releaseextrafull ref INNER JOIN releases r ON r.id = ref.releaseid WHERE r.musicinfoid = -2"); $rescount = sizeof($res); if ($rescount > 0) { if ($this->echooutput) { echo "MusicPr : Processing " . $rescount . " audio releases via mediainfo\n"; } //load genres $gen = new Genres(); $defaultGenres = $gen->getGenres(Genres::MUSIC_TYPE); $genreassoc = array(); foreach ($defaultGenres as $dg) { $genreassoc[$dg['id']] = strtolower($dg['title']); } foreach ($res as $rel) { $albumId = -3; $mi = null; $mi = @simplexml_load_string($rel["mediainfo"]); if ($mi != null) { $artist = (string) $mi->File->track[0]->Performer; $album = (string) $mi->File->track[0]->Album; $year = (string) $mi->File->track[0]->Recorded_date; $genre = (string) $mi->File->track[0]->Genre; $publisher = (string) $mi->File->track[0]->Publisher; $albumCheck = $this->getMusicInfoByName($artist, $album); if ($albumCheck === false) { // // insert new musicinfo // $genreKey = -1; if ($genre != "") { $albumId = $this->addUpdateMusicInfo($album, "", "", "null", $artist, $publisher, "null", "", $year, $genreKey, "", 0); } } else { $albumId = $albumCheck["id"]; } } $sql = sprintf("update releases set musicinfoid = %d where id = %d", $albumId, $rel["releaseid"]); $this->pdo->queryExec($sql); } } return true; }
/** * Write an NZB to the hard drive for a single release. * * @param int $relID The id of the release in the DB. * @param string $relGuid The guid of the release. * @param string $name The name of the release. * @param string $cTitle The name of the category this release is in. * * @return bool Have we successfully written the NZB to the hard drive? * * @access public */ public function writeNZBforReleaseId($relID, $relGuid, $name, $cTitle) { $path = $this->buildNZBPath($relGuid, $this->nzbSplitLevel, true) . $relGuid . '.nzb.gz'; $fp = gzopen($path, 'wb7'); if ($fp) { $nzb_guid = ''; gzwrite($fp, sprintf($this->_nzbHeadString, htmlspecialchars($cTitle, ENT_QUOTES, 'utf-8'), htmlspecialchars($name, ENT_QUOTES, 'utf-8'))); $binaries = $this->pdo->queryDirect($this->_binariesQuery . $relID . ' ORDER BY name'); if ($binaries instanceof \Traversable) { foreach ($binaries as $binary) { $poster = htmlspecialchars($binary['fromname'], ENT_QUOTES, 'utf-8'); if ($binary instanceof \Traversable) { foreach ($binary as $bin) { // Buffer segment writes, increases performance. $string = ''; $parts = $this->pdo->queryDirect(sprintf($this->_partsQuery, $bin['id'])); if ($parts instanceof \Traversable) { foreach ($parts as $part) { if ($nzb_guid === '') { $nzb_guid = $part['messageid']; } $string .= ' <segment bytes="' . $part['size'] . '" number="' . $part['partnumber'] . '">' . htmlspecialchars($part['messageid'], ENT_QUOTES, 'utf-8') . "</segment>\n"; } } gzwrite($fp, '<file poster="' . $poster . '" date="' . $bin['udate'] . '" subject="' . htmlspecialchars($bin['name'], ENT_QUOTES, 'utf-8') . ' (1/' . $bin['totalparts'] . ")\">\n <groups>\n <group>" . $bin['groupname'] . "</group>\n </groups>\n <segments>\n" . $string . " </segments>\n</file>\n"); } } } } gzwrite($fp, '</nzb>'); gzclose($fp); if (is_file($path)) { $this->pdo->queryExec(sprintf(' UPDATE releases SET nzbstatus = %d %s WHERE id = %d', NZB::NZB_ADDED, $nzb_guid === '' ? '' : ', nzb_guid = UNHEX( ' . $this->pdo->escapestring(md5($nzb_guid)) . ' )', $relID)); // Chmod to fix issues some users have with file permissions. chmod($path, 0777); return true; } else { echo "ERROR: {$path} does not exist.\n"; } } return false; }
/** * 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); }
/** * Process all untagged releases to see if they are found in predb. */ public function processReleases($daysback = 3) { if ($this->echooutput) { echo "Predb : Updating releases with pre data\n"; } $matched = 0; $releasesQuery = $this->pdo->queryDirect(sprintf('SELECT id, searchname FROM releases WHERE preid IS NULL AND adddate > DATE_SUB(NOW(), INTERVAL %d DAY)', $daysback)); while ($arr = $this->pdo->getAssocArray($releasesQuery)) { $arr['searchname'] = str_replace(' ', '_', $arr['searchname']); $sql = sprintf("SELECT id FROM predb WHERE dirname = %s LIMIT 1", $this->pdo->escapeString($arr['searchname'])); $predbQuery = $this->pdo->queryOneRow($sql); if ($predbQuery) { $this->pdo->queryExec(sprintf('UPDATE releases SET preid = %d WHERE id = %d', $predbQuery['id'], $arr['id'])); $matched++; } } if ($this->echooutput) { echo "Predb : Matched pre data to " . $matched . " releases\n"; } }
/** * Check if the tables exists for the group_id, make new tables for table per group. * * @param int $groupID * * @return bool */ public function createNewTPGTables($groupID) { foreach (['binaries', 'parts', 'partrepair'] as $tableName) { if ($this->pdo->queryExec(sprintf('SELECT * FROM %s_%s LIMIT 1', $tableName, $groupID), true) === false) { if ($this->pdo->queryExec(sprintf('CREATE TABLE %s_%s LIKE %s', $tableName, $groupID, $tableName), true) === false) { return false; } /*else { if ($tableName === 'binaries') { $this->pdo->queryExec( sprintf( 'CREATE TRIGGER delete_binaries_%s BEFORE DELETE ON binaries_%s FOR EACH ROW BEGIN' . ' DELETE FROM parts_%s WHERE binaryid = OLD.id; END', $groupID, $groupID, $groupID ) ); } }*/ } } return true; }
/** * Check all untagged console releases for their extended metadata. */ public function processConsoleReleases() { $ret = 0; $numlookedup = 0; $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where consoleinfoid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 100", Category::CAT_PARENT_GAME)); if ($this->pdo->getNumRows($res) > 0) { if ($this->echooutput) { echo "ConsPrc : Processing " . $this->pdo->getNumRows($res) . " console releases\n"; } while ($arr = $this->pdo->getAssocArray($res)) { if ($numlookedup > Console::NUMTOPROCESSPERTIME) { return; } $gameInfo = $this->parseTitle($arr['searchname']); if ($gameInfo !== false) { if ($this->echooutput) { echo 'ConsPrc : ' . $gameInfo["title"] . ' (' . $gameInfo["platform"] . ')' . "\n"; } //check for existing console entry $gameCheck = $this->getConsoleInfoByName($gameInfo["title"], $gameInfo["platform"]); if ($gameCheck === false) { $numlookedup++; $gameId = $this->updateConsoleInfo($gameInfo); if ($gameId === false) { $gameId = -2; } } else { $gameId = $gameCheck["id"]; } //update release $this->pdo->queryExec(sprintf("update releases SET consoleinfoid = %d WHERE id = %d", $gameId, $arr["id"])); } else { //could not parse release title $this->pdo->queryExec(sprintf("update releases SET consoleinfoid = %d WHERE id = %d", -2, $arr["id"])); } } } }
/** * Process all untagged book releases for additional metadata. */ public function processBookReleases() { $numlookedup = 0; $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where bookinfoid IS NULL and categoryid = %d ORDER BY postdate DESC LIMIT 100", Category::CAT_BOOK_EBOOK)); if ($this->pdo->getNumRows($res) > 0) { if ($this->echooutput) { echo "BookPrc : Processing " . $this->pdo->getNumRows($res) . " book releases\n"; } while ($arr = $this->pdo->getAssocArray($res)) { if ($numlookedup > Book::NUMTOPROCESSPERTIME) { return; } $bookId = -2; $book = $this->parseAuthor($arr['searchname']); if ($book !== false) { if ($this->echooutput) { echo 'BookPrc : ' . $book["author"] . ' - ' . $book["title"] . "\n"; } //check for existing book entry $bookCheck = $this->getBookInfoByName($book["author"], $book["title"]); if ($bookCheck === false) { // // get from amazon // $numlookedup++; $ret = $this->updateBookInfo($book["author"], $book["title"]); if ($ret !== false) { $bookId = $ret; } } else { $bookId = $bookCheck["id"]; } } $this->pdo->queryExec(sprintf("update releases SET bookinfoid = %d WHERE id = %d", $bookId, $arr["id"])); } } }
/** * Process XXX releases where xxxinfo is 0 * */ public function processXXXReleases() { $res = $this->pdo->query(sprintf("\n\t\t\t\tSELECT r.searchname, r.id\n\t\t\t\tFROM releases r\n\t\t\t\tWHERE r.nzbstatus = 1\n\t\t\t\tAND r.xxxinfo_id = 0\n\t\t\t\tAND r.categoryid IN (6010, 6020, 6030, 6040, 6041, 6042, 6080, 6090)\n\t\t\t\tLIMIT %d", $this->movieqty)); $movieCount = count($res); if ($movieCount > 0) { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $movieCount . " XXX releases.")); } // Loop over releases. foreach ($res as $arr) { $idcheck = -2; // Try to get a name. if ($this->parseXXXSearchName($arr['searchname']) !== false) { $check = $this->checkXXXInfoExists($this->currentTitle); if ($check === false) { $this->currentRelID = $arr['id']; $movieName = $this->currentTitle; if ($this->debug && $this->echooutput) { $this->pdo->log->doEcho("DB name: " . $arr['searchname'], true); } if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->primaryOver("Looking up: ") . $this->pdo->log->headerOver($movieName), true); } $idcheck = $this->updateXXXInfo($movieName); } else { $idcheck = (int) $check['id']; } } else { $this->pdo->log->doEcho(".", true); } $this->pdo->queryExec(sprintf('UPDATE releases SET xxxinfo_id = %d WHERE id = %d', $idcheck, $arr['id'])); } } elseif ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header('No xxx releases to process.')); } }
$baseUrl = 'https://www.dropbox.com/sh/' . $innerUrl; $folderUrl['url'] = $baseUrl . '/AACy9Egno_v2kcziVHuvWbbxa'; $result = Utility::getUrl($folderUrl); if (!$result) { exit('Error connecting to dropbox.com, try again later?' . PHP_EOL); } $result = preg_match_all('#<a [\\w"=-]+ href="https://www.dropbox.com/sh/' . $innerUrl . '/(\\S+/\\d+' . $fileName . '\\?dl=0)"#', $result, $all_matches); if ($result) { exec('clear'); $all_matches = array_unique($all_matches[1]); $total = count($all_matches); $pdo = new Settings(); if ($argv[1] != 'progress') { $progress['last'] = !is_numeric($argv[1]) ? time() : $argv[1]; } $pdo->queryExec('DROP TABLE IF EXISTS tmp_pre'); $pdo->queryExec('CREATE TABLE tmp_pre LIKE prehash'); // Drop id as it is not needed and incurs overhead creating each id. $pdo->queryExec('ALTER TABLE tmp_pre DROP COLUMN id'); // Add a column for the group's name which is included instead of the groupid, which may be // different between individual databases $pdo->queryExec('ALTER TABLE tmp_pre ADD COLUMN groupname VARCHAR (255)'); // Drop indexes on tmp_pre $pdo->queryExec('ALTER TABLE tmp_pre DROP INDEX `ix_prehash_nfo`, DROP INDEX `ix_prehash_predate`, DROP INDEX `ix_prehash_source`, DROP INDEX `ix_prehash_title`, DROP INDEX `ix_prehash_requestid`'); foreach ($all_matches as $matches) { if (preg_match('#^(.+)/(\\d+)_#', $matches, $match)) { $timematch = -1 + $progress['last']; // Skip patches the user does not want. if ($match[2] < $timematch) { echo 'Skipping dump ' . $match[2] . ', as your minimum unix time argument is ' . $timematch . PHP_EOL; --$total;
/** * 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 require_once dirname(__FILE__) . "/../../../bin/config.php"; use newznab\db\Settings; $pdo = new Settings(); if (isset($argv[1]) && ($argv[1] == "true" || $argv[1] == "drop")) { $pdo->queryExec("UPDATE groups SET first_record = 0, first_record_postdate = NULL, last_record = 0, last_record_postdate = NULL, last_updated = NULL"); echo $pdo->log->primary("Reseting all groups completed."); $arr = array("parts", "partrepair", "binaries"); foreach ($arr as &$value) { $rel = $pdo->queryExec("TRUNCATE TABLE {$value}"); if ($rel !== false) { echo $pdo->log->primary("Truncating {$value} completed."); } } unset($value); $tpg = $pdo->getSetting('tablepergroup'); $tablepergroup = !empty($tpg) ? $tpg : 0; if ($tablepergroup == 1) { $sql = 'SHOW table status'; $tables = $pdo->query($sql); foreach ($tables as $row) { $tbl = $row['name']; if (preg_match('/binaries_\\d+/', $tbl) || preg_match('/parts_\\d+/', $tbl) || preg_match('/partrepair_\\d+/', $tbl) || preg_match('/\\d+_binaries/', $tbl) || preg_match('/\\d+_parts/', $tbl) || preg_match('/\\d+_partrepair_\\d+/', $tbl)) { if ($argv[1] == "drop") { $rel = $pdo->queryDirect(sprintf('DROP TABLE %s', $tbl)); if ($rel !== false) { echo $pdo->log->primary("Dropping {$tbl} completed."); } } else { $rel = $pdo->queryDirect(sprintf('TRUNCATE TABLE %s', $tbl));
/** * Mark a release as missing so it isn't ever parsed again */ private function setNfoMissing($relid) { $db = new Settings(); $q = sprintf("UPDATE releases SET releasenfoid = %d " . "WHERE id = %d", Nfo::FLAG_NFO_MISSING, $relid); return $db->queryExec($q); }
/** * Add a new binary row and its associated parts. */ public function delete($id) { $db = new Settings(); $db->queryExec(sprintf("DELETE from parts where binaryid = %d", $id)); $db->queryExec(sprintf("DELETE from binaries where id = %d", $id)); }
/** * Delete all Binaries/Parts for a group id. * * @param int $groupID The id of the group. * * @note A trigger automatically deletes the parts. * * @return void */ public function purgeGroup($groupID) { $this->_pdo->queryExec(sprintf('DELETE b FROM binaries b WHERE b.groupid = %d', $groupID)); }