-
Notifications
You must be signed in to change notification settings - Fork 2
/
radio.py
43 lines (34 loc) · 1.24 KB
/
radio.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
import requests
import json
uri = 'https://api.wnyc.org/api/v1/whats_on/wqxr/'
class Radio:
def fetchTrack():
response = requests.get(uri)
json = response.json()
if 'current_playlist_item' in json and json['current_playlist_item'] != None:
return json['current_playlist_item']
elif 'current_show' in json:
return json['current_show']
return []
def getTitle(track):
if 'title' in track:
return track['title']
elif 'catalog_entry' in track and 'title' in track['catalog_entry']:
return track['catalog_entry']['title']
return ''
def getComposer(track):
if 'show_title' in track:
return track['show_title']
elif 'catalog_entry' in track and 'composer' in track['catalog_entry']:
return track['catalog_entry']['composer']['name']
return ''
def getConductor(track):
return track['conductor']['name']
def getStartTime(track):
# if there's an actual track
if 'start_time_ts' in track:
return track['start_time_ts']
# if we're falling back on show
elif 'start_ts' in track:
return track['start_ts']
return ''