I am BARRY HESS > Blog

Exporting Your Netflix Queue With Ruby

I have been with Netflix for over seven years now. Or I should say, I had been up until last Friday. Ultimately, it came down to none of us having enough time to actually watch DVDs from Netflix. When time was available to view films, we either needed to kowtow to The Kid’s viewability needs (she’s only 3, after all) or else we had such a large pool of movies we haven’t seen that larger immediate choice became key.

The decision boiled down to either increasing the size of our Netflix commitment to allow us to break up our account into three separate queues (one for me, one for The Wife and one for The Kid) or simply eliminating the thing entirely. We chose the latter.

As you can imagine, I had a significant queue built up; 345 DVDs to be precise. I just couldn’t delete that queue. I don’t know if Netflix will reinstate it upon my eventual return? Or will they obliterate it and make me rebuild it? In any case, I’d like to have the option to revisit that original queue, culled over seven glorious years of membership. (I found the answer after canceling - they retain your queue for 2 years.)

Ruby and REXML to the rescue!

First, I saved my queue RSS feed (that link should work if you have an account) to my local machine. The feed looks something like this:

    <title>Netflix Queue</title>
    <description>DVDs in your Netflix Queue</description>
      <title>1- The Good Shepherd</title>
        Matt Damon and Robert De Niro (who also directs) star in this partially fact-based drama that examines the early history of the CIA as seen through the eyes of a dedicated agent. An upstanding, sharp-minded Yale student, Edward Wilson (Damon) is recruited to work for the fledgling CIA during World War II. Though loyal to his country, Wilson begins to feel the job eroding his ideals, filling him with distrust and destroying his personal life.
      <title>2- Deja Vu</title>
        Deja vu -- that powerful but fleeting sense that you've been here, or met someone, before. ATF agent Doug Carlin (Denzel Washington) finds himself dogged by that feeling as he investigates a bombing on a New Orleans ferry. Should he shrug off the unsettling sensation, or can it help him unravel the clues he needs to save hundreds of innocent people from disaster? Directed by Tony Scott, this thriller also stars James Caviezel and Val Kilmer.
  . . .

The next task, assuming you have Ruby installed on your machine (you do own a Mac, right?), is to create the code to process your downloaded queue XML document. I created a new text file and saved it in the same directory as my XML file sits, calling it “parse-netflix-titles.rb”.

The code is quite simple.

require 'rexml/document'
include REXML
doc = Document.new(File.new("QueueRSS.xml"))
root = doc.root
aFile = File.new("netflix-queue-titles.txt", 'w')
root.each_element('channel/item') { |item|

Assuming you didn’t change the default name of the XML file, this should output a file called “netflix-queue-titles.txt” to the same directory as the XML file. There’s one downside, however. Each title is prefixed with a number representing its order in the queue. I didn’t care, but I’m sure someone with regular expression skills could eliminate that rather quickly.