-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSkyQgetChannelList.py
50 lines (41 loc) · 1.25 KB
/
SkyQgetChannelList.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/local/bin/python3
import sys
import json
import asyncio
import time
import requests
import yaml
# configuration
filename = '/config/packages/skyq_mediaplayer.yaml
name = 'Sky'
host = '192.168.1.15'
country = 'ITA'
async def buildChannelList():
sources = {}
url = 'http://{0}:9006/as/services'.format(host)
r = requests.get(url, headers={'content-type': 'application/json'})
array = r.json()
for channel in array['services']:
chName = channel['t'].replace(" ", "") + "_"+channel['c']
chNumber = ",".join([channel['c'][i:i+1] for i in range(0, len(channel['c']), 1)])
sources[chName] = chNumber
entity = {'media_player':[
{'platform': 'skyq',
'name': name,
'host': host,
'live_tv': False,
'country': country,
'sources': sources
}
]}
with open(filename, 'w') as f:
data = yaml.dump(entity, f, sort_keys=False)
async def main():
asyncio.ensure_future(buildChannelList())
# Main body
if __name__ == '__main__':
start = time.time()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
end = time.time()
#print(f'Time: {end-start:.2f} sec')