/** * 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)); }
/** * 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; } }
/** * 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; }
/** * 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; }
/** * Update movie on movie-edit page. * * @param array $values Array of keys/values to update. See $validKeys * @return int|bool */ public function update(array $values) { if (!count($values)) { return false; } $validKeys = $this->getColumnKeys(); $query = ['0' => 'INSERT INTO movieinfo (updateddate, createddate, ', '1' => ' VALUES (NOW(), NOW(), ', '2' => 'ON DUPLICATE KEY UPDATE updateddate = NOW(), ']; $found = 0; foreach ($values as $key => $value) { if (in_array($key, $validKeys) && !empty($value)) { $found++; $query[0] .= "{$key}, "; if (in_array($key, ['genre', 'language'])) { $value = substr($value, 0, 64); } $value = $this->pdo->escapeString($value); $query[1] .= "{$value}, "; $query[2] .= "{$key} = {$value}, "; } } if (!$found) { return false; } foreach ($query as $key => $value) { $query[$key] = rtrim($value, ', '); } return $this->pdo->queryInsert($query[0] . ') ' . $query[1] . ') ' . $query[2]); }
/** * 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; }
/** * Inserts new anime info from AniDB to anidb table * * @param array $episodeArr */ private function insertAniDBEpisodes(array $episodeArr = []) { if (!empty($episodeArr)) { foreach ($episodeArr as $episode) { $this->pdo->queryInsert(sprintf(' INSERT IGNORE INTO anidb_episodes (anidbid, episodeid, episode_no, episode_title, airdate) VALUES (%d, %d, %d, %s, %s)', $this->anidbId, $episode['episode_id'], $episode['episode_no'], $this->pdo->escapeString($episode['episode_title']), $this->pdo->escapeString($episode['airdate']))); } } }
/** * 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; }
/** * Inserts aliases for videos * * @param $videoId * @param array $aliases */ public function addAliases($videoId, array $aliases = []) { if (!empty($aliases) && $videoId > 0) { foreach ($aliases as $key => $title) { // Check for tvmaze style aka if (is_array($title) && !empty($title['name'])) { $title = $title['name']; } // Check if we have the AKA already $check = $this->getAliases(0, $title); if ($check === false) { $this->pdo->queryInsert(sprintf(' INSERT IGNORE INTO videos_aliases (videos_id, title) VALUES (%d, %s)', $videoId, $this->pdo->escapeString($title))); } } } }
/** * @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; }
/** * When a user wants to add a show to "my shows" insert it into the user series table. * * @param int $uID ID of user. * @param int $rageID Rage ID of tv show. * @param array $catID List of category ID's * * @return bool|int */ public function addShow($uID, $rageID, $catID = array()) { return $this->pdo->queryInsert(sprintf("INSERT INTO userseries (user_id, rageid, categoryid, createddate) VALUES (%d, %d, %s, NOW())", $uID, $rageID, !empty($catID) ? $this->pdo->escapeString(implode('|', $catID)) : "NULL")); }
/** * Fetch IMDB/TMDB info for the movie. * * @param string $imdbId * * @return bool */ public function updateMovieInfo($imdbId) { if ($this->echooutput && $this->service !== '') { $this->pdo->log->doEcho($this->pdo->log->primary("Fetching IMDB info from TMDB using IMDB ID: " . $imdbId)); } // Check TMDB for IMDB info. $tmdb = $this->fetchTMDBProperties($imdbId); // Check IMDB for movie info. $imdb = $this->fetchIMDBProperties($imdbId); if (!$imdb && !$tmdb) { return false; } // Check FanArt.tv for background images. $fanart = $this->fetchFanartTVProperties($imdbId); $mov = []; $mov['cover'] = $mov['backdrop'] = $movieID = 0; $mov['type'] = $mov['director'] = $mov['actors'] = $mov['language'] = ''; $mov['imdb_id'] = $imdbId; $mov['tmdb_id'] = !isset($tmdb['tmdb_id']) || $tmdb['tmdb_id'] == '' ? 'NULL' : $tmdb['tmdb_id']; // Prefer FanArt.tv cover over TMDB. And TMDB over IMDB. if ($this->checkVariable($fanart['cover'])) { $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $fanart['cover'], $this->imgSavePath); } else { if ($this->checkVariable($tmdb['cover'])) { $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $tmdb['cover'], $this->imgSavePath); } else { if ($this->checkVariable($imdb['cover'])) { $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $imdb['cover'], $this->imgSavePath); } } } // Backdrops. if ($this->checkVariable($fanart['backdrop'])) { $mov['backdrop'] = $this->releaseImage->saveImage($imdbId . '-backdrop', $fanart['backdrop'], $this->imgSavePath, 1920, 1024); } else { if ($this->checkVariable($tmdb['backdrop'])) { $mov['backdrop'] = $this->releaseImage->saveImage($imdbId . '-backdrop', $tmdb['backdrop'], $this->imgSavePath, 1920, 1024); } } $mov['title'] = $this->setTmdbImdbVar($imdb['title'], $tmdb['title']); $mov['rating'] = $this->setTmdbImdbVar($imdb['rating'], $tmdb['rating']); $mov['plot'] = $this->setTmdbImdbVar($imdb['plot'], $tmdb['plot']); $mov['tagline'] = $this->setTmdbImdbVar($imdb['tagline'], $tmdb['tagline']); $mov['year'] = $this->setTmdbImdbVar($imdb['year'], $tmdb['year']); $mov['genre'] = $this->setTmdbImdbVar($imdb['genre'], $tmdb['genre']); if ($this->checkVariable($imdb['type'])) { $mov['type'] = $imdb['type']; } if ($this->checkVariable($imdb['director'])) { $mov['director'] = is_array($imdb['director']) ? implode(', ', array_unique($imdb['director'])) : $imdb['director']; } if ($this->checkVariable($imdb['actors'])) { $mov['actors'] = is_array($imdb['actors']) ? implode(', ', array_unique($imdb['actors'])) : $imdb['actors']; } if ($this->checkVariable($imdb['language'])) { $mov['language'] = is_array($imdb['language']) ? implode(', ', array_unique($imdb['language'])) : $imdb['language']; } if (is_array($mov['genre'])) { $mov['genre'] = implode(', ', array_unique($mov['genre'])); } if (is_array($mov['type'])) { $mov['type'] = implode(', ', array_unique($mov['type'])); } $mov['title'] = html_entity_decode($mov['title'], ENT_QUOTES, 'UTF-8'); $mov['plot'] = html_entity_decode(preg_replace('/\\s+See full summary »/', ' ', $mov['plot']), ENT_QUOTES, 'UTF-8'); $mov['tagline'] = html_entity_decode($mov['tagline'], ENT_QUOTES, 'UTF-8'); $mov['genre'] = html_entity_decode($mov['genre'], ENT_QUOTES, 'UTF-8'); $mov['director'] = html_entity_decode($mov['director'], ENT_QUOTES, 'UTF-8'); $mov['actors'] = html_entity_decode($mov['actors'], ENT_QUOTES, 'UTF-8'); $mov['language'] = html_entity_decode($mov['language'], ENT_QUOTES, 'UTF-8'); $mov['type'] = html_entity_decode(ucwords(preg_replace('/[\\.\\_]/', ' ', $mov['type'])), ENT_QUOTES, 'UTF-8'); $mov['title'] = str_replace(['/', '\\'], '', $mov['title']); $movieID = $this->pdo->queryInsert(sprintf("\n\t\t\t\tINSERT INTO movieinfo\n\t\t\t\t\t(imdbid, tmdbid, title, rating, tagline, plot, year, genre, type,\n\t\t\t\t\tdirector, actors, language, cover, backdrop, createddate, updateddate)\n\t\t\t\tVALUES\n\t\t\t\t\t(%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d, NOW(), NOW())\n\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t\timdbid = %d, tmdbid = %s, title = %s, rating = %s, tagline = %s, plot = %s, year = %s, genre = %s,\n\t\t\t\t\ttype = %s, director = %s, actors = %s, language = %s, cover = %d, backdrop = %d, updateddate = NOW()", $mov['imdb_id'], $mov['tmdb_id'], $this->pdo->escapeString($mov['title']), $this->pdo->escapeString($mov['rating']), $this->pdo->escapeString($mov['tagline']), $this->pdo->escapeString($mov['plot']), $this->pdo->escapeString($mov['year']), $this->pdo->escapeString(substr($mov['genre'], 0, 64)), $this->pdo->escapeString($mov['type']), $this->pdo->escapeString($mov['director']), $this->pdo->escapeString($mov['actors']), $this->pdo->escapeString(substr($mov['language'], 0, 64)), $mov['cover'], $mov['backdrop'], $mov['imdb_id'], $mov['tmdb_id'], $this->pdo->escapeString($mov['title']), $this->pdo->escapeString($mov['rating']), $this->pdo->escapeString($mov['tagline']), $this->pdo->escapeString($mov['plot']), $this->pdo->escapeString($mov['year']), $this->pdo->escapeString(substr($mov['genre'], 0, 64)), $this->pdo->escapeString($mov['type']), $this->pdo->escapeString($mov['director']), $this->pdo->escapeString($mov['actors']), $this->pdo->escapeString(substr($mov['language'], 0, 64)), $mov['cover'], $mov['backdrop'])); if ($this->echooutput && $this->service !== '') { $this->pdo->log->doEcho($this->pdo->log->headerOver($movieID !== 0 ? 'Added/updated movie: ' : 'Nothing to update for movie: ') . $this->pdo->log->primary($mov['title'] . ' (' . $mov['year'] . ') - ' . $mov['imdb_id'])); } return $movieID === 0 ? false : true; }
$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; }
/** * Add a new regex. * * @param array $data * * @return bool */ public function addRegex(array $data) { return (bool) $this->pdo->queryInsert(sprintf('INSERT INTO %s (group_regex, regex, status, description, ordinal%s) VALUES (%s, %s, %d, %s, %d%s)', $this->tableName, $this->tableName === 'category_regexes' ? ', category_id' : '', trim($this->pdo->escapeString($data['group_regex'])), trim($this->pdo->escapeString($data['regex'])), $data['status'], trim($this->pdo->escapeString($data['description'])), $data['ordinal'], $this->tableName === 'category_regexes' ? ', ' . $data['category_id'] : '')); }
/** * Adds a new blacklist from binary blacklist edit admin web page. * * @param Array $blacklistArray * * @return bool */ public function addBlacklist($blacklistArray) { return $this->_pdo->queryInsert(sprintf(' INSERT INTO binaryblacklist (groupname, regex, status, description, optype, msgcol) VALUES (%s, %s, %d, %s, %d, %d)', $blacklistArray['groupname'] == '' ? 'null' : $this->_pdo->escapeString(preg_replace('/a\\.b\\./i', 'alt.binaries.', $blacklistArray['groupname'])), $this->_pdo->escapeString($blacklistArray['regex']), $blacklistArray['status'], $this->_pdo->escapeString($blacklistArray['description']), $blacklistArray['optype'], $blacklistArray['msgcol'])); }
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)); }
/** * Add a movie to the users movie list. * * @param int $uid * @param int $imdbid * @param array $catid * * @return bool|int */ public function addMovie($uid, $imdbid, $catid = []) { $catid = !empty($catid) ? $this->pdo->escapeString(implode('|', $catid)) : "NULL"; return $this->pdo->queryInsert(sprintf("INSERT INTO user_movies (user_id, imdbid, categoryid, createddate) VALUES (%d, %d, %s, NOW())", $uid, $imdbid, $catid)); }
/** * Insert a single release returning the ID on success or false on failure. * * @param array $parameters Insert parameters, must be escaped if string. * * @return bool|int */ public function insertRelease(array $parameters = []) { $parameters['id'] = $this->pdo->queryInsert(sprintf("INSERT INTO releases\n\t\t\t\t\t(name, searchname, totalpart, group_id, adddate, guid, postdate, fromname,\n\t\t\t\t\tsize, passwordstatus, haspreview, categoryid, nfostatus, nzbstatus,\n\t\t\t\t\tisrenamed, iscategorized, reqidstatus, preid)\n\t\t\t\t VALUES (%s, %s, %d, %d, NOW(), %s, %s, %s, %s, %d, -1, %d, -1, %d, %d, 1, %d, %d)", $parameters['name'], $parameters['searchname'], $parameters['totalpart'], $parameters['group_id'], $parameters['guid'], $parameters['postdate'], $parameters['fromname'], $parameters['size'], $this->passwordStatus, $parameters['categoryid'], $parameters['nzbstatus'], $parameters['isrenamed'], $parameters['reqidstatus'], $parameters['preid'])); $this->sphinxSearch->insertRelease($parameters); return $parameters['id']; }
if ($collections instanceof \Traversable) { foreach ($collections as $collection) { $collection['subject'] = $pdo->escapeString($collection['subject']); $collection['fromname'] = $pdo->escapeString($collection['fromname']); $collection['date'] = $pdo->escapeString($collection['date']); $collection['collectionhash'] = $pdo->escapeString($collection['collectionhash']); $collection['dateadded'] = $pdo->escapeString($collection['dateadded']); $collection['xref'] = $pdo->escapeString($collection['xref']); $collection['releaseid'] = $pdo->escapeString($collection['releaseid']); $oldcid = array_shift($collection); if ($debug) { echo "\n\nCollection insert:\n"; print_r($collection); echo sprintf("\nINSERT INTO collections_%d (subject, fromname, date, xref, totalfiles, group_id, collectionhash, dateadded, filecheck, filesize, releaseid) VALUES (%s)\n\n", $collection['group_id'], implode(', ', $collection)); } $newcid = array('collection_id' => $pdo->queryInsert(sprintf('INSERT INTO collections_%d (subject, fromname, date, xref, totalfiles, group_id, collectionhash, dateadded, filecheck, filesize, releaseid) VALUES (%s);', $collection['group_id'], implode(', ', $collection)))); $consoletools->overWrite('Collections Completed: ' . $consoletools->percentString($ccount, $clen['total'])); //Get binaries and split to correct group tables. $binaries = $pdo->queryAssoc('SELECT * FROM binaries WHERE collection_id = ' . $oldcid . ';'); if ($binaries instanceof \Traversable) { foreach ($binaries as $binary) { $binary['name'] = $pdo->escapeString($binary['name']); $binary['binaryhash'] = $pdo->escapeString($binary['binaryhash']); $oldbid = array_shift($binary); $binarynew = array_replace($binary, $newcid); if ($debug) { echo "\n\nBinary insert:\n"; print_r($binarynew); echo sprintf("\nINSERT INTO binaries_%d (name, collection_id, filenumber, totalparts, currentparts, binaryhash, partcheck, partsize) VALUES (%s)\n\n", $collection['group_id'], implode(', ', $binarynew)); } $newbid = array('binaryid' => $pdo->queryInsert(sprintf('INSERT INTO binaries_%d (name, collection_id, filenumber, totalparts, currentparts, binaryhash, partcheck, partsize) VALUES (%s);', $collection['group_id'], implode(', ', $binarynew))));
public function add($menu) { return $this->pdo->queryInsert(sprintf("INSERT INTO menu_items (href, title, tooltip, role, ordinal, menueval, newwindow ) VALUES (%s, %s, %s, %d, %d, %s, %d)", $this->pdo->escapeString($menu["href"]), $this->pdo->escapeString($menu["title"]), $this->pdo->escapeString($menu["tooltip"]), $menu["role"], $menu["ordinal"], $this->pdo->escapeString($menu["menueval"]), $menu["newwindow"])); }
/** * @param string $bookInfo * @param null $amazdata * * @return false|int|string */ public function updateBookInfo($bookInfo = '', $amazdata = null) { $ri = new ReleaseImage($this->pdo); $book = []; $amaz = false; if ($bookInfo != '') { $amaz = $this->fetchAmazonProperties($bookInfo); } else { if ($amazdata != null) { $amaz = $amazdata; } } if (!$amaz) { return false; } $book['title'] = (string) $amaz->Items->Item->ItemAttributes->Title; $book['author'] = (string) $amaz->Items->Item->ItemAttributes->Author; $book['asin'] = (string) $amaz->Items->Item->ASIN; $book['isbn'] = (string) $amaz->Items->Item->ItemAttributes->ISBN; if ($book['isbn'] == '') { $book['isbn'] = 'null'; } $book['ean'] = (string) $amaz->Items->Item->ItemAttributes->EAN; if ($book['ean'] == '') { $book['ean'] = 'null'; } $book['url'] = (string) $amaz->Items->Item->DetailPageURL; $book['url'] = str_replace("%26tag%3Dws", "%26tag%3Dopensourceins%2D21", $book['url']); $book['salesrank'] = (string) $amaz->Items->Item->SalesRank; if ($book['salesrank'] == '') { $book['salesrank'] = 'null'; } $book['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher; if ($book['publisher'] == '') { $book['publisher'] = 'null'; } $book['publishdate'] = date('Y-m-d', strtotime((string) $amaz->Items->Item->ItemAttributes->PublicationDate)); if ($book['publishdate'] == '') { $book['publishdate'] = 'null'; } $book['pages'] = (string) $amaz->Items->Item->ItemAttributes->NumberOfPages; if ($book['pages'] == '') { $book['pages'] = 'null'; } if (isset($amaz->Items->Item->EditorialReviews->EditorialReview->Content)) { $book['overview'] = strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content); if ($book['overview'] == '') { $book['overview'] = 'null'; } } else { $book['overview'] = 'null'; } if (isset($amaz->Items->Item->BrowseNodes->BrowseNode->Name)) { $book['genre'] = (string) $amaz->Items->Item->BrowseNodes->BrowseNode->Name; if ($book['genre'] == '') { $book['genre'] = 'null'; } } else { $book['genre'] = 'null'; } $book['coverurl'] = (string) $amaz->Items->Item->LargeImage->URL; if ($book['coverurl'] != '') { $book['cover'] = 1; } else { $book['cover'] = 0; } $check = $this->pdo->queryOneRow(sprintf('SELECT id FROM bookinfo WHERE asin = %s', $this->pdo->escapeString($book['asin']))); if ($check === false) { $bookId = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\t\t\t\tINSERT INTO bookinfo\n\t\t\t\t\t\t\t\t\t(title, author, asin, isbn, ean, url, salesrank, publisher, publishdate, pages,\n\t\t\t\t\t\t\t\t\toverview, genre, cover, createddate, updateddate)\n\t\t\t\t\t\t\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, now(), now())", $this->pdo->escapeString($book['title']), $this->pdo->escapeString($book['author']), $this->pdo->escapeString($book['asin']), $this->pdo->escapeString($book['isbn']), $this->pdo->escapeString($book['ean']), $this->pdo->escapeString($book['url']), $book['salesrank'], $this->pdo->escapeString($book['publisher']), $this->pdo->escapeString($book['publishdate']), $book['pages'], $this->pdo->escapeString($book['overview']), $this->pdo->escapeString($book['genre']), $book['cover'])); } else { $bookId = $check['id']; $this->pdo->queryExec(sprintf(' UPDATE bookinfo SET title = %s, author = %s, asin = %s, isbn = %s, ean = %s, url = %s, salesrank = %s, publisher = %s, publishdate = %s, pages = %s, overview = %s, genre = %s, cover = %d, updateddate = NOW() WHERE id = %d', $this->pdo->escapeString($book['title']), $this->pdo->escapeString($book['author']), $this->pdo->escapeString($book['asin']), $this->pdo->escapeString($book['isbn']), $this->pdo->escapeString($book['ean']), $this->pdo->escapeString($book['url']), $book['salesrank'], $this->pdo->escapeString($book['publisher']), $this->pdo->escapeString($book['publishdate']), $book['pages'], $this->pdo->escapeString($book['overview']), $this->pdo->escapeString($book['genre']), $book['cover'], $bookId)); } if ($bookId) { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header("Added/updated book: ")); if ($book['author'] !== '') { $this->pdo->log->doEcho($this->pdo->log->alternateOver(" Author: ") . $this->pdo->log->primary($book['author'])); } echo $this->pdo->log->alternateOver(" Title: ") . $this->pdo->log->primary(" " . $book['title']); if ($book['genre'] !== 'null') { $this->pdo->log->doEcho($this->pdo->log->alternateOver(" Genre: ") . $this->pdo->log->primary(" " . $book['genre'])); } } $book['cover'] = $ri->saveImage($bookId, $book['coverurl'], $this->imgSavePath, 250, 250); } else { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header('Nothing to update: ') . $this->pdo->log->primary($book['author'] . ' - ' . $book['title'])); } } return $bookId; }
/** * @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; }
} $data = $nntp->getGroups(); if ($nntp->isError($data)) { exit($pdo->log->error("\nFailed to getGroups() from nntp server.\n")); } if (!isset($data['group'])) { exit($pdo->log->error("\nFailed to getGroups() from nntp server.\n")); } $nntp->doQuit(); $res = $pdo->query("SELECT name FROM groups"); $counter = 0; $minvalue = $argv[1]; foreach ($data as $newgroup) { if (isset($newgroup["group"])) { if (strstr($newgroup["group"], ".bin") != false && MyInArray($res, $newgroup["group"], "name") == false && $newgroup["last"] - $newgroup["first"] > 1000000) { $pdo->queryInsert(sprintf("INSERT INTO allgroups (name, first_record, last_record, updated) VALUES (%s, %d, %d, NOW())", $pdo->escapeString($newgroup["group"]), $newgroup["first"], $newgroup["last"])); } } } $grps = $pdo->query("SELECT DISTINCT name FROM allgroups WHERE name NOT IN (SELECT name FROM groups)"); foreach ($grps as $grp) { if (!myInArray($res, $grp, "name")) { $data = $pdo->queryOneRow(sprintf("SELECT (MAX(last_record) - MIN(first_record)) AS count, (MAX(last_record) - MIN(last_record))/(UNIX_TIMESTAMP(MAX(updated))-UNIX_TIMESTAMP(MIN(updated))) as per_second, (MAX(last_record) - MIN(last_record)) AS tracked, MIN(updated) AS firstchecked from allgroups WHERE name = %s", $pdo->escapeString($grp["name"]))); if (floor($data["per_second"] * 3600) >= $minvalue) { echo $pdo->log->header($grp["name"]); echo $pdo->log->primary("Available Post Count: " . number_format($data["count"]) . "\n" . "Date First Checked: " . $data["firstchecked"] . "\n" . "Posts Since First: " . number_format($data["tracked"]) . "\n" . "Average Per Hour: " . number_format(floor($data["per_second"] * 3600)) . "\n"); $counter++; } } } if ($counter == 0) {
$nntp = new NNTP(['Settings' => $pdo]); if ($nntp->doConnect() !== true) { exit($pdo->log->error("Unable to connect to usenet.")); } echo $pdo->log->header("Getting first/last for all your active groups."); $data = $nntp->getGroups(); if ($nntp->isError($data)) { exit($pdo->log->error("Failed to getGroups() from nntp server.")); } echo $pdo->log->header("Inserting new values into shortgroups table."); $pdo->queryExec('TRUNCATE TABLE shortgroups'); // Put into an array all active groups $res = $pdo->query('SELECT name FROM groups WHERE active = 1 OR backfill = 1'); foreach ($data as $newgroup) { if (myInArray($res, $newgroup['group'], 'name')) { $pdo->queryInsert(sprintf('INSERT INTO shortgroups (name, first_record, last_record, updated) VALUES (%s, %s, %s, NOW())', $pdo->escapeString($newgroup['group']), $pdo->escapeString($newgroup['first']), $pdo->escapeString($newgroup['last']))); echo $pdo->log->primary('Updated ' . $newgroup['group']); } } echo $pdo->log->header('Running time: ' . $consoleTools->convertTimer(TIME() - $start)); function myInArray($array, $value, $key) { //loop through the array foreach ($array as $val) { //if $val is an array cal myInArray again with $val as array input if (is_array($val)) { if (myInArray($val, $value, $key)) { return true; } } else { //else check if the given key has $value as value
/** * 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; }
/** * If a user downloads a NZB, log it. * * @param int $userID ID of the user. * * @return bool|int */ public function addDownloadRequest($userID) { return $this->pdo->queryInsert(sprintf("INSERT INTO user_downloads (user_id, timestamp) VALUES (%d, NOW())", $userID)); }