Backing Up a Podcast

Everything on the internet is there forever. Right? It depends on what you mean. If something makes it into the Internet Archive, I feel pretty confident it will be around for the duration of my lifetime. Yet, I\'m from a time right on the cusp on when permenance became a possibility. I can name many bands that were just a few years to early to appear on Youtube and get an album into iTunes. Those works are much more at risk of bitrot.

Similarly, there are a few things I sometimes worry about. I\'ve seen good podcasts unexpectedly end. When those podcasters fail to pay their hosting company, the files eventually get deleted and there\'s no way to retrieve it.

While I\'m not ready to start the Internet Archive for Podcasts, I do have a few shows that I\'m fond of and want to keep a copy of. I realized this evening that there were two I needed to backup for my own personal archive. Those are the Computational Complexity Cast with Lance Fortnow and Bill Gasarch. To any listeners or readers of Data Skeptic, my love of that show will seem rather obvious. The second show I want to backup is the Encounters Podcast with Richard Nelson. That might not seem like something I\'d obviously like, but I must confess I treasure this show and encourage you to check it out. If you don\'t understand why, email me, and we\'ll discuss.

The function below will make you a local backup.

import requests
import xmltodict
import os
def backup_podcast(url, dname):
    r = requests.get(url)
    rss = xmltodict.parse(r.content)
    items = rss['rss']['channel']['item']
    files = []
    for item in items:
        if 'link' in item:
            file = item['link']
        else:
            file = item['enclosure']['@url']
        files.append(file)
        i = len(files)
        for file in files:
            fname = dname + '/' + file[file.rfind('/')+1:]
            if not(os.path.isfile(fname)):
                r = requests.get(file)
                b = r.content
                f = open(fname, 'wb')
                f.write(b)
                f.close()
                i -= 1
dname = 'encounters'
url = 'http://feeds2.feedburner.com/EncountersNorth'
backup_podcast(url, dname)
dname = 'complexity'
url = 'http://oldblog.computationalcomplexity.org/podcast.xml'
backup_podcast(url, dname)