SHARE
TWEET

RadioRecord playlist generator

Danfocus Jun 15th, 2018 365 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from io import open as ioopen
  2. import json
  3.  
  4. try:
  5.     from urllib2 import urlopen, Request
  6. except ImportError:
  7.     from urllib.request import urlopen, Request
  8.  
  9. STATIONS_API_URL = 'http://www.radiorecord.ru/radioapi/stations/'
  10.  
  11.  
  12. def main():
  13.     resp = urlopen(Request(STATIONS_API_URL)).read()
  14.     resp_dict = json.loads(resp.decode('utf-8'))
  15.     stations = resp_dict['result']
  16.     stations_sorted = sorted(stations, key=lambda x: x['title'])
  17.     for bitrate in (32, 64, 128, 320):
  18.         with ioopen('RadioRecord_st{}_{}.m3u8'.format(len(stations), bitrate), 'w', encoding='utf-8') as f:
  19.             f.write(u'#EXTM3U\r\n')
  20.             f.write(u'#PLAYLIST:Radio Record ({})\r\n'.format(bitrate))
  21.             for station in stations_sorted:
  22.                 f.write(u'#EXTINF:-1,{}\r\n'.format(station['title']))
  23.                 f.write(u'{}\r\n'.format(station['stream_{}'.format(bitrate)]))
  24.  
  25.  
  26. if __name__ == '__main__':
  27.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top