Ejemplo n.º 1
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";
             }
         }
     }
 }