15 Jul 2010 salimma   » (Apprentice)

iTunes feed extractor

The downside of Apple’s iPod/iPhone being so popular is that so many podcasts only publish iTunes links, instead of the more standard RSS/Atom feeds. And I know of OS X and Windows users who detest iTunes — imagine how Unix users feel!

Well, the feeds are still there, but hidden from plain sight — turns out, though, that if you pretend to be iTunes, you can actually trick the iTMS server into giving you the raw data. And with Python 2.6′s built-in support for Apple’s property lists, extracting the feed is a trivial matter.

#!/usr/bin/env python

import plistlib
import urllib2
import sys

ITUNES_VER = '7.4.1'

USER_AGENT = 'iTunes/' + ITUNES_VER

def get_props(url):
    request = urllib2.Request(url)
    request.add_header('User-Agent', USER_AGENT)
    response = urllib2.urlopen(request)
    return plistlib.readPlistFromString(response.read())

def get_feed(url):
    next_url = get_props(url)['action']['url']
    props = get_props(next_url)
    return props['items'][0]['feedURL']

if __name__ == '__main__':
    for url in sys.argv[1:]:
        print get_feed(url)

Syndicated 2010-07-15 01:59:18 from Intuitionistically Uncertain » Technology

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!