Beispiel #1
0
 /**
  * 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"]));
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Check all untagged console releases for their extended metadata.
  */
 public function processConsoleReleases()
 {
     $ret = 0;
     $numlookedup = 0;
     $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where consoleinfoid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 100", Category::CAT_PARENT_GAME));
     if ($this->pdo->getNumRows($res) > 0) {
         if ($this->echooutput) {
             echo "ConsPrc : Processing " . $this->pdo->getNumRows($res) . " console releases\n";
         }
         while ($arr = $this->pdo->getAssocArray($res)) {
             if ($numlookedup > Console::NUMTOPROCESSPERTIME) {
                 return;
             }
             $gameInfo = $this->parseTitle($arr['searchname']);
             if ($gameInfo !== false) {
                 if ($this->echooutput) {
                     echo 'ConsPrc : ' . $gameInfo["title"] . ' (' . $gameInfo["platform"] . ')' . "\n";
                 }
                 //check for existing console entry
                 $gameCheck = $this->getConsoleInfoByName($gameInfo["title"], $gameInfo["platform"]);
                 if ($gameCheck === false) {
                     $numlookedup++;
                     $gameId = $this->updateConsoleInfo($gameInfo);
                     if ($gameId === false) {
                         $gameId = -2;
                     }
                 } else {
                     $gameId = $gameCheck["id"];
                 }
                 //update release
                 $this->pdo->queryExec(sprintf("update releases SET consoleinfoid = %d WHERE id = %d", $gameId, $arr["id"]));
             } else {
                 //could not parse release title
                 $this->pdo->queryExec(sprintf("update releases SET consoleinfoid = %d WHERE id = %d", -2, $arr["id"]));
             }
         }
     }
 }
Beispiel #3
0
 /**
  * Process all untagged releases to see if musicinfo exists for them.
  */
 public function processMusicReleases()
 {
     $ret = 0;
     $numlookedup = 0;
     $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where musicinfoid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 1000", Category::CAT_PARENT_MUSIC));
     if ($this->pdo->getNumRows($res) > 0) {
         if ($this->echooutput) {
             echo "MusicPr : Processing " . $this->pdo->getNumRows($res) . " audio releases\n";
         }
         while ($arr = $this->pdo->getAssocArray($res)) {
             if ($numlookedup > Music::NUMTOPROCESSPERTIME) {
                 return;
             }
             $albumId = -2;
             $album = $this->parseArtist($arr['searchname']);
             if ($album !== false) {
                 if ($this->echooutput) {
                     echo 'MusicPr : Looking up: ' . $album["artist"] . ' - ' . $album["album"] . "\n";
                 }
                 //check for existing music entry
                 $albumCheck = $this->getMusicInfoByName($album["artist"], $album["album"]);
                 if ($albumCheck === false) {
                     //
                     // get from amazon
                     //
                     $numlookedup++;
                     $ret = $this->updateMusicInfo($album["artist"], $album["album"], $album['year']);
                     if ($ret !== false) {
                         $albumId = $ret;
                     }
                 } else {
                     $albumId = $albumCheck["id"];
                 }
             }
             $this->pdo->queryExec(sprintf("update releases SET musicinfoid = %d WHERE id = %d", $albumId, $arr["id"]));
         }
     }
 }
Beispiel #4
0
 /**
  * Process all untagged book releases for additional metadata.
  */
 public function processBookReleases()
 {
     $numlookedup = 0;
     $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where bookinfoid IS NULL and categoryid = %d ORDER BY postdate DESC LIMIT 100", Category::CAT_BOOK_EBOOK));
     if ($this->pdo->getNumRows($res) > 0) {
         if ($this->echooutput) {
             echo "BookPrc : Processing " . $this->pdo->getNumRows($res) . " book releases\n";
         }
         while ($arr = $this->pdo->getAssocArray($res)) {
             if ($numlookedup > Book::NUMTOPROCESSPERTIME) {
                 return;
             }
             $bookId = -2;
             $book = $this->parseAuthor($arr['searchname']);
             if ($book !== false) {
                 if ($this->echooutput) {
                     echo 'BookPrc : ' . $book["author"] . ' - ' . $book["title"] . "\n";
                 }
                 //check for existing book entry
                 $bookCheck = $this->getBookInfoByName($book["author"], $book["title"]);
                 if ($bookCheck === false) {
                     //
                     // get from amazon
                     //
                     $numlookedup++;
                     $ret = $this->updateBookInfo($book["author"], $book["title"]);
                     if ($ret !== false) {
                         $bookId = $ret;
                     }
                 } else {
                     $bookId = $bookCheck["id"];
                 }
             }
             $this->pdo->queryExec(sprintf("update releases SET bookinfoid = %d WHERE id = %d", $bookId, $arr["id"]));
         }
     }
 }
