Podcast generation with PyRSS2gen

Here is a simple recursing podcast xml generator I wrote for http://gozu.co.nz

Install PyRSS2Gen with: sudo easy_install pyrss2gen

Then run it from the root of your recordings directory. It will add all the mp3s it finds in subdirectories to podcast.xml in each directory

import datetime
import PyRSS2Gen
import os

shows = []
for path, dirs, files in list(os.walk("."))[1:]:
    mp3s = []
    path = path[2:]
    for f in files:
        print "adding: %s/%s"%(path, f)
        mp3s.append(path +"/" + f)
    shows.append([path, mp3s])

splitfile = lambda x: tuple(x.rsplit(".mp3")[0].split("/")[1].split("-"))

for path, mp3s in shows:
    rss = PyRSS2Gen.RSS2(
        title = "gozu.co.nz: recordings/%s"%path,
        link = "http://gozu.co.nz/recordings/%s"%path,
        description = "%s Recordings from boosh.fm"%path,
        lastBuildDate = datetime.datetime.now(),

        items = [
             title = "%s live stream %s/%s/%s"%splitfile(x),
             link = "http://www.gozu.co.nz/recordings/",
             description = "Another awesome show by %s"%splitfile(x)[0],
             pubDate = datetime.datetime.fromtimestamp(os.path.getmtime(x)),
             enclosure = PyRSS2Gen.Enclosure("http://www.gozu.co.nz/recordings/%s"%x, os.path.getsize(x),"audio/mpeg"),
             categories = [PyRSS2Gen.Category("Awesome")],
             guid = PyRSS2Gen.Guid("http://www.gozu.co.nz/recordings/"+ x)) for x in mp3s

    rss.write_xml(open("%s/podcast.xml"%path, "w"))