/** * 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) { $insert = 0; $duplicateCheck = $this->pdo->queryOneRow(sprintf(' SELECT id FROM releasefiles WHERE releaseid = %d AND name = %s', $id, $this->pdo->escapeString(utf8_encode($name)))); if ($duplicateCheck === false) { $insert = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\t\tINSERT INTO releasefiles\n\t\t\t\t\t\t(releaseid, name, size, createddate, passworded)\n\t\t\t\t\t\tVALUES\n\t\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 $insert; }
/** * Add a forum post. */ 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)); } $this->pdo->queryInsert(sprintf("INSERT INTO forumpost (forumid, parentid, userid, subject, message, locked, sticky, replies, createddate, updateddate) VALUES ( 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 from nntp provider matching a regex and return an array of messages. */ function addBulk($groupList, $active = 1, $backfill = 1) { $ret = array(); if ($groupList == "") { $ret[] = "No group list provided."; } else { $nntp = new NNTP(['Echo' => false]); if (!$nntp->doConnect()) { $ret[] = "Failed to get NNTP connection"; return $ret; } $groups = $nntp->getGroups(); $nntp->doQuit(); $regfilter = "/(" . str_replace(array('.', '*'), array('\\.', '.*?'), $groupList) . ")\$/"; 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) { $this->pdo->queryExec(sprintf("update groups SET active = %d where id = %d", $active, $res["id"])); $ret[] = array('group' => $group['group'], 'msg' => 'Updated'); } else { $desc = ""; $this->pdo->queryInsert(sprintf("INSERT INTO groups (name, description, active, backfill) VALUES (%s, %s, %d, %s)", $this->pdo->escapeString($group['group']), $this->pdo->escapeString($desc), $active, $backfill)); $ret[] = array('group' => $group['group'], 'msg' => 'Created'); } } } } return $ret; }
public function addMovie($uid, $imdbid, $catid = array()) { $db = new Settings(); $catid = !empty($catid) ? $db->escapeString(implode('|', $catid)) : "null"; $sql = sprintf("insert into usermovies (userid, imdbid, categoryid, createddate) values (%d, %d, %s, now())", $uid, $imdbid, $catid); return $db->queryInsert($sql); }
public function addFull($id, $xml) { $row = $this->getFull($id); if ($row) { return -1; } return $this->pdo->queryInsert(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) { $res = ''; 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; }
/** * 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; }
/** * Add a release_comments row. */ public function addComment($id, $gid, $text, $userid, $host) { if (strlen(trim($text)) == 0) { return false; } if ($this->pdo->getSetting('storeuserips') != "1") { $host = ""; } $comid = $this->pdo->queryInsert(sprintf("INSERT INTO release_comments (releaseid, gid, text, userid, createddate, host) VALUES (%d, %s, %s, %d, now(), %s)", $id, $this->pdo->escapeString($gid), $this->pdo->escapeString($text), $userid, $this->pdo->escapeString($host))); $this->updateReleaseCommentCount($gid); return $comid; }
/** * Insert or update a musicinfo row. */ public function addUpdateMusicInfo($title, $asin, $url, $salesrank, $artist, $publisher, $releasedate, $review, $year, $genreID, $tracks, $cover) { if (strlen($year) > 4) { if (preg_match("/\\d{4}/", $year, $matches)) { $year = $this->pdo->escapeString($matches[0]); } else { $year = "null"; } } else { $year = $this->pdo->escapeString($year); } $sql = sprintf("\n\t\tINSERT INTO musicinfo (title, asin, url, salesrank, artist, publisher, releasedate, review, year, genreID, tracks, cover, createddate, updateddate)\n\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, now(), now())\n\t\t\tON DUPLICATE KEY UPDATE title = %s, asin = %s, url = %s, salesrank = %s, artist = %s, publisher = %s, releasedate = %s, review = %s, year = %s, genreID = %s, tracks = %s, cover = %d, createddate = now(), updateddate = now()", $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $salesrank, $this->pdo->escapeString($artist), $this->pdo->escapeString($publisher), $releasedate, $this->pdo->escapeString($review), $year, $genreID == -1 ? "null" : $genreID, $this->pdo->escapeString($tracks), $cover, $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $salesrank, $this->pdo->escapeString($artist), $this->pdo->escapeString($publisher), $releasedate, $this->pdo->escapeString($review), $this->pdo->escapeString($year), $genreID == -1 ? "null" : $genreID, $this->pdo->escapeString($tracks), $cover); $musicId = $this->pdo->queryInsert($sql); return $musicId; }
/** * Add a releaseregex row. * * @param $regex * * @return bool|int */ public function add($regex) { $groupname = $regex["groupname"]; if ($groupname == "") { $groupname = "null"; } else { $groupname = sprintf("%s", $this->pdo->escapeString($regex["groupname"])); } $catid = $regex["category"]; if ($catid == "-1") { $catid = "null"; } else { $catid = sprintf("%d", $regex["category"]); } return $this->pdo->queryInsert(sprintf("insert into releaseregex (groupname, regex, ordinal, status, description, categoryid) values (%s, %s, %d, %d, %s, %s) ", $groupname, $this->pdo->escapeString($regex["regex"]), $regex["ordinal"], $regex["status"], $this->pdo->escapeString($regex["description"]), $catid)); }
/** * Insert or update a bookinfo row. */ public function addUpdateBookInfo($title, $asin, $url, $author, $publisher, $publishdate, $review, $cover, $dewey, $ean, $isbn, $pages) { if ($pages == 0) { $pages = "null"; } else { $pages = $pages + 0; } if ($publishdate == "") { $publishdate = "null"; } elseif (strlen($publishdate) == 4) { $publishdate = $this->pdo->escapeString($publishdate . "-01-01"); } elseif (strlen($publishdate) == 7) { $publishdate = $this->pdo->escapeString($publishdate . "-01"); } else { $publishdate = $this->pdo->escapeString($publishdate); } $sql = sprintf("INSERT INTO bookinfo (title, asin, url, author, publisher, publishdate, review, cover, createddate, updateddate, dewey, ean, isbn, pages)\n\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %d, now(), now(), %s, %s, %s, %s)\n\t\t\tON DUPLICATE KEY UPDATE title = %s, asin = %s, url = %s, author = %s, publisher = %s, publishdate = %s, review = %s, cover = %d, createddate = now(), updateddate = now(), dewey = %s, ean = %s, isbn = %s, pages = %s", $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $this->pdo->escapeString($author), $this->pdo->escapeString($publisher), $publishdate, $this->pdo->escapeString($review), $cover, $this->pdo->escapeString($dewey), $this->pdo->escapeString($ean), $this->pdo->escapeString($isbn), $pages, $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $this->pdo->escapeString($author), $this->pdo->escapeString($publisher), $this->pdo->escapeString($publishdate), $this->pdo->escapeString($review), $cover, $this->pdo->escapeString($dewey), $this->pdo->escapeString($ean), $this->pdo->escapeString($isbn), $pages); $bookId = $this->pdo->queryInsert($sql); return $bookId; }
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, genreid, 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; }
/** * 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.groupid = ' . $groupID; $optionsQuery = self::NfoQueryString($this->pdo); $res = $this->pdo->query(sprintf(' SELECT r.id, r.guid, r.groupid, 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]); $tvRage = new TvRage(['Echo' => $this->echo, 'Settings' => $this->pdo]); foreach ($res as $arr) { $fetchedBinary = $nzbContents->getNFOfromNZB($arr['guid'], $arr['id'], $arr['groupid'], $groups->getByNameByID($arr['groupid'])); if ($fetchedBinary !== false) { // Insert nfo into database. $cp = 'COMPRESS(%s)'; $nc = $this->pdo->escapeString($fetchedBinary); $ckreleaseid = $this->pdo->queryOneRow(sprintf('SELECT id FROM releasenfo WHERE releaseid = %d', $arr['id'])); if (!isset($ckreleaseid['id'])) { $this->pdo->queryInsert(sprintf('INSERT INTO releasenfo (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. if ($processTvrage == 1) { $rageId = $this->parseRageId($fetchedBinary); if ($rageId !== 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 %s %s', NZB::NZB_ADDED, $this->maxRetries, $groupIDQuery, $guidCharQuery)); if ($releases instanceof Traversable) { foreach ($releases as $release) { $this->pdo->queryExec(sprintf('DELETE FROM releasenfo WHERE nfo IS NULL AND releaseid = %d', $release['id'])); } } // Set releases with no NFO. $this->pdo->queryExec(sprintf(' UPDATE releases r SET r.nfostatus = %d WHERE r.nzbstatus = %d AND r.nfostatus < %d %s %s', self::NFO_FAILED, NZB::NZB_ADDED, $this->maxRetries, $groupIDQuery, $guidCharQuery)); 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; }
public function addSource($description, $username, $usermail, $usenetgroup, $publickey) { $db = new Settings(); $sql = sprintf("INSERT INTO spotnabsources " . "(description, username, useremail," . " usenetgroup, publickey, active) " . "VALUES (%s, %s, %s, %s, %s, 0)", $db->escapeString($description), $db->escapeString($username), $db->escapeString($usermail), $db->escapeString($usenetgroup), $db->escapeString($publickey)); return $db->queryInsert($sql); }
require_once dirname(__FILE__) . '/../../../www/config.php'; use newznab\db\Settings; $pdo = new Settings(); if (!isset($argv[1]) || $argv[1] != 'true') { exit($pdo->log->error("\nThis script will download all tvrage shows and insert into the db.\n\n" . "php {$argv['0']} true ...: To run.\n")); } $newnames = $updated = 0; echo "Attempting to fetch data file from TVRage...\n"; $tvshows = @simplexml_load_file('http://services.tvrage.com/feeds/show_list.php'); if ($tvshows !== false) { echo "Starting to process file entries...\n"; foreach ($tvshows->show as $rage) { echo "RageID: " . $rage->id . ", name: " . $rage->name . " - "; $dupecheck = $pdo->queryOneRow(sprintf('SELECT COUNT(id) AS count FROM tvrage WHERE id = %s', $pdo->escapeString($rage->id))); if (isset($rage->id) && isset($rage->name) && !empty($rage->id) && !empty($rage->name) && $dupecheck !== false && $dupecheck['count'] == 0) { $pdo->queryInsert(sprintf('INSERT INTO tvrage (rageid, releasetitle, country) VALUES (%s, %s, %s)', $pdo->escapeString($rage->id), $pdo->escapeString($rage->name), $pdo->escapeString($rage->country))); $updated++; echo "added\n"; } elseif (isset($rage->id) && isset($rage->name) && !empty($rage->id) && !empty($rage->name) && $dupecheck !== false && $dupecheck['count'] > 0) { echo "Up to date\n"; } else { echo "FAILED\n"; } } } else { exit($pdo->log->info("TVRage site has a hard limit of 400 concurrent API requests. At the moment, they have reached that limit. Please wait before retrying\n")); } if ($updated != 0) { echo $pdo->log->info("Inserted " . $updated . " new shows into the TvRage table. To fill out the newly populated TvRage table\n" . "php misc/update_scripts/nix_scripts/tmux/lib/testing/PostProc/updateTvRage.php\n"); } else { echo "\n";
/** * Add a releasefiles row. */ public function add($id, $name, $size, $createddate, $passworded) { $db = new Settings(); $sql = sprintf("INSERT INTO releasefiles (releaseid, name, size, createddate, passworded) VALUES (%d, %s, %s, from_unixtime(%d), %d)", $id, $db->escapeString($name), $db->escapeString($size), $createddate, $passworded); return $db->queryInsert($sql); }
$binary['date'] = $pdo->escapeString($binary['date']); $binary['binaryhash'] = $pdo->escapeString($binary['binarynhash']); $binary['dateadded'] = $pdo->escapeString($binary['dateadded']); $binary['xref'] = $pdo->escapeString($binary['xref']); $binary['releaseid'] = $pdo->escapeString($binary['releaseid']); $binary['categoryid'] = $pdo->escapeString($binary['categoryid']); $binary['totalparts'] = $pdo->escapeString($binary['totalparts']); $binary['relpart'] = $pdo->escapeString($binary['relpart']); $binary['reltotalpart'] = $pdo->escapeString($binary['reltotalpart']); $oldbid = array_shift($binary); if ($debug) { echo "\n\nBinaries insert:\n"; print_r($binary); echo sprintf("\nINSERT INTO binaries_%d (name, fromname, date, xref, groupid, dateadded, releaseid, categoryid, totalparts, binaryhash, relpart, reltotalpart) VALUES (%s)\n\n", $binary['groupid'], implode(', ', $binary)); } $newbid = array('binaryid' => $pdo->queryInsert(sprintf('INSERT INTO binaries_%d (NAME, fromname, date, xref, groupid, dateadded, releaseid, categoryid, totalparts, binaryhash, relpart, reltotalpart) VALUES (%s);', $binary['groupid'], implode(', ', $binarynew)))); //Get parts and split to correct group tables. $parts = $pdo->queryAssoc('SELECT * FROM parts WHERE binaryid = ' . $oldbid . ';'); if ($parts instanceof \Traversable) { $firstpart = true; $partsnew = ''; foreach ($parts as $part) { $oldpid = array_shift($part); $partnew = array_replace($part, $newbid); $partsnew .= '(\'' . implode('\', \'', $partnew) . '\'), '; } $partsnew = substr($partsnew, 0, -2); if ($debug) { echo "\n\nParts insert:\n"; echo sprintf("\nINSERT INTO parts_%d (binaryid, messageid, number, partnumber, size) VALUES %s;\n\n", $binary['groupid'], $partsnew); }
/** * 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 = array(); // 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 = array(); 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: ") . $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; }
$binaryId = 0; $groupRegexes = $releaseRegex->getForGroup($groupName); foreach ($nzbInfo->nzb as $postFile) { $regexMatches = []; foreach ($groupRegexes as $groupRegex) { $regexCheck = $releaseRegex->performMatch($groupRegex, $postFile["subject"]); if ($regexCheck !== false) { $regexMatches = $regexCheck; break; } } if (!empty($regexMatches)) { $relparts = explode("/", $regexMatches['parts']); $regexMatches['regcatid'] = $categoryoverride != -1 ? $categoryoverride : $regexMatches['regcatid']; $sql = sprintf("INSERT INTO binaries (name, fromname, date, xref, totalParts, groupid, binaryhash, dateadded,\n categoryid, regexid, reqid, procstat, relpart, reltotalpart, relname)\n values (%s, %s, %s, %s, %d, %d, %s, NOW(), %s, %d, %s, %d, %d, %d, %s )", $db->escapeString($postFile["subject"]), $db->escapeString($postFile["poster"]), $db->escapeString(date("Y-m-d H:i:s", $postFile["posted"])), $db->escapeString(implode(': ', $nzbInfo->groups) . ':'), $postFile["segmenttotal"], $groupID, $db->escapeString(md5($postFile["subject"] . $postFile["poster"] . $groupID)), $regexMatches['regcatid'], $regexMatches['regexid'], $db->escapeString($regexMatches['reqid']), \Releases::PROCSTAT_TITLEMATCHED, $relparts[0], $relparts[1], $db->escapeString(str_replace('_', ' ', $regexMatches['name']))); $binaryId = $db->queryInsert($sql); $numbins++; if (count($postFile['segments']) > 0) { $sql = "INSERT INTO parts (binaryid, messageid, number, partnumber, size) values "; foreach ($postFile['segments'] as $fileSegmentNum => $fileSegment) { $sql .= sprintf("(%d, %s, 0, %d, %d),", $binaryId, $db->escapeString($fileSegment), $fileSegmentNum, $postFile['segmentbytes'][$fileSegmentNum]); $numparts++; } $db->queryInsert(substr($sql, 0, -1)); } } } if ($binaryId != 0) { echo sprintf("%0" . $digits . "d %.2f%% Imported %s (%d:%s-%d/%d)\n", $items - $num, $num / $items * 100, basename($nzbFile), $regexMatches['regcatid'], $regexMatches['regexid'], $numbins, $numparts); if ($movefiles) { if (!file_exists($importedpath)) {
$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
/** * @param $title * @param $year * @param 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("INSERT INTO musicinfo (title, asin, url, salesrank, artist, publisher, " . "releasedate, review, year, genreID, tracks, cover, createddate, updateddate) VALUES " . "(%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, genreID = %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->primaryOver($artist . $mus['title'] . " (" . $mus['year'] . ")")); } } return $musicId; }
/** * Add a new blacklist row. */ public function addBlacklist($regex) { $db = new Settings(); $groupname = $regex["groupname"]; if ($groupname == "") { $groupname = "null"; } else { $groupname = preg_replace("/a\\.b\\./i", "alt.binaries.", $groupname); $groupname = sprintf("%s", $db->escapeString($groupname)); } return $db->queryInsert(sprintf("insert into binaryblacklist (groupname, regex, status, description, optype, msgcol) values (%s, %s, %d, %s, %d, %d) ", $groupname, $db->escapeString($regex["regex"]), $regex["status"], $db->escapeString($regex["description"]), $regex["optype"], $regex["msgcol"])); }
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->header($book['author'] . ' - ' . $book['title'])); } } return $bookId; }
/** * Add/Update upcoming row. */ public function updateInsUpcoming($source, $type, $info) { $sql = sprintf("INSERT into upcoming (source,typeID,info,updateddate) VALUES (%s, %d, %s, now()) ON DUPLICATE KEY UPDATE info = %s", $this->pdo->escapeString($source), $type, $this->pdo->escapeString($info), $this->pdo->escapeString($info)); $this->pdo->queryInsert($sql); }
public function add($menu) { return $this->pdo->queryInsert(sprintf("INSERT INTO menu (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 $seriesname */ public function addEmptySeries($seriesname) { $this->pdo->queryInsert(sprintf("INSERT INTO thetvdb (tvdbid, seriesname, createddate) VALUES (0, %s, now())", $this->pdo->escapeString($seriesname))); }
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)); }
private function store_blob($nfometa, $blobhash, $removed) { // This takes a array of blobs with their index id being // the release id; In the event we fetch the data and deem // it no good, we need to add it to the skipped array which // must be passed into the function. $db = new Settings(); foreach ($blobhash as $uid => $blob) { $query = sprintf("REPLACE INTO releasenfo (id, releaseid, binaryID, nfo) " . "VALUES (NULL, %d, 0, compress(%s));", $uid, $db->escapeString($blob)); $id = $db->queryInsert($query); if (!$id) { if ($this->verbose) { echo "!"; } } else { $query = sprintf("UPDATE releases SET releasenfoid = %d WHERE id = %d LIMIT 1", $id, $uid); $res = $db->queryExec($query); if ($this->verbose) { echo "s"; } } } // Now we update the database with entries that have no nfo files // associated with the release foreach ($removed as $uid) { $res = $this->setNfoMissing($uid); if ($res <= 0) { if ($this->verbose) { echo "!"; } } else { if ($this->verbose) { echo "s"; } } } }
/** * Check whether a title is available at Amazon and store its metadata. */ public function updateConsoleInfo($gameInfo) { $gen = new Genres(); $ri = new ReleaseImage(); $con = []; $amaz = $this->fetchAmazonProperties($gameInfo['title'], $gameInfo['node']); if (!$amaz) { return false; } //load genres $defaultGenres = $gen->getGenres(Genres::CONSOLE_TYPE); $genreassoc = []; foreach ($defaultGenres as $dg) { $genreassoc[$dg['id']] = strtolower($dg['title']); } // // get game properties // $con['coverurl'] = (string) $amaz->Items->Item->LargeImage->URL; if ($con['coverurl'] != "") { $con['cover'] = 1; } else { $con['cover'] = 0; } $con['title'] = (string) $amaz->Items->Item->ItemAttributes->Title; if (empty($con['title'])) { $con['title'] = $gameInfo['title']; } $con['platform'] = (string) $amaz->Items->Item->ItemAttributes->Platform; if (empty($con['platform'])) { $con['platform'] = $gameInfo['platform']; } //Beginning of Recheck Code //This is to verify the result back from amazon was at least somewhat related to what was intended. //Some of the Platforms don't match Amazon's exactly. This code is needed to facilitate rechecking. if (preg_match('/^X360$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('X360', 'Xbox 360', $gameInfo['platform']); // baseline single quote } if (preg_match('/^XBOX360$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('XBOX360', 'Xbox 360', $gameInfo['platform']); // baseline single quote } if (preg_match('/^NDS$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('NDS', 'Nintendo DS', $gameInfo['platform']); // baseline single quote } if (preg_match('/^PS3$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('PS3', 'PlayStation 3', $gameInfo['platform']); // baseline single quote } if (preg_match('/^PSP$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('PSP', 'Sony PSP', $gameInfo['platform']); // baseline single quote } if (preg_match('/^Wii$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('Wii', 'Nintendo Wii', $gameInfo['platform']); // baseline single quote $gameInfo['platform'] = str_replace('WII', 'Nintendo Wii', $gameInfo['platform']); // baseline single quote } if (preg_match('/^N64$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('N64', 'Nintendo 64', $gameInfo['platform']); // baseline single quote } if (preg_match('/^NES$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('NES', 'Nintendo NES', $gameInfo['platform']); // baseline single quote } if (preg_match('/Super/i', $con['platform'])) { $con['platform'] = str_replace('Super Nintendo', 'SNES', $con['platform']); // baseline single quote $con['platform'] = str_replace('Nintendo Super NES', 'SNES', $con['platform']); // baseline single quote } //Remove Online Game Code So Titles Match Properly. if (preg_match('/\\[Online Game Code\\]/i', $con['title'])) { $con['title'] = str_replace(' [Online Game Code]', '', $con['title']); // baseline single quote } //Basically the XBLA names contain crap, this is to reduce the title down far enough to be usable if (preg_match('/xbla/i', $gameInfo['platform'])) { $gameInfo['title'] = substr($gameInfo['title'], 0, 10); $con['substr'] = $gameInfo['title']; } //This actual compares the two strings and outputs a percentage value. $titlepercent = ''; $platformpercent = ''; similar_text(strtolower($gameInfo['title']), strtolower($con['title']), $titlepercent); similar_text(strtolower($gameInfo['platform']), strtolower($con['platform']), $platformpercent); //Since Wii Ware games and XBLA have inconsistent original platforms, as long as title is 50% its ok. if (preg_match('/(wiiware|xbla)/i', $gameInfo['platform'])) { if ($titlepercent >= 50) { $platformpercent = 100; } } //If the release is DLC matching sucks, so assume anything over 50% is legit. if (isset($gameInfo['dlc']) && $gameInfo['dlc'] == 1) { if ($titlepercent >= 50) { $titlepercent = 100; $platformpercent = 100; } } //Show the Percentages //echo("Matched: Title Percentage: $titlepercent%"); //echo("Matched: Platform Percentage: $platformpercent%"); //If the Title is less than 80% Platform must be 100% unless it is XBLA if ($titlepercent < 70) { if ($platformpercent != 100) { return false; } } //If title is less than 80% then its most likely not a match if ($titlepercent < 70) { return false; } //Platform must equal 100% if ($platformpercent != 100) { return false; } $con['asin'] = (string) $amaz->Items->Item->ASIN; $con['url'] = (string) $amaz->Items->Item->DetailPageURL; $con['salesrank'] = (string) $amaz->Items->Item->SalesRank; if ($con['salesrank'] == "") { $con['salesrank'] = 'null'; } $con['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher; $con['esrb'] = (string) $amaz->Items->Item->ItemAttributes->ESRBAgeRating; $con['releasedate'] = $this->pdo->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate); if ($con['releasedate'] == "''") { $con['releasedate'] = 'null'; } $con['review'] = ""; if (isset($amaz->Items->Item->EditorialReviews)) { $con['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content)); } $genreKey = -1; $genreName = ''; if (isset($amaz->Items->Item->BrowseNodes) || isset($amaz->Items->Item->ItemAttributes->Genre)) { 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("//Name"); foreach ($amazGenres as $amazGenre) { $currName = trim($amazGenre[0]); if (empty($genreName)) { $genreMatch = $this->matchBrowseNode($currName); if ($genreMatch !== false) { $genreName = $genreMatch; break; } } } } if (empty($genreName) && isset($amaz->Items->Item->ItemAttributes->Genre)) { $tmpGenre = (string) $amaz->Items->Item->ItemAttributes->Genre; $tmpGenre = str_replace('-', ' ', $tmpGenre); $tmpGenre = explode(' ', $tmpGenre); foreach ($tmpGenre as $tg) { $genreMatch = $this->matchBrowseNode(ucwords($tg)); if ($genreMatch !== false) { $genreName = $genreMatch; break; } } } } if (empty($genreName)) { $genreName = 'Unknown'; } if (in_array(strtolower($genreName), $genreassoc)) { $genreKey = array_search(strtolower($genreName), $genreassoc); } else { $genreKey = $this->pdo->queryInsert(sprintf("INSERT INTO genres (`title`, `type`) VALUES (%s, %d)", $this->pdo->escapeString($genreName), Genres::CONSOLE_TYPE)); } $con['consolegenre'] = $genreName; $con['consolegenreID'] = $genreKey; $query = sprintf("\n\t\tINSERT INTO consoleinfo (`title`, `asin`, `url`, `salesrank`, `platform`, `publisher`, `genreid`, `esrb`, `releasedate`, `review`, `cover`, `createddate`, `updateddate`)\n\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, now(), now())\n\t\t\tON DUPLICATE KEY UPDATE `title` = %s, `asin` = %s, `url` = %s, `salesrank` = %s, `platform` = %s, `publisher` = %s, `genreid` = %s, `esrb` = %s, `releasedate` = %s, `review` = %s, `cover` = %d, createddate = now(), updateddate = 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['review']), $con['cover'], $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['review']), $con['cover']); $consoleId = $this->pdo->queryInsert($query); if ($consoleId) { $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250); } return $consoleId; }