repl.it
@anonymous/

AntiqueExoticToolbox

Python

No description

fork
loading
Files
  • main.py
  • dfm_aac_96.m3u8
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 = 'https://dfm.ru/api/channel_list'


def main():
    resp = urlopen(Request(STATIONS_API_URL)).read()
    stations = json.loads(resp.decode('utf-8'))['items']
    with ioopen('dfm_aac_96.m3u8', 'w', encoding='utf-8') as f:
        f.write(u'#EXTM3U\r\n')
        f.write(u'#PLAYLIST:dfm.ru\r\n')
        for station in stations:
            f.write(u'#EXTINF:-1,{}\r\n'.format(station['name']))
            f.write(u'{}\r\n'.format(station['stream_url']))
    print("Generated playlist. Count of stations: ", len(stations))


if __name__ == '__main__':
    main()
Fetching token
?