Login  |  Register
X
Username
Password
Forgot your password? 

Some switchers to EE have asked me whether I could update my MT Netflix Plugin to work with EE. The fact is, I just don't have the time to do that right. At least not right at the moment. But, I wanted to help out, and this kind of thing is so easy to do in Perl, that I kludged up a CGI script that you can call from PHP to check your Netflix Queue.

See my Netflix Queue Here. A thrill ain't it? That queue is the same as it was a year ago ... arrgghh ...

Oh, and this should work for any website using php, like WordPress.

Note 6/17/04: Paul has released a great php NetFlix Plugin for EE which does all this and more, with much greater convenience, needless to say!

Anyway, download Netflix.cgi, throw it in your cgi-bin directory, and chmod to 755. This script requires the LWP::UserAgent perl module, which you probably have, and the HTTP::Cookies module which you may or may not. Ask your host to install them if you don't, or use CPAN, or ask me about it.

Now you have to throw together a little php to call the script. You'll need your Netflix shopper ID #. After you've signed into your account, go to your cookies and find netflix. You'll see a 35 digit number beginning with "P". That's the one.

Okay, here's some php for your template:

<?php

$output = `/home/webadmin/ofhills.com/cgi-bin/netflix.cgi "PXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"`;
$explode = explode("%", $output);
$i = 0;
while ($i < count($explode)-1) {
$url = $explode[$i];
$title = $explode[$i +1];
$availability = $explode[$i +2];
$rating = $explode[$i +3];
$genre = $explode[$i +4];
$image = $explode[$i +5];
echo "<a href=\"",$url,"\"><img src = \"",$image,"\"border=\"0\"><br />",$title,"</a><br /><br />";
$i = $i+6;
}


?>

This will produce what I have in my link above. Note the "PXXXX..." stands for your ID number. The information is returned from Netflix and dumped into the $output variable as a list of 6 attributes for each flick -> url, title, availability, rating, genre, and an image of the movie. The last statement of that code just puts together a little clickable list, but you can use those values to output it any way you see fit.

Okay, there's a little problem. Do you really want to scrape Netflix every time someone hits your site? Nah. Waste of resources. I'm sure there's a better way to solve this than mine, but here's what I do. Put a blank text file named "netflix.dat" in your web directory somewhere, and chmod to 666. When you scrape netflix, you will write the results to that file. The next time someone hits yoru site, your php will check the file and if it hasn't been updated in a set amount of time (I use four days, but it could be a year for me - you should decide how often your queue changes and go with roughly that), the code re-scrapes, otherwise it just takes it from your file (much much faster).

Here's the modified php to do that ...

<?php
$myCheckInt = (60*60*24*4); //time between checking netflix = 4 days, in this case
$filename = "/path/to/mysite.com/html/blog/netflix.dat"; // put this empty file in directory, chmod 777
$file_last_modified = filemtime($filename);
$currentTime = time();
$f_pointer = fopen($filename, "r");
$f_read = fread($f_pointer, filesize($filename));
fclose($f_pointer);


if (($currentTime - $file_last_modified) > $myCheckInt || $f_read =="") {
$output = `/home/webadmin/ofhills.com/cgi-bin/netflix.cgi "PXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"`;
$f_pointer = fopen($filename, "w");
fwrite($f_pointer, $output);
fclose($f_pointer);
} else {
$output = $f_read;}


$explode = explode("%", $output);
$i = 0;
while ($i < count($explode)-1) {
$url = $explode[$i];
$title = $explode[$i +1];
$availability = $explode[$i +2];
$rating = $explode[$i +3];
$genre = $explode[$i +4];
$image = $explode[$i +5];
echo "<a href=\"",$url,"\"><img src = \"",$image,"\"border=\"0\"><br />",$title,"</a><br /><br />";
$i = $i+6;
}
?>

Well, that's it. I wish I had time to make this easier, but it will have to do for now, and it's better than no Netflix access. I welcome any input, and maybe one of these days, I'll get my other plugins ported over. The good news is you get a fair amount of data back, and you can use php to display it any way you wish. Hope you enjoy it!

Comments

8 Responses to Netflix Queue For Expression Engine
  1. Tony Garcia Says:

    forgot to post the link
    http://www.azulinteractive.com/blog/netflix/

    check it out

  2. tony Says:

    Thanks i got it working.. also did some tweaks to it. check it out

  3. Sara (Southern Gal) Says:

    Please don’t think I’m trying to rush you, Oscar, just asking. Have a good rest of the week, I’m on vacation tomorrow for a few days. It’s our wedding anniversary!

  4. Oscar Says:

    Hi Sara - Yes, I have been totally swamped with work as I gear up to go on vacation on Friday. If I get a little downtime on vacation, I will put all that code together, or else in August when things are generally quiet for me. It shouldn’t be at all difficult - it just requires a few uninterrupted hours to organize everything and create a reasonable interface. I will do my best to hurry it along ...

  5. Sara (Southern Gal) Says:

    Oscar, thank you for the code! I would like to split the queue from the movies I have out. I see that you had plans to work on that code last month…any progress?

    I have a page for my queue and would like to have the option of putting the movies I have on that page as well as having it on my sidebar through an include. Does that make sense?

    Thanks for everything!

  6. Mizidy Mizark Says:

    Thanks for the help, I am using WP so after looking at the EE script, I was a bit confused as to if I could apply that to WP or not.  Thanks for your help.

  7. Oscar Says:

    Yes, I haven’t bothered porting the Outstanding and History scripts over since the Expression Engine plugin does all that very nicely. But, I see that you are on WordPress which makes me think there is not a good plugin or script for that yet.

    Really, it should be done with PHP alone, as Paul did for EE, just for simplicity’s sake, but I have done it with the Perl scripts because I maintain them anyway for MT.

    When I get a chance later in the week, I will see if I can combine all three functions in one script. I hadn’t bothered because I didn;t think there was any interest, but it should be easy enough. I’ll post them here ...

  8. Mizidy Mizark Says:

    I was wondering if there was any way to show the list of movies currently out instead of the queue.  If not, that is cool, just thought I would ask.

  9. Page 1 of 1 pages






Tell us your thoughts...
And (as you probably know) if you want a pic to show with your comment, go get a gravatar!

Smilies

Please be kind enough to submit the word you see below:




Next entry: Content Reduced

Previous entry: ShoutBox Spam - Here's A Partial Fix