Created
February 18, 2015 08:10
-
-
Save ajtucker/eae4c1914efb9ba09a17 to your computer and use it in GitHub Desktop.
Find URLs of BBC radio streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import cgi | |
from urllib2 import urlopen | |
from ConfigParser import ConfigParser | |
from StringIO import StringIO | |
form = cgi.FieldStorage() | |
stations = { | |
'radio1': '57286085', | |
'radio2': '57286086', | |
'radio3': '57874420', | |
'radio4': '57874419', | |
'radio4extra': '57874434', | |
'radio5live': '57874445', | |
'6music': '57286093' | |
} | |
if 'channel' in form and form['channel'].value in stations: | |
stationId = stations[form['channel'].value] | |
redirect = urlopen('http://stream.radiotime.com/listen.stream?streamId=' + stationId) | |
playlist = urlopen(redirect.geturl()).read() | |
print "Status: 302 Moved" | |
try: | |
config = ConfigParser() | |
config.readfp(StringIO(playlist)) | |
print "Location: %s" % config.get('playlist', 'file1') | |
except: | |
# assume it's just a single line with the URL | |
print "Location: %s" % playlist.strip() | |
else: | |
print "Status: 404" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment