/** * Process all untagged movies to link them to a movieinfo row. */ public function processMovieReleases() { $ret = 0; $nfo = new Nfo(); $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where imdbid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 100", Category::CAT_PARENT_MOVIE)); if ($this->pdo->getNumRows($res) > 0) { if ($this->echooutput) { echo "MovProc : Processing " . $this->pdo->getNumRows($res) . " movie releases\n"; } while ($arr = $this->pdo->getAssocArray($res)) { $imdbID = false; /* Preliminary IMDB id Detection from NFO file */ $rawnfo = ''; if ($nfo->getNfo($arr['id'], $rawnfo)) { $imdbID = $this->parseImdbFromNfo($rawnfo); } if ($imdbID !== false) { // Set IMDB (if found in nfo) and move along $this->pdo->queryExec(sprintf("update releases set imdbid = %s where id = %d", $this->pdo->escapeString($imdbID), $arr["id"])); //check for existing movie entry $movCheck = $this->getMovieInfo($imdbID); if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) { $movieId = $this->updateMovieInfo($imdbID); } continue; } $moviename = $this->parseMovieName($arr['searchname']); if ($moviename !== false) { if ($this->echooutput) { echo 'MovProc : ' . $moviename . ' [' . $arr['searchname'] . ']' . "\n"; } //$buffer = getUrl("https://www.google.com/search?source=ig&hl=en&rlz=&btnG=Google+Search&aq=f&oq=&q=".urlencode($moviename.' site:imdb.com')); $buffer = Utility::getUrl(['url' => 'http://www.bing.com/search?&q=' . urlencode($moviename . ' site:imdb.com')]); // make sure we got some data if ($buffer !== false && strlen($buffer)) { $imdbId = $this->parseImdbFromNfo($buffer); if ($imdbId !== false) { //update release with imdb id $this->pdo->queryExec(sprintf("update releases SET imdbid = %s WHERE id = %d", $this->pdo->escapeString($imdbId), $arr["id"])); //check for existing movie entry $movCheck = $this->getMovieInfo($imdbId); if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) { $movieId = $this->updateMovieInfo($imdbId); } } else { //no imdb id found, set to all zeros so we dont process again $this->pdo->queryExec(sprintf("update releases SET imdbid = %d WHERE id = %d", 0, $arr["id"])); } } else { //url fetch failed, will try next run } } else { //no valid movie name found, set to all zeros so we dont process again $this->pdo->queryExec(sprintf("update releases SET imdbid = %d WHERE id = %d", 0, $arr["id"])); } } } }
public function processTvReleases($lookupTvRage = true, $numtoProcess = 100) { $ret = 0; $nfo = new Nfo(); // get all releases without a rageid which are in a tv category. $result = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where rageid = -1 and categoryid in ( select id from category where parentid = %d ) order by postdate desc limit %d ", Category::CAT_PARENT_TV, $numtoProcess)); if ($this->pdo->getNumRows($result) > 0) { if ($this->echooutput) { echo "TVRage : Looking up " . $this->pdo->getNumRows($result) . " releases" . ($lookupTvRage ? " using local and web\n" : " local only\n"); } while ($arr = $this->pdo->getAssocArray($result)) { $rageID = false; /* Preliminary Rage id Detection from NFO file */ $rawnfo = ''; if ($nfo->getNfo($arr['id'], $rawnfo)) { $rageID = $this->parseRageIdFromNfo($rawnfo); } if ($rageID) { // Set RageID (if matched db) and move along $res = $this->pdo->query(sprintf("SELECT count(id) as cnt from tvrage where rageid = %d", $rageID)); if (count($res) >= 1 && intval($res[0]['cnt']) > 1) { $this->pdo->queryExec(sprintf("update releases set rageid = %d where id = %d", $rageID, $arr["id"])); continue; } } $show = $this->parseNameEpSeason($arr['searchname']); if (is_array($show) && $show['name'] != '') { // update release with season, ep, and airdate info (if available) from releasetitle $this->updateEpInfo($show, $arr['id']); // find the rageid $id = $this->getByTitle($show['cleanname']); if ($id === false && $lookupTvRage) { // if it doesnt exist locally and lookups are allowed lets try to get it if ($this->echooutput) { echo "TVRage : Didnt find " . $show['cleanname'] . " locally, checking web\n"; } $tvrShow = $this->getRageMatch($show); if ($tvrShow !== false && is_array($tvrShow)) { // get all tv info and add show $this->updateRageInfo($tvrShow['showid'], $show, $tvrShow, $arr['id']); } elseif ($tvrShow === false) { // no match //add to tvrage with rageid = -2 and $show['cleanname'] title only $this->add(-2, $show['cleanname'], '', '', '', ''); } else { // $tvrShow probably equals -1 but we'll do this as a catchall instead of a specific elseif //skip because we couldnt connect to tvrage.com } } elseif ($id > 0) { $tvairdate = isset($show['airdate']) && !empty($show['airdate']) ? $this->pdo->escapeString($show['airdate']) : "null"; $tvtitle = "null"; if ($lookupTvRage) { if ($tvairdate == "null") { //check local releases to see if we already have the data $epinfo = $this->pdo->queryOneRow(sprintf("select tvtitle as title, tvairdate as airdate from releases where tvairdate is not null and season = %s and episode = %s and rageid = %d", $this->pdo->escapeString($show['season']), $this->pdo->escapeString($show['episode']), $id)); //check tvdb episodeinfo data if ($epinfo == false) { $sql = sprintf("select eptitle as title, airdate as airdate from episodeinfo where airdate is not null and fullep = %s and rageid = %d", $this->pdo->escapeString(str_replace('S', '', $show['season']) . 'x' . str_replace('E', '', $show['episode'])), $id); $epinfo = $this->pdo->queryOneRow($sql); } if ($epinfo == false) { $epinfo = $this->getEpisodeInfo($id, $show['season'], $show['episode']); } if ($epinfo !== false) { if (!empty($epinfo['airdate'])) { $tvairdate = $this->pdo->escapeString($epinfo['airdate']); } if (!empty($epinfo['title'])) { $tvtitle = $this->pdo->escapeString($epinfo['title']); } } } } $this->pdo->queryExec(sprintf("update releases set tvtitle=trim(%s), tvairdate=%s, rageid = %d where id = %d", $tvtitle, $tvairdate, $id, $arr["id"])); } else { // cant find rageid, so set rageid to n/a $this->pdo->queryExec(sprintf("update releases set rageid = -2 where id = %d", $arr["id"])); } } else { // not a tv episode, so set rageid to n/a $this->pdo->queryExec(sprintf("update releases set rageid = -2 where id = %d", $arr["id"])); } $ret++; } } return $ret; }