Saturday, 24 November 2012

I Hate ITunes

I hate iTunes. I quite intensely dislike most apple products but ITunes especially. I find myself writing this because of the enormous lengths I had to go to this evening to try and download a podcast. I'd heard advertised on the radio the latest XFM breakfast show podcast with Danny Wallace starring some of my favourite comedians. I found the link and ended up at a holding page on the iTunes website informing me that I should download it before I could listen. Surely not I thought... a podcast at the end of the day is usually just and MP3 and there must be and RSS/Atom feed somewhere that I can just download it from. Apparently not.

It turns out that I've had this problem before and it's only now that this hunt begins again that I remember going through these same steps a few years ago and coming to the same conclusion. Last time I think it was for the first series of Robin Ince and Josie Long's Utter Shambles podcast and whilst the later series had standard download links, the first series seemed tied to iTunes. I managed to find a python script that extracted the feed URL by pretending to be iTunes and accessing the site that way and it was still sitting on my desktop so I gave that a go.

More wishful thinking... it didn't work. A bit of digging around lead me to find that the version of iTunes I was trying to impersonate was a bit out of date so I changed version 7 to the newest version, 10.6.4. The result was worse, from what I understand, the script was previously retrieving something in a pList format (I don't really know what this is) but now it was unable to parse the response so clearly it was now something else. I decided to dump the response to a file to discover that it had actually returned exactly what I wanted. It was basically a HTML page with all the information needed to display the result in iTunes presumably.

A quick scan of the output and I had struck gold. A link with a "feed-url" attribute that didn't point to an iTunes site! Bingo, pasting that into my browser I was presented with a feed of all the podcasts with links to download the MP3. Why couldn't they just offer that in the first place! OK, there are probably plenty of reasons, firstly that most people aren't nearly as determined as I am to avoid downloading it but there are plenty of people out there who don't use Windows / Macs and have no choice short of using Wine and there's no guarantee that will work.

So, in case anyone out there is having the same problems as me, here's the code I used - it should be fairly trivial to covert it to the language of your choosing but the original script was in python so that's how it stayed.

import urllib2
import sys
import re

ITUNES_VER = '10.6.4'
USER_AGENT = 'iTunes/' + ITUNES_VER
FEED_URL_RE = re.compile( 'item-name="([^"]+).*feed-url="([^"]+)"' );

def get_feeds(url):
    request = urllib2.Request(url)
    request.add_header('User-Agent', USER_AGENT)
    response = urllib2.urlopen(request)
    
    feedsDict = {}
    m = FEED_URL_RE.findall(response.read())
    if m:
        for match in m:
            feedsDict[match[0]] = match[1]
            
    return feedsDict
    
url = "https://itunes.apple.com/gb/podcast/the-xfm-breakfast-show-danny/id279213645"

feeds = get_feeds(url)
for feed in feeds:
    print feed + " - " + feeds[feed]

You will need to change the URL to point to whatever podcast you're trying to download and presumably bump up the version number in line with the releases.

Happy listening!

No comments:

Post a Comment