-
Notifications
You must be signed in to change notification settings - Fork 1
/
tunein.py
60 lines (45 loc) · 1.66 KB
/
tunein.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
51
52
53
54
55
56
57
58
59
60
#http://opml.radiotime.com/Browse.ashx?id=r0&render=json
import urllib.request
from urllib.request import Request
from urllib.request import urlopen
from urllib.error import HTTPError
import json
class openRadio(object):
def __init__(self):
pass
def getOverview(self):
result = []
url = "http://opml.radiotime.com/Browse.ashx?render=json"
try:
req = urllib.request.urlopen(url)
res = json.loads(req.read().decode('utf-8'))
body = res.get("body")
for item in body:
result.append({"name":item.get("text"),"url":item.get("URL"), "type":item.get("type")})
except Exception as msg:
print(msg)
return result
def getNextLayer(self, url):
result = []
try:
req = urllib.request.urlopen(url + "&render=json")
res = json.loads(req.read().decode('utf-8'))
body = res.get("body")
if "children" in body[0]:
body = body[0].get("children")
#print("BODY" + str(body))
for item in body:
result.append({"name":item.get("text"),"url":item.get("URL"), "type":item.get("type"), "image":item.get("image")})
except Exception as msg:
print(msg)
return result
def getStreamUrl(self, url):
result = []
try:
req = urllib.request.urlopen(url)
res = req.read().decode('utf-8')
print("URL stack includes:\n",res)
result = res
except Exception as msg:
print(msg)
return result