repl.it
@Danfocus/

ElectricDependentBytes

Python

No description

fork
loading
Files
  • main.py
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
26
27
28
29
import configparser
import io
import json
from urllib.request import urlopen, Request

DI_FM_PREM_HI_URL = 'http://listen.di.fm/premium_high.json'
LISTEN_KEY = 'YOUR_LISTEN_KEY_HERE'


def main():
    resp = urlopen(Request(DI_FM_PREM_HI_URL)).read()
    stations = json.loads(resp.decode('utf-8'))
    stations_sorted = sorted(stations, key=lambda x: x['name'])
    with open('di_fm.m3u8', 'w') as f:
        f.write('#EXTM3U\r\n')
        f.write('#PLAYLIST:DI.FM\r\n')
        for station in stations_sorted:
            resp = urlopen(Request(station['playlist'])).read()
            config = configparser.ConfigParser()
            config.readfp(io.StringIO(resp.decode('utf-8')))
            if config.getint('playlist', 'NumberOfEntries') > 0:
                f.write('#EXTINF:-1,{}\r\n'.format(station['name']))
                f.write('{}?{}\r\n'.format(
                    config.get('playlist', 'File1'), LISTEN_KEY))


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