Disappearing Netflix plugin images

I’m a huge fan of Netflix: it’s great for catching old and new movies I’ve missed or love, and for catching up on entire seasons of TV shows (it’s how I became addicted to Battlestar Galactica, for example).

I list the three DVDs I have at home right here on my blog; it’s one way you can see what kind of odd taste I sometimes have in movies. I use a pair of WordPress plugins to generate the list, and sometimes the cover images sometimes don’t show up. I figured out how to fix this; hopefully you’ll find it helpful.

The first plugin is called, curiously, “WordPress Netflix Plugin“. This gives the basic functionality: grabbing the raw Netflix datastream, parsing it and displaying the images and such.

The second turns the first into a WordPress Widget for easier display on my blog. It’s called Netflix Widget. Where do they get those wonderful names?

Netflix Image Not Found What’s particularly frustrating about the cover images sometimes not showing up is the “sometimes” part: One day the correct images will show up, and the next, they’re gone, with no changes on my part. Instead, I’d see an “Image Not Available” graphic.

This is so much of a problem that even the authors of the two plugins that provide this great feature both have missing images on their blogs. That’s what I call irony!

I posted a comment to the WordPress Netflix Plugin’s author’s page asking for help, and then decided to figure it out myself. After all, it’s just PHP, and the code is open for access.

It only took about 15 minutes to figure out the problem. Whether my solution is the right one is up for debate, but here’s what I found.

The plugin relies on your personal Netflix RSS feed. You can see your queue (mine—which I use NetFlix Freak to manage; totally worth the $15—is currently 165 items deep); the movies you have at home, recommendations from Netflix, and more.

The Movies at Home RSS feed has a link entry that points to the DVD, along with its numerical ID (the “movie ID”). For example, the Monty Python and the Holy Grail entry looks like this:

<link>
http://www.netflix.com/Movie/Monty_Python_and_the_Holy_Grail/771476
</link>

The number at the end (771476) is this movie’s unique ID in Netflix’s database.

The plugin code grabs the RSS fed, breaks it out into various pieces, including that link, grabs the movie id, and sticks it into a known URL format.

Here’s how the movie id ($movie_id, in the code) is used:

$display = '<img src="http://cdn.nflximg.com/us/boxshots/' .
   $image_size . '/' . $movie_id . '.jpg" 
   alt="' . $title . '" title="' . $title . '" />';

And heres how the code figures out the movie id:

$link = $item['link'];
if (preg_match("#/(\d+)\?trkid=(\d+)#", $link, $matches)) {
    $movie_id = $matches[1];
} 

This should generate a URL that looks like:

http://cdn.nflximg.com/us/boxshots/large/771476.jpg

But instead generates a URL that looks like:

http://cdn.nflximg.com/us/boxshots/large/.jpg

Lookie there, no movie id! If you look back at the link entry earlier, you may already know the problem and the solution. The problem is the link entry doesn’t have a trkid section.

The code is looking for a URL formated like this:

http://www.netflix.com/Movie/Monty_Python_and_the_Holy_Grail?trkid=771476

But is getting one formatted like this:

http://www.netflix.com/Movie/Monty_Python_and_the_Holy_Grail/771476

Even though the code doesn’t use the trkid, it’s assuming its there. Since it’s not, the $movie_id ends up blank. Netflix must have changed this because this code used to work perfectly.

The easiest way to “fix” this is to remove the part of the code that is looking for trkid. Instead of

if (preg_match("#/(\d+)\?trkid=(\d+)#", $link, $matches)) {

use

if (preg_match("#/(\d+)#", $link, $matches)) {

If you have version 3.0 of the plugin, you can simply find the first line and replace it with the second. Disclaimer: this change works for me using version 3.0 of WordPress Netflix Plugin under WordPress 2.2.1. Your milage may vary.

I’m sure the author will release a version of his plugin that handles both formats from Netflix (my next stop is to add that into my own version; it should be a simple either/or), but in the meantime, my Netflix images are back on my blog, and that makes me smile.

Update: The developer has updated his plugin. Go get it now!

Technorati Tags: , , ,

One thought on “Disappearing Netflix plugin images”

Comments are closed.