The Netflix plugin that I first started using wasn’t all to feature-oriented. It basically took a Netflix RSS feed and dumped it without any processing or formatting. That is, if you wanted to display your activity queue, it just spit the 3 (or however many DVDs you can have out at one time) most recent discs shipped to you, and the most recent discs you returned. Plus, it didn’t have any way of displaying your rental queue.
Well, I didn’t think that was too cool, so I decided to hack away at it.
First, I modified it so that it would only show the discs most recently shipped to you. Then I realized that it might be cool, also, to show the discs you most recently returned. So I took the function and gave it some arguments — you can specify an “action” as “rented” and “returned.” Then I realized that you might want to see both in the same list, so I added an “activity” variable as well.
To that, I added the “queue” action which spit out your rental queue… Well, my queue has over 100 discs, so that was overkill, so I added the ability to limit (mine is current set at six, since that’s about as far ahead as I plan my queue).
After I finished all of that, I thought sometime in the future it might be nice to customize the way the list is presented (mainly, whether it should be an ordered list — <ol> — or an unordered list — <ul>), so I added arguments for those elements as well.
I’m not sure exactly how to go ahead and submit these modifications as a plugin, but I’ll look into that. For the time being, here is the code if anyone else uses WordPress and wants the functionality:
function mynetflix(
$action,
$listtag="ul",
$itemtag="li",
$count=10) {
global $activityurl;
global $queueurl;
switch ($action) {
case "rented" :
case "returned" :
case "activity" : {
$rss = fetch_rss($activityurl);
echo "<".$listtag.">\n";
foreach($rss->items as $item) {
$title = $item["title"];
$link = $item["link"];
$desc = $item["description"];
$parts = explode(":", $title, 2);
$act = trim($parts[0]);
$title = trim($parts[1]);
$parts = explode(".", $desc, 2);
$date = strip_tags(trim($parts[0]));
$a = "<".$itemtag.">\n";
$b = "</".$itemtag.">\n";
if($act == "Shipped" && $action == "rented")
echo wptexturize($a."<a href="".$link."">".
$title."</a> ".$date.$b);
else if($act == "Received" && $action == "returned")
echo wptexturize($a."<a href="".$link."">".
$title."</a> ".$date.$b);
else if($action == "activity")
echo wptexturize($a."<a href="".$link."">".
$title."</a> ".$date.$b);
}
echo "</".$listtag.">\n";
break;
}
case "queue" : {
$rss = fetch_rss($queueurl);
echo "<".$listtag.">\n";
$i=0;
foreach($rss->items as $item) {
if($i >= $count) break;
$parts = explode("-", $item["title"], 2);
$num = trim($parts[0]);
$title = trim($parts[1]);
$link = $item["link"];
echo "<".$itemtag." value="".$num."">\n";
echo wptexturize("<a href="".$link."">".$title."</a>");
echo "</".$itemtag.">\n";
$i++;
}
echo "</".$listtag.">\n";
break;
}
}
}
To use it, you define two varibles:
$activityurl = "look on your Netflix RSS page";
$queueurl = "look on your Netflix RSS page";
And call the function like:
<?php mynetflix('rented'); echo "\n"; ?>
or
<?php mynetflix('queue', 'ol', 'li', 6); echo "\n"; ?>
Magic! I love this stuff!
Update:
I really do impress myself 🙂 I just added some more functionality so that a page like My Entire Netflix Queue works… check it out. The biggest addition was the ability to show the description (which Netflix feeds in the RSS).