a HammerFlix update

[Sat, 10 Sep 2011 17:16:10 +0000]
Update, November 27, 2011: If you're looking for a live list of Hammer Films [] streaming on Netflix you can see it here []. To read more about the HammerFlicks project, click here []. ... Principal photography has begun on HammerFlix [] - a small project to use the Netflix API to discover which Hammer Films movies are available on Netflix's Watch Instantly. So far, I've got a PHP file that has two functions. The first one, named Igor, takes two arguments: a movie title and its release year. Igor then sends this to the Netflix API and retrieves only the first result for searching against that given title. Then Igor sends the XML version of the API results to another function, Master. Master, aka Dr. Frankenstein, then evaluates the result. If the Netflix release date for the movie returned by the API matches the year value sent to Igor, then Master will display the link to that movie on Netflix. If the movie is available via Watch Instantly, Master will also display the link to the streaming movie. If the year doesn't match, Master reports that no results were found. Testing against just the first match and using release year as the only qualifier might not be the best, but I think it might work pretty decently. If not, I'll have Igor retrieve more results and then Master can evaluate more results and use more test criteria before assuming the movie isn't on Netflix. The next step is to get all the Hammer titles from the Hammer Filmography [] on Wikipedia and send each title and release year to HammerFlix. There might be some open/linked data opportunities later down the road with dbPedia [], but that's not important for now. You can see this very basic test of HammerFlix 0.01 here []. Anyway, here's the code for the development version of 0.01. <?php //Igor does the hard work of hitting up the Netflix API for movies matching $title. //The code is mainly from: function Igor($title, $year) { include ('../authentication/myAPI.php'); //this includes my Netflix API key and shared secret as $apiKey and $sharedSecret. //build stuff to send to API. $arguments = Array( 'term' => $title, 'expand' => 'formats', 'max_results' => '1', 'output' => 'xml' ); $path = ""; $oauth = new OAuthSimple(); $signed = $oauth->sign(Array('path' => $path, 'parameters' => $arguments, 'signatures' => Array('consumer_key' => $apiKey, 'shared_secret' => $sharedSecret ))); //hit up API via CURL. $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $signed['signed_url']); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($curl, CURLOPT_SETTIMEOUT, 2); //Nitin commented this out on 2/5/2011 to prevent a PHP error message. $buffer = curl_exec($curl); if (curl_errno($curl)) { die("An error occurred:" . curl_error()); } Master($buffer, $title, $year); //send XML results to Master(). } //Master (Dr. Frankenstein) parses/returns the Netflix XML results retrieved by Igor. function Master($buffer, $title, $year) { $xml = simplexml_load_string($buffer); $movieInfo = ($xml->catalog_title); $short = "short"; $movieTitle_short = ($movieInfo->title->attributes()->$short); $regular = "regular"; $movieTitle_regular = ($movieInfo->title->attributes()->$regular); $movieLink = ($movieInfo->id); $movieId = str_replace("", "", $movieLink); $movieYear = ($movieInfo->release_year); //test if movie is available for Watch Instantly/streaming. $streaming = $xml->xpath('//availability/category/@label'); foreach ($streaming as $instantTest) { if ($instantTest == 'instant') { $streams = ''; } } //output findings. echo "<li><p>Testing:<em> " . $title . " </em>from the year:<em> " . $year . "</em><br />"; if ($movieYear == $year) { echo "<a href='" . $movieId . "'>" . $movieTitle_short . "</a>"; //IT'S ALIVE!!! //aka: show user the Watch Instantly link if it exists. if (isset($streams)) { echo "<br /><strong><a href='" . $movieId . "'>Watch Instantly</a></strong>"; } } else { echo "No match."; } echo "</p></li>"; } //Create life! //aka: start doing things. include ('../authentication/OAuthSimple.php'); echo "<ul>"; //put results in unordered list; send arguments to Igor(). Igor("The Brides of Dracula", "1960"); Igor("The Brides of Dracula", "1961"); Igor("Dracula Has Risen from the Grave", "1968"); Igor("Vampire Circus", "1972"); echo "</ul>"; ?>