Beispiel #5
0
 /**
  *
  */
 public function processReleases()
 {
     $results = $this->pdo->queryDirect(sprintf("SELECT id, searchname, rageid, anidbid, seriesfull, season, episode, tvtitle FROM releases WHERE episodeinfoid IS NULL AND categoryid IN ( SELECT id FROM category WHERE parentid = %d ) LIMIT 150", Category::CAT_PARENT_TV));
     if ($this->pdo->getNumRows($results) > 0) {
         if ($this->echooutput) {
             echo "TheTVDB : Looking up last " . $this->pdo->getNumRows($results) . " releases\n";
         }
         while ($arr = $this->pdo->getAssocArray($results)) {
             unset($TheTVDBAPIArray, $episodeArray, $fullep, $epabsolute, $additionalSql);
             $seriesName = '';
             if ($arr['rageid'] > 0) {
                 $seriesName = $this->pdo->queryOneRow(sprintf('SELECT releasetitle AS seriesName FROM tvrage WHERE rageid = %d', $arr['rageid']));
             } elseif ($arr['anidbid'] > 0) {
                 $seriesName = $this->pdo->queryOneRow(sprintf('SELECT title AS seriesName FROM anidb WHERE anidbid = %d', $arr['anidbid']));
             }
             if (empty($seriesName) || !$seriesName) {
                 $this->notFound($seriesName, "", $arr['id'], false);
                 continue;
             }
             $seriesName = str_replace('`', '\'', $seriesName['seriesName']);
             if (!preg_match('/[21]\\d{3}\\/\\d{2}\\/\\d{2}/', $arr['seriesfull'])) {
                 $fullep = str_pad(str_replace('S', '', $arr['season']), 2, '0', STR_PAD_LEFT) . 'x' . str_pad(str_replace('E', '', $arr['episode']), 2, '0', STR_PAD_LEFT);
             } else {
                 $fullep = str_replace('/', '-', $arr['seriesfull']);
             }
             $TheTVDBAPIArray = $this->getSeriesInfoByName($seriesName);
             if (!$TheTVDBAPIArray) {
                 $seriesid = $this->lookupSeriesID($seriesName);
                 if ($seriesid > 0) {
                     $TheTVDBAPIArray = $this->TheTVDBAPI($seriesid, $seriesName);
                     if ($TheTVDBAPIArray) {
                         $this->addSeries($TheTVDBAPIArray);
                         $this->addEpisodes($TheTVDBAPIArray);
                     } else {
                         $this->addEmptySeries($seriesName);
                         $this->notFound($seriesName, $fullep, $arr['id']);
                         continue;
                     }
                 } else {
                     $this->addEmptySeries($seriesName);
                     $this->notFound($seriesName, $fullep, $arr['id']);
                     continue;
                 }
             } else {
                 if ($TheTVDBAPIArray['tvdbid'] > 0 && time() - strtotime($TheTVDBAPIArray['createddate']) > 604800) {
                     $TheTVDBAPIArray = $this->TheTVDBAPI($TheTVDBAPIArray['tvdbid'], $seriesName);
                     $this->updateSeries($TheTVDBAPIArray['tvdbid'], $TheTVDBAPIArray['actors'], $TheTVDBAPIArray['airsday'], $TheTVDBAPIArray['airstime'], $TheTVDBAPIArray['contentrating'], $TheTVDBAPIArray['firstaired'], $TheTVDBAPIArray['genre'], $TheTVDBAPIArray['imdbid'], $TheTVDBAPIArray['network'], $TheTVDBAPIArray['overview'], $TheTVDBAPIArray['rating'], $TheTVDBAPIArray['ratingcount'], $TheTVDBAPIArray['runtime'], $TheTVDBAPIArray['seriesname'], $TheTVDBAPIArray['status']);
                     $this->addEpisodes($TheTVDBAPIArray);
                 }
             }
             if ($TheTVDBAPIArray['tvdbid'] > 0) {
                 $epabsolute = '0';
                 if ($arr['anidbid'] > 0) {
                     if (preg_match('/S(?P<season>\\d+)[ED](?P<episode>\\d+)/', $arr['episode'], $seasonEpisode)) {
                         $arr['season'] = $seasonEpisode['season'];
                         $arr['episode'] = $seasonEpisode['episode'];
                     } else {
                         $epabsolute = $arr['episode'];
                     }
                 }
                 $Episode = new Episode();
                 $episodeArray = $Episode->getEpisodeInfoByName($seriesName, $fullep, (string) $epabsolute);
                 if (!$episodeArray) {
                     $this->notFound($seriesName, $fullep, $arr['id']);
                     continue;
                 }
             } else {
                 $this->notFound($seriesName, $fullep, $arr['id']);
                 continue;
             }
             $additionalSql = '';
             if ($arr['anidbid'] > 0 && $episodeArray['epabsolute'] > 0) {
                 $additionalSql = sprintf(', season = NULL, episode = %d, tvtitle = %s, tvairdate = %s', $episodeArray['epabsolute'], $this->pdo->escapeString($episodeArray['epabsolute'] . ' - ' . str_replace('\'', '`', $episodeArray['eptitle'])), $this->pdo->escapeString($episodeArray['airdate']));
             }
             $this->pdo->queryExec(sprintf('UPDATE releases SET tvdbid = %d, episodeinfoid = %d %s WHERE id = %d', $TheTVDBAPIArray['tvdbid'], $episodeArray['id'], $additionalSql, $arr['id']));
             if ($this->echooutput) {
                 echo 'TheTVDB : ' . $seriesName . ' ' . $fullep . " returned " . $episodeArray['tvdbid'] . "\n";
             }
         }
     }
 }
Beispiel #6
0
 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;
 }