PHPTVDB: Using PHP to Retrieve TV Show Information
I'm a bigtime TV/movie buff. If it's ever seen the light of day on HBO or BBC America, I've seen it (and quite possibly filmed my own made-for-TV-short-film). Unfortunately IMDB doesn't provide an official API for movies and TV shows but thankfully TVDB does.
Retrieving information from TVDB is a breeze using a small library called PHPTVDB written by Ryan Doherty. With a little PHP knowledge and TVDB API key, you can easily grab data about any TV show.
The PHP
/* include the library */ require 'phptvdb-1.0.2/TVDB.php'; /* get the office! */ $shows = TV_Shows::search('The Office UK'); /* get the first show */ $show = $shows[0]; /* a few shortcuts / formatted vars */ $firstAired = date('l, F j, Y',$show->firstAired); $imdb_url = "http://imdb.com/title/$show->imdbId"; /* spit out the show information */ echo "<h2>$show->seriesName</h2> <div class=\"meta\"> <strong>Rating:</strong> $show->rating • <strong>Debuted:</strong> $firstAired on $show->network • <a href=\"$imdb_url\">$show->seriesName on IMDB</a> </div> <p>$show->overview</p>"; /* my favorite episode info */ $episode = $show->getEpisode(1,4); echo "<div class=\"righty\"> <h3>Favorite Episode: $episode->name</h3> <p>$episode->overview</p> </div>"; /* spit out the actors */ echo '<h3>The Cast</h3><ul>'; foreach($show->actors as $actor) { echo "<li>$actor</li>"; } echo '</ul><br />'; /* learn more link */ echo "<p><a href=\"http:/* imdb.com/title/\">Learn more about \"$imdb_url\" on IMDB</a></p>";
The above is just a sample usage of this great PHP library. You can find documentation here. Remember to try to be specific in your initial show search. I recommend going to IMDB or TVDB to get the show's "official" name to confirm you are being as specific as possible.
Awesome!
you know if exist a script can retrive information from freedb.org ?
Tnx
This is so cool Dave.
Hey, thanks for writing up a blog post about PHP::TVDB! I seem to have lost some pages about it and was using Google to see if they were still cached. That’s how I found this article.
Anyway, thanks, it’s nice to see that my code is useful!
This only gives me an empty page. Nothing is printed and the source is null.
It’s worth noting that this requires the php5-curl package which may not be installed by default.
A tidy post, just what I was after – thanks. :-)
Hey Dave, I know it’s an old post, but when I first checked it out a few months ago, everything seemed to work. I was able to use parts of the code and set it up in my own environment. Unfortunately, soon after, mine stopped working and upon returning to this page, it looks like your demo also stopped working – any idea why?