Welcome to Geeklog, Anonymous Wednesday, November 27 2024 @ 01:31 am EST
Geeklog Forums
NetFlix via RSS in a StaticPage
Status: offline
mst3kroqs
Forum User
Regular Poster
Registered: 10/18/05
Posts: 78
Location:Cary, NC USA
Greetings -
Once in awhile, I realize that something I knocked together for myself might be useful to others.
I've seen a few posts recently asking how to display RSS feeds in staticpages - this might prove to be a useful example for you. This staticpage allows you to view your NetFlix account queue and recent activity, as well as a few other reports/lists that NetFlix publishes via RSS.
As a prerequisite, you'll need MagPieRSS, which is a (somewhat dated) RSS parser package that I'm fond of. GeekLog has it's own classes, of course, but I haven't taken the time to figure out how to use them. Maybe I'll harass Michael Jervis one of these days (grin).
You can retrieve MagPieRSS from: http://magpierss.sourceforge.net. I chose to untar it in my GeekLog system directory, which creates a 'magpierss-0.72' directory.
Now let's make the PHP staticpage:
global $_CONF;
$spurl = $_CONF['site_url'] . "/staticpages/index.php"; // you shouldn't have to change this
// you need the magpie rss class to make this work. you can retrieve the latest version (0.72)
// as of this writing from: http://magpierss.sourceforge.net. it doesn't matter where you put the
// package, the path below reflects my choice - which was to unzip it to my geeklog system directory
require_once $_CONF['path'] . "system/magpierss-0.72/rss_fetch.inc";
// user/site-specific config
$spid = "netflix"; // must match staticpage id (not title)
$nfid = "P0123456789012345678901234567890123"; // your netflix userid (see notes below)
$qmax = 20; // max queue to display
$nmax = 40; // max new releases to display
// note: to find your netflix userid (nfid above), login to netflix, scroll to the bottom of the page,
// and click 'RSS'. Under 'Personalized Feeds', you will see your id appended to the Queue, Most
// Recent Rental Activity, and Movies At Home links as id=P<series of 34 decimal digits>. Your netflix
// userid is unique to you, the $nfid above is set to a dummy value.
// don't forget to put the logo image in your /images directory. feel free to retrieve the .png from
// my site if you like: http://www.the-howards.net/images/netflix-logo.png. the netflix logo is
// copyright and a trademark of netflix, i'm sure.
$retval = "<p><a href=\"http://www.netflix.com\"><img width=\"124\" height=\"66\" align=\"right\" src=\"/images/netflix-logo.png\" alt=\"www.netflix.com\" /></a>";
$rpt = $_GET['rpt'];
switch ($rpt) {
// Recent Activity
case "recent":
$retval .= "<b>Recent Activity</b></p>";
$rss = fetch_rss("http://rss.netflix.com/TrackingRSS?id={$nfid}");
if (count($rss->items) > 0) {
$retval .= "<ul>";
foreach ($rss->items as $item) {
$title = stripslashes($item['title']);
$retval .= "<li><a href=\"{$item['link'] }\">{$title}</a><br>\n";
}
$retval .= "</ul>";
}
$retval .= "View: [ " ."At Home/In Queue" ." | New Releases" ." | Recommendations" ." | Top25 Sci-Fi" ." ]<br><br>\n";
break;
// New Releases
case "new":
$retval .= "<b>New Releases</b></p>";
$rss = fetch_rss("http://rss.netflix.com/NewReleasesRSS");
$n = count($rss->items);
if ($n > 0) {
$retval .= "<ul>";
if ($n > $nmax) $n = $nmax;
for ($i = 0; $i < $n; $i++) {
$title = stripslashes($rss->items[$i]['title']);
$link = $rss->items[$i]['link'];
$retval .= "<li><a href=\"{$link}\">{$title}</a><br>\n";
}
$retval .="</ul>";
}
$retval .= "View: [ " ."At Home/In Queue" ." | Recent Activity" ." | Recommendations" ." | Top25 Sci-Fi" ." ]<br><br>\n";
break;
// Recommendations
case "recommend":
$retval .= "<b>Recommendations</b></p>";
$rss = fetch_rss("http://rss.netflix.com/RecommendationsRSS?id={$nfid}");
if (count($rss->items) > 0) {
$retval .= "<ul>";
foreach ($rss->items as $item) {
$title = stripslashes($item['title']);
$retval .= "<li><a href=\"{$item['link'] }\">{$title}</a><br>\n";
}
$retval .= "</ul>";
}
$retval .= "View: [ " ."At Home/In Queue" ." | Recent Activity" ." | New Releases" ." | Top25 Sci-Fi" ." ]<br><br>\n";
break;
// Top25 Sci-Fi
case "scifi":
$retval .= "<b>Top 25 Sci-Fi</b></p>";
$rss = fetch_rss("http://rss.netflix.com/Top25RSS?gid=373");
if (count($rss->items) > 0) {
$retval .= "<ol>";
foreach ($rss->items as $item) {
$title = stripslashes($item['title']);
$retval .= "<li><a href=\"{$item['link'] }\">{$title}</a><br>\n";
}
$retval .= "</ol>";
}
$retval .= "View: [ " ."At Home/In Queue" ." | Recent Activity" ." | New Releases" ." | Recommendations" ." ]<br><br>\n";
break;
// Default NetFlix Report Screen
default:
$retval .= "<b>Movies at Home</b> [ Recent Rental Activity ]</p>";
$rss = fetch_rss("http://rss.netflix.com/AtHomeRSS?id={$nfid}");
if (count($rss->items) > 0) {
$retval .= "<ul>";
foreach ($rss->items as $item) {
$title = stripslashes($item['title']);
$retval .= "<li><a href=\"{$item['link'] }\">{$title}</a><br>\n";
}
$retval .="</ul>";
}
$retval .= "<b>Movies in the Queue</b> [ Visit Queue ]<br>";
$rss = fetch_rss("http://rss.netflix.com/QueueRSS?id={$nfid}");
$n = count($rss->items);
if ($n > 0) {
$retval .= "<ul>";
if ($n > $qmax) $n = $qmax;
for ($i = 0; $i < $n; $i++) {
$title = stripslashes($rss->items[$i]['title']);
$link = $rss->items[$i]['link'];
$retval .= "<li><a href=\"{$link}\">{$title}</a><br>\n";
}
$retval .="</ul>";
}
$retval .= "View: [ " ."Recent Activity" ." | New Releases" ." | Recommendations" ." | Top25 Sci-Fi" ." ]<br><br>\n";
}
Note that based upon my testing with the GeekLog 1.5.0 beta, you may have to add the following to the end of this script to get it to work with 1.5.0:
return $retval;
In GL 1.4.1, this does not seem to be necessary, and in fact it causes the rendered page content to be duplicated for some odd reason.
The script is easily customized - you may want to add other reports and/or TopN reports.
Have fun!
-m
- Make sure that you have enabled PHP execution for staticpages, eg: http://www.geeklog.net/docs/staticpages.html#php
- Create a static page. I used the title "NetFlix Report", but it's arbitrary.
- Add it to your Site Menu if you like.
- Change the ID: to 'netflix'. This has to match a config value in the script below.
- Cut/paste the code below into the staticpage content window.
- Check 'Wrap Static Page in a block'.
- Set the PHP option to 'execute PHP (return)'.
- Set the access rights appropriately (you probably don't want anonymous users or perhaps even members seeing/using the script.
- Save, but don't run it yet.
- Edit the staticpage content again, and read the comments at the top of the script.
- Retrieve and install the logo and place it in your /images directory.
- You're going to need to determine what your user-specific ID is for NetFlix - the instructions are in the file. Edit the config value(s) accordingly.
- Note that the $spid value must match the staticpage ID (default:netflix) you chose above!
- Save!
Text Formatted Code
global $_CONF;
$spurl = $_CONF['site_url'] . "/staticpages/index.php"; // you shouldn't have to change this
// you need the magpie rss class to make this work. you can retrieve the latest version (0.72)
// as of this writing from: http://magpierss.sourceforge.net. it doesn't matter where you put the
// package, the path below reflects my choice - which was to unzip it to my geeklog system directory
require_once $_CONF['path'] . "system/magpierss-0.72/rss_fetch.inc";
// user/site-specific config
$spid = "netflix"; // must match staticpage id (not title)
$nfid = "P0123456789012345678901234567890123"; // your netflix userid (see notes below)
$qmax = 20; // max queue to display
$nmax = 40; // max new releases to display
// note: to find your netflix userid (nfid above), login to netflix, scroll to the bottom of the page,
// and click 'RSS'. Under 'Personalized Feeds', you will see your id appended to the Queue, Most
// Recent Rental Activity, and Movies At Home links as id=P<series of 34 decimal digits>. Your netflix
// userid is unique to you, the $nfid above is set to a dummy value.
// don't forget to put the logo image in your /images directory. feel free to retrieve the .png from
// my site if you like: http://www.the-howards.net/images/netflix-logo.png. the netflix logo is
// copyright and a trademark of netflix, i'm sure.
$retval = "<p><a href=\"http://www.netflix.com\"><img width=\"124\" height=\"66\" align=\"right\" src=\"/images/netflix-logo.png\" alt=\"www.netflix.com\" /></a>";
$rpt = $_GET['rpt'];
switch ($rpt) {
// Recent Activity
case "recent":
$retval .= "<b>Recent Activity</b></p>";
$rss = fetch_rss("http://rss.netflix.com/TrackingRSS?id={$nfid}");
if (count($rss->items) > 0) {
$retval .= "<ul>";
foreach ($rss->items as $item) {
$title = stripslashes($item['title']);
$retval .= "<li><a href=\"{$item['link'] }\">{$title}</a><br>\n";
}
$retval .= "</ul>";
}
$retval .= "View: [ " ."At Home/In Queue" ." | New Releases" ." | Recommendations" ." | Top25 Sci-Fi" ." ]<br><br>\n";
break;
// New Releases
case "new":
$retval .= "<b>New Releases</b></p>";
$rss = fetch_rss("http://rss.netflix.com/NewReleasesRSS");
$n = count($rss->items);
if ($n > 0) {
$retval .= "<ul>";
if ($n > $nmax) $n = $nmax;
for ($i = 0; $i < $n; $i++) {
$title = stripslashes($rss->items[$i]['title']);
$link = $rss->items[$i]['link'];
$retval .= "<li><a href=\"{$link}\">{$title}</a><br>\n";
}
$retval .="</ul>";
}
$retval .= "View: [ " ."At Home/In Queue" ." | Recent Activity" ." | Recommendations" ." | Top25 Sci-Fi" ." ]<br><br>\n";
break;
// Recommendations
case "recommend":
$retval .= "<b>Recommendations</b></p>";
$rss = fetch_rss("http://rss.netflix.com/RecommendationsRSS?id={$nfid}");
if (count($rss->items) > 0) {
$retval .= "<ul>";
foreach ($rss->items as $item) {
$title = stripslashes($item['title']);
$retval .= "<li><a href=\"{$item['link'] }\">{$title}</a><br>\n";
}
$retval .= "</ul>";
}
$retval .= "View: [ " ."At Home/In Queue" ." | Recent Activity" ." | New Releases" ." | Top25 Sci-Fi" ." ]<br><br>\n";
break;
// Top25 Sci-Fi
case "scifi":
$retval .= "<b>Top 25 Sci-Fi</b></p>";
$rss = fetch_rss("http://rss.netflix.com/Top25RSS?gid=373");
if (count($rss->items) > 0) {
$retval .= "<ol>";
foreach ($rss->items as $item) {
$title = stripslashes($item['title']);
$retval .= "<li><a href=\"{$item['link'] }\">{$title}</a><br>\n";
}
$retval .= "</ol>";
}
$retval .= "View: [ " ."At Home/In Queue" ." | Recent Activity" ." | New Releases" ." | Recommendations" ." ]<br><br>\n";
break;
// Default NetFlix Report Screen
default:
$retval .= "<b>Movies at Home</b> [ Recent Rental Activity ]</p>";
$rss = fetch_rss("http://rss.netflix.com/AtHomeRSS?id={$nfid}");
if (count($rss->items) > 0) {
$retval .= "<ul>";
foreach ($rss->items as $item) {
$title = stripslashes($item['title']);
$retval .= "<li><a href=\"{$item['link'] }\">{$title}</a><br>\n";
}
$retval .="</ul>";
}
$retval .= "<b>Movies in the Queue</b> [ Visit Queue ]<br>";
$rss = fetch_rss("http://rss.netflix.com/QueueRSS?id={$nfid}");
$n = count($rss->items);
if ($n > 0) {
$retval .= "<ul>";
if ($n > $qmax) $n = $qmax;
for ($i = 0; $i < $n; $i++) {
$title = stripslashes($rss->items[$i]['title']);
$link = $rss->items[$i]['link'];
$retval .= "<li><a href=\"{$link}\">{$title}</a><br>\n";
}
$retval .="</ul>";
}
$retval .= "View: [ " ."Recent Activity" ." | New Releases" ." | Recommendations" ." | Top25 Sci-Fi" ." ]<br><br>\n";
}
9
7
Quote
Status: offline
mst3kroqs
Forum User
Regular Poster
Registered: 10/18/05
Posts: 78
Location:Cary, NC USA
A BlockBuster version can be found in this post.
Enjoy!
8
13
Quote
All times are EST. The time is now 01:31 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content