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:
[ruby]
require ‘rubygems’
require ‘json’
require ‘open-uri’
require ‘rss’
API_URL_BASE = “http://3voor12.vpro.nl/api/media/1/rest/”
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
end
def urn_to_url(urn)
urn_parts = urn.split(“:”)
“http://3voor12.vpro.nl/tv/\#/#{PLAYLIST_ID}/#{urn_parts[3]}”
end
# 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|
maker.channel.title = “3voor12tv :: #{playlist['group']['title']}”
maker.channel.description = playlist['group']['shortTitle']
maker.channel.about = “http://3voor12.vpro.nl/tv/”
maker.channel.link = “http://3voor12.vpro.nl/tv/”
# 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 = “http://images.vpro.nl/images/#{program['relatedImages']['relatedImage']['image']['@id']}+s(320)”
item.title = program['title']
item.description = (program['synopsis'] || program['title']) + “
”
item.link = urn_to_url(urn)
enclosure = maker.items.last.enclosure
enclosure.url = img_url
enclosure.length = -1
enclosure.type = “image/jpeg”
end
end
end
# write to disk
File.open(“3v12feed.xml”,”w”) do |f|
f.write(rss)
end
[/ruby]
I have a cronjob executing the script once in a while:
Can’t you also build this into 3VOOR12 for all those mere mortals out there?
Sure… but hey… you have a working checkout of 3voor12 on you workstation as well
Pingback: 3v12 api from Scala « log4p