Skip to content

Instantly share code, notes, and snippets.

@derrod
Created January 21, 2017 22:02
Show Gist options
  • Save derrod/fab840d0cd2be74d1d70b965749b132d to your computer and use it in GitHub Desktop.
Save derrod/fab840d0cd2be74d1d70b965749b132d to your computer and use it in GitHub Desktop.
Creates .pls playlist for NRJ (ENERGY) radio stations
#!/usr/bin/env python2.7
import json
import urllib2
locale = 'de'
url = 'http://players.nrjaudio.fm/wr_api/live/%s?ver=2&fmt=json&act=get_setup&id_radio=1&cp=utf8&id_sysos=2' % locale
r = urllib2.urlopen(url)
j = json.loads(r.read())
playlist = ["[playlist]",
"NumberOfEntries=%d" % len(j['webradios'])]
for counter, channel in enumerate(sorted(j['webradios'], key=lambda a: a['name']), start=1):
name = channel['name'].strip()
# Use highest quality stream available
listenurl = ""
if channel['url_hd_aac']:
listenurl = channel['url_hd_aac']
elif channel['url_128k_mp3']:
listenurl = channel['url_128k_mp3']
elif channel['url_64k_aac']:
listenurl = channel['url_64k_aac']
print "Channel %02d:" % counter, name
playlist.append("File{num:d}={url}".format(num=counter, url=listenurl))
playlist.append("Title{num:d}={name}".format(num=counter, name=name))
playlist.append("Length{num:d}=-1".format(num=counter))
with open('nrj.pls', 'w') as f:
f.write("\n".join(playlist))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment