Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from io import open as ioopen
- import json
- try:
- from urllib2 import urlopen, Request
- except ImportError:
- from urllib.request import urlopen, Request
- STATIONS_API_URL = 'http://www.radiorecord.ru/radioapi/stations/'
- def main():
- resp = urlopen(Request(STATIONS_API_URL)).read()
- resp_dict = json.loads(resp.decode('utf-8'))
- stations = resp_dict['result']
- stations_sorted = sorted(stations, key=lambda x: x['title'])
- for bitrate in (32, 64, 128, 320):
- with ioopen('RadioRecord_st{}_{}.m3u8'.format(len(stations), bitrate), 'w', encoding='utf-8') as f:
- f.write(u'#EXTM3U\r\n')
- f.write(u'#PLAYLIST:Radio Record ({})\r\n'.format(bitrate))
- for station in stations_sorted:
- f.write(u'#EXTINF:-1,{}\r\n'.format(station['title']))
- f.write(u'{}\r\n'.format(station['stream_{}'.format(bitrate)]))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement