-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradiobrowser.py
38 lines (25 loc) · 964 Bytes
/
radiobrowser.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
import urllib
import ast
from state import *
class RadioBrowser():
@staticmethod
def to_radio(s):
return Radio(s['id'], s['name'], s['url'])
@staticmethod
def search(searchterm):
url = 'http://www.radio-browser.info/webservice/json/stations/' + urllib.quote_plus(searchterm)
print 'Quering: ' + url
stations = ast.literal_eval(urllib.urlopen(url).read())
data = [];
for s in stations:
data.append(RadioBrowser.to_radio(s))
return data
@staticmethod
def byid(id):
print 'RadioBrowser.get: ' + str(id)
url = 'http://www.radio-browser.info/webservice/json/stations/byid/' + urllib.quote_plus(id)
print 'Quering: ' + url
stations = ast.literal_eval(urllib.urlopen(url).read())
for s in stations:
return RadioBrowser.to_radio(s)
return None