Using the 3voor12 api to get an RSS feed of your favorite playlist

A couple of months ago we developed 3voor12TV. During festivals like Noorderslag, Pinkpop and (upcoming) Lowlands the 3voor12 crew tries to get as much high quality (h264) material online in the shortest time possible.

The application was developed in actionscript 3.0 on top of a public API. Well, it is public… but no public documentation yet. Sorry ;-) The 3voor12 Pinkpop mashup was the first real utilization of the API.

Whilst waiting for the new video’s I found myself refreshing the player over and over again; checking for new content.

I decided to automate this using the API. The Ruby script below uses the API to create a simple RSS feed with images and a direct link to each concert:

require ‘rubygems’
require ‘json’
require ‘open-uri’
require ‘rss’

PLAYLIST_ID = “41129661″

# function to convert urn to urls
def urn_to_api_url(urn)
urn_parts = urn.split(“:”) # urn contains source, entity type and unique number
“#{API_URL_BASE}#{urn_parts[2]}/#{urn_parts[3]}.json” # bypass content negotiation, force json formatted responses

def urn_to_url(urn)
urn_parts = urn.split(“:”)

# retrieve and parse a playlist (group)
playlist = JSON.load(open(“#{API_URL_BASE}group/#{PLAYLIST_ID}.json”))
# extract the playlist items
programUrns = playlist['group']['members']['member'].map{|m| m['media']['@urn']}

# create playlist
rss = RSS::Maker.make(“2.0″) do |maker| = “3voor12tv :: #{playlist['group']['title']}” = playlist['group']['shortTitle'] = “” = “”
# retrieve the playlist items
programUrns[0..15].each do |urn|
maker.items.new_item do |item|
program = JSON.load(open(urn_to_api_url(urn)))['program']
img_url = “{program['relatedImages']['relatedImage']['image']['@id']}+s(320)”

item.title = program['title']
item.description = (program['synopsis'] || program['title']) + “ = urn_to_url(urn)

enclosure = maker.items.last.enclosure
enclosure.url = img_url
enclosure.length = -1
enclosure.type = “image/jpeg”

# write to disk“3v12feed.xml”,”w”) do |f|

I have a cronjob executing the script once in a while:

This entry was posted in 3voor12, api, ruby. Bookmark the permalink.

3 Responses to Using the 3voor12 api to get an RSS feed of your favorite playlist

  1. Can’t you also build this into 3VOOR12 for all those mere mortals out there?

  2. peter says:

    Sure… but hey… you have a working checkout of 3voor12 on you workstation as well ;)

  3. Pingback: 3v12 api from Scala « log4p

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>