Example #1
0
 /**
  * Gets the specific episode info for the parsed release after match
  * Returns a formatted array of episode data or false if no match
  *
  * @param integer $tvmazeid
  * @param integer $season
  * @param integer $episode
  * @param string  $airdate
  * @param integer $videoId
  *
  * @return array|false
  */
 protected function getEpisodeInfo($tvmazeid, $season, $episode, $airdate = '', $videoId = 0)
 {
     $return = $response = false;
     if ($airdate !== '') {
         $response = $this->client->getEpisodesByAirdate($tvmazeid, $airdate);
     } else {
         if ($videoId > 0) {
             $response = $this->client->getEpisodesByShowID($tvmazeid);
         } else {
             $response = $this->client->getEpisodeByNumber($tvmazeid, $season, $episode);
         }
     }
     sleep(1);
     //Handle Single Episode Lookups
     if (is_object($response)) {
         if ($this->checkRequiredAttr($response, 'tvmazeE')) {
             $return = $this->formatEpisodeInfo($response);
         }
     } else {
         if (is_array($response)) {
             //Handle new show/all episodes and airdate lookups
             foreach ($response as $singleEpisode) {
                 if ($this->checkRequiredAttr($singleEpisode, 'tvmazeE')) {
                     // If this is an airdate lookup and it matches the airdate, set a return
                     if ($airdate !== '' && $airdate == $singleEpisode->airdate) {
                         $return = $this->formatEpisodeInfo($singleEpisode);
                     } else {
                         // Insert the episode
                         $this->addEpisode($videoId, $this->formatEpisodeInfo($singleEpisode));
                     }
                 }
             }
         }
     }
     return $return;
 }