alhrock / phptvdb

Automatically exported from code.google.com/p/phptvdb
0 stars 0 forks source link

Add GetEpisodeByAirDate support to TV_Show #5

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
http://forums.thetvdb.com/viewtopic.php?f=8&t=866

http://www.thetvdb.com/api/GetEpisodeByAirDate.php?apikey=xxxxxxxxxxxxxxxxx&seri
esid=71256&airdate=2009-04-01

Original issue reported on code.google.com by senorsma...@gmail.com on 15 Apr 2009 at 9:37

GoogleCodeExporter commented 8 years ago
[Added to TVDB_Show.class.php]

    /**
     * Get a specific episode by air date php timestamp
     *
     * @var int $airDateTS required timestamp of Air Date
     * @return TV_Episode
     **/
    public function getEpisodeByAirDateTS($airDateTS) {
      return getEpisodeByAirDate(date("Y-m-d",$airDateTS));
    }

    /**
     * Get a specific episode by air date
     *
     * @var String $airDate required text of the air date 2009-04-15 or 15-04-2009,
or not certain all format supported by tvdb
     * @return TV_Episode
     **/
    public function getEpisodeByAirDate($airDate) {
      $params = array('action' => 'get_episode_by_air_date',
              'airDate' => $airDate,
              'show_id' => $this->id);

      $data = self::request($params);

      if ($data) {
        $xml = simplexml_load_string($data);
        return new TV_Episode($xml->Episode);
      } else {
        return false;
      }
    }

[Added to TVDB.Class.php request method]

        case 'get_episode_by_air_date':
          $airDate = $params['airDate'];
          $showId = $params['show_id'];
          $url =
self::apiUrl."/GetEpisodeByAirDate?apikey=".self::apiKey."&seriesid=".$showId."&
airdate=".$airDate;

          $data = self::fetchData($url);
          return $data;
        break;

Original comment by senorsma...@gmail.com on 18 Apr 2009 at 9:04

GoogleCodeExporter commented 8 years ago
In case it wasn't clear in my last comments.

I added that code to my copy, not to svn.

It will add support for GetEpisodeByAirDate

Original comment by senorsma...@gmail.com on 20 Apr 2009 at 8:18

GoogleCodeExporter commented 8 years ago
Here's a code change that handles not finding episodes by air dates better.

    /**
     * Get a specific episode by air date
     *
     * @var String $airDate required text of the air date 2009-04-15 or 15-04-2009,
or not certain all format supported by tvdb
     * @return TV_Episode
     **/
    public function getEpisodeByAirDate($airDate) {
      $params = array('action' => 'get_episode_by_air_date',
              'airDate' => $airDate,
              'show_id' => $this->id);

      $data = self::request($params);

      if ($data) {
        $xml = simplexml_load_string($data);
        if ($xml->Episode->id != "" ) {
                return new TV_Episode($xml->Episode);
        } else {
                return false;
        }
      } else {
        return false;
      }
    }

Original comment by senorsma...@gmail.com on 21 Apr 2009 at 7:00

GoogleCodeExporter commented 8 years ago
This will most likely go into 1.0.3, but getEpisodeByAirDate() will expect a 
UNIX
timestamp.

Original comment by ryan.doherty on 3 May 2009 at 8:32