-
-
Save nicksnell/a88a492b5896e1670e32 to your computer and use it in GitHub Desktop.
Command line tool to get the radio station urls...
This file contains hidden or 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 sys | |
from urllib2 import urlopen | |
from ConfigParser import ConfigParser | |
from StringIO import StringIO | |
stations = { | |
'radio1': '57286085', | |
'radio2': '57286086', | |
'radio3': '57874420', | |
'radio4': '57874419', | |
'radio4extra': '57874434', | |
'radio5live': '57874445', | |
'6music': '57286093' | |
} | |
def get_station_url(station): | |
stationId = stations[station] | |
redirect = urlopen('http://stream.radiotime.com/listen.stream?streamId=' + stationId) | |
playlist = urlopen(redirect.geturl()).read() | |
try: | |
config = ConfigParser() | |
config.readfp(StringIO(playlist)) | |
print config.get('playlist', 'file1') | |
except: | |
# assume it's just a single line with the URL | |
print playlist.strip() | |
if __name__ == '__main__': | |
if not len(sys.argv) > 1: | |
print 'Enter a station... %s' % ','.join(stations.keys()) | |
get_station_url(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment