-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebradio_metadata.py
54 lines (45 loc) · 1.51 KB
/
webradio_metadata.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
# package webradio_metadata/webradio_metadata.py
# Scraps webradio metadatas
import sys
import requests
import time
import json
#import subprocess
from streams_url import streamsurl
def main():
name = sys.argv[1]
url = streamsurl[name]['url']
parser = streamsurl[name]['parser']
while True:
try:
data = requests.get(url).json()
func = globals()[parser]
metadata = func(data)
print( json.dumps(metadata) )
return
except Exception:
time.sleep(2)
continue
def fip(data):
level = data['levels'][0]
uid = level['items'][level['position']]
metadata = data['steps'][uid]
return { 'title': metadata['title'], 'artist': metadata['authors'], 'annee': metadata['anneeEditionMusique'], 'cover': metadata['visual'] }
def france_inter(data):
seconds = time.time()
metadata = {'artist': None, 'title': None, 'annee': None, 'cover': None}
for item in data:
if seconds > item['start'] and seconds < item['end']:
if 'conceptParentTitle' in item:
metadata['artist'] = item["conceptParentTitle"];
metadata['title'] = item['conceptTitle']
if 'expressionTitle' in item :
metadata['title'] += " - " + item['expressionTitle']
return metadata
if __name__== "__main__":
import traceback
try:
main()
except:
with open('/tmp/fip-crash.log', 'w') as f:
traceback.print_exc(file=f)