repl.it
@Danfocus/

PrivateWelltodoMode

Python

No description

fork
loading
Files
  • main.py
  • calmradio_free.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
26
27
28
29
from io import open as ioopen
import json

try:
    from urllib2 import urlopen, Request
except ImportError:
    from urllib.request import urlopen, Request

CHANNELS_API_URL = 'https://api.calmradio.com/v2/channels.json'


def main():
    resp = urlopen(Request(CHANNELS_API_URL)).read()
    channels = json.loads(resp.decode('utf-8'))['channels']
    channels_sorted = sorted(channels, key=lambda x: x['title'].lower())
    count = 0
    with ioopen('calmradio_free.m3u8', 'w', encoding='utf-8') as f:
        f.write(u'#EXTM3U\r\n')
        f.write(u'#PLAYLIST:calmradio_free\r\n')
        for channel in channels_sorted:
            if channel['free']:
                count += 1
                f.write(u'#EXTINF:-1,{}\r\n'.format(channel['title']))
                f.write(u'{}\r\n'.format(channel['free'][0]['streams']['128']))
    print(count)


if __name__ == '__main__':
    main()