/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env python """ Create a SMIL file of all the full tracks from this week's All Songs Considered (http://www.npr.org/programs/asc/). """ import re import sys import urllib2 from BeautifulSoup import BeautifulSoup RA_URL = "rtsp://real.npr.org:80/real.npr.na-central/%s.rm" def allsongsallsongs(url): smil = ["<smil>", "<body>"] soup = BeautifulSoup(urllib2.urlopen(url)) for songlink in soup.findAll("a", {"href" : re.compile("getStaticMedia")})[1:]: rafile = RA_URL % songlink["href"].split("'")[1] smil.append("<audio src='%s' />" % rafile) smil.extend(["</body>", "</smil>"]) return "\n".join(smil) if __name__ == '__main__': if len(sys.argv) > 1: url = sys.argv[1] else: url = "http://www.npr.org/programs/asc/" print allsongsallsongs(url)