xmlEpisodeInfoUrl = "http://services.tvrage.com/myfeeds/episodeinfo.php?key=" . TvRage::APIKEY; $this->imgSavePath = NN_COVERS . 'tvrage' . DS; } /** * Main processing director function for scrapers * Calls work query function and initiates processing * * @param $groupID * @param $guidChar * @param $process * @param bool $local */ public function processSite($groupID = '', $guidChar = '', $process, $local = false) { $res = $this->getTvReleases($groupID, $guidChar, $local, parent::PROCESS_TVRAGE); $tvcount = $res->rowCount(); if ($this->echooutput && $tvcount > 1) { echo $this->pdo->log->header("Processing TV Rage lookup for " . number_format($tvcount) . " release(s)."); } if ($res instanceof \Traversable) { foreach ($res as $arr) { $this->rageId = $this->rageId = false; $show = $this->parseInfo($arr['searchname']); if (is_array($show) && $show['name'] != '') { // Find the Video ID if it already exists by checking the title. $this->videoId = $this->getByTitle($show['cleanname'], parent::TYPE_TV); // Force local lookup only if ($local == true) { $process = false; } if ($this->videoId === false && $process) { // If it doesnt exist locally and lookups are allowed lets try to get it. if ($this->echooutput) { echo $this->pdo->log->primaryOver("Video ID for ") . $this->pdo->log->headerOver($show['cleanname']) . $this->pdo->log->primary(" not found in local db, checking web."); } $tvrShow = $this->getShowInfo($show); if ($tvrShow !== false && is_array($tvrShow)) { // Get all tv info and add show. $this->rageId = $tvrShow['showid']; $this->updateRageInfo($this->rageId, $tvrShow); } else { $this->setVideoNotFound(parent::PROCESS_TVMAZE, $arr['id']); } } if ($this->videoId > 0) { if ($this->echooutput) { echo $this->pdo->log->primaryOver("Video ID for ") . $this->pdo->log->headerOver($show['cleanname']) . $this->pdo->log->primary(" found in local db, setting tvrage ID and attempting episode lookup."); } $episodeId = $this->getBySeasonEp($this->videoId, $show['season'], $show['episode']); if ($episodeId === false) { $epinfo = $this->getEpisodeInfo($this->rageId, $show['season'], $show['episode']); if ($epinfo !== false && isset($epinfo['airdate']) && !empty($epinfo['title'])) { $tvairdate = $this->pdo->escapeString($this->checkDate($epinfo['airdate'])); $tvtitle = $this->pdo->escapeString(trim($epinfo['title'])); $seComplete = 'S' . sprintf('%02s', $show['season']) . 'E' . sprintf('%02s', $show['episode']); $episodeId = $this->addEpisode($this->videoId, [ 'series' => $show['season'], 'episode' => $show['episode'], 'se_complete' => $seComplete, 'firstaired' => $tvairdate, 'title' => $tvtitle, 'summary' => '' ] ); } } echo $this->pdo->log->primary("Found TV Rage Match!"); $this->setVideoIdFound($this->videoId, $arr['id'], $episodeId); // Cant find videos_id, so set tv_episodes_id to PROCESS_TVMAZE. } else { $this->setVideoNotFound(parent::NO_MATCH_FOUND, $arr['id']); } // Not a tv episode, so set videos_id to n/a. } else { $this->setVideoNotFound(parent::NO_MATCH_FOUND, $arr['id']); } } } } /** * Placeholder for Videos getBanner * * @param $videoID * @param $siteId * * @return bool */ protected function getBanner($videoID, $siteId) { return false; } /** * Retrieves poster image from TvRage through ReleaseImage * * @param int $videoId * @param int $siteId * * @return null */ protected function getPoster($videoId, $siteId) { $hascover = (new ReleaseImage($this->pdo))->saveImage( $videoId, $this->posterUrl, $this->imgSavePath, '', '' ); if ($hascover == 1) { $this->setCoverFound($videoId); } } /** * Formats and inserts the TvRage match and calls the download of the cover image * * @param $rageid * @param $tvrShow */ public function updateRageInfo($rageid, $tvrShow) { $country = ''; if (isset($tvrShow['country']) && !empty($tvrShow['country'])) { $country = Country::countryCode($tvrShow['country'], $this->pdo); } $rInfo = $this->getRageInfoFromPage($rageid); $summary = ''; if (isset($rInfo['desc']) && !empty($rInfo['desc'])) { $summary = $rInfo['desc']; } $this->videoId = $this->add( [ 'type' => parent::TYPE_TV, 'title' => $tvrShow['title'], 'column' => 'tvrage', 'siteid' => $rageid, 'summary' => $summary, 'country' => $country, 'started' => $tvrShow['started'], 'publisher' => $tvrShow['publisher'], 'source' => parent::SOURCE_TVRAGE, 'tvdbid' => 0, 'traktid' => 0, 'tvrageid' => $rageid, 'tvmazeid' => 0, 'imdbid' => 0, 'tmdbid' => 0, 'aliases' => $tvrShow['aliases'] ] ); if (isset($rInfo['imgurl']) && !empty($rInfo['imgurl'])) { $this->posterUrl = $rInfo['imgurl']; $this->getPoster($this->videoId, $this->rageId); } } /** * Retrieves episode specific information once a RageID is matched * Returns episode info array if matched, else false * * @param int $rageid * @param int $series * @param int $episode * * @return array|bool */ public function getEpisodeInfo($rageid, $series, $episode) { $result = false; $series = str_ireplace("s", "", $series); $episode = str_ireplace("e", "", $episode); $xml = Utility::getUrl(['url' => $this->xmlEpisodeInfoUrl . "&sid=" . $rageid . "&ep=" . $series . "x" . $episode]); if ($xml !== false) { if (stripos($xml, 'no show found') === false) { $xmlObj = @simplexml_load_string($xml); $arrXml = Utility::objectsIntoArray($xmlObj); if (is_array($arrXml)) { $result = []; if (isset($arrXml['episode']['airdate']) && $arrXml['episode']['airdate'] != '0000-00-00') { $result['airdate'] = $arrXml['episode']['airdate']; } if (isset($arrXml['episode']['title'])) { $result['title'] = $arrXml['episode']['title']; } } } } return $result; } /** * Scrapes additional fields not offered through the standard API * Returns an array of additional params or false if no matched response * * @param string $rageid * * @return array|bool|mixed */ public function getRageInfoFromService($rageid) { $result = false; // Standard show info search as AKAs not needed. $xml = Utility::getUrl(['url' => $this->xmlShowInfoUrl . $rageid]); if ($xml !== false) { $arrXml = Utility::objectsIntoArray(simplexml_load_string($xml)); if (is_array($arrXml)) { $result = ['showid' => $rageid]; $result['country'] = (isset($arrXml['origin_country'])) ? $arrXml['origin_country'] : ''; $result['firstaired'] = (isset($arrXml['startdate'])) ? date('m-d-Y', strtotime($arrXml['startdate'])) : ''; $result = Country::countryCode($result, $this->pdo); } } return $result; } /** * Queries for show description and the cover image info * Returns an array of the additional parameters or seemingly useless array * * @param $rageid * * @return array */ public function getRageInfoFromPage($rageid) { $result = ['desc' => '', 'imgurl' => '']; $page = Utility::getUrl(['url' => $this->showInfoUrl . $rageid]); $matches = ''; if ($page !== false) { // Description. preg_match('@