PHPTVDB: Using PHP to Retrieve TV Show Information

By  on  
The Office (UK)

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.

Recent Features

  • By
    9 Mind-Blowing WebGL Demos

    As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us.  Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos.  Another technology available...

  • By
    6 Things You Didn&#8217;t Know About Firefox OS

    Firefox OS is all over the tech news and for good reason:  Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript.  Firefox OS has been rapidly improving...

Incredible Demos

  • By
    Facebook-Style Modal Box Using MooTools

    In my oh-so-humble opinion, Facebook's Modal box is the best modal box around. It's lightweight, subtle, and very stylish. I've taken Facebook's imagery and CSS and combined it with MooTools' awesome functionality to duplicate the effect. The Imagery Facebook uses a funky sprite for their modal...

  • By
    Dynamically Load Stylesheets Using MooTools 1.2

    Theming has become a big part of the Web 2.0 revolution. Luckily, so too has a higher regard for semantics and CSS standards. If you build your pages using good XHTML code, changing a CSS file can make your website look completely different.

Discussion

  1. francesco

    Awesome!
    you know if exist a script can retrive information from freedb.org ?
    Tnx

  2. This is so cool Dave.

  3. 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!

  4. Daniel Wall

    This only gives me an empty page. Nothing is printed and the source is null.

  5. Weasel

    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. :-)

  6. Kurt

    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?

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!