Child: [37e96a] (diff)

Download this file

fip-meta.py    46 lines (39 with data), 1.2 kB

 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
#!/usr/bin/env python3
#
# Metadata getter for fip stations, we get the station number as first
# parameter (set in config file).
import requests
import json
import sys
import os
import time
def firstvalid(a, names):
for nm in names:
if nm in a and a[nm]:
return a[nm]
return ''
def titlecase(t):
return " ".join([s.capitalize() for s in t.split()])
stationid = ''
if len(sys.argv) > 1:
stationid = sys.argv[1]
# Make sure this not one of the upmpdcli param namess, but a number
try:
bogus = int(stationid)
except:
stationid = ''
r = requests.get('https://www.fip.fr/livemeta/' + stationid)
r.raise_for_status()
newjsd = r.json()
songs = newjsd['steps']
now = time.time()
for song in songs.values():
song_end = song['end']
if song['embedType'] == 'song' and song_end >= now and song['start'] <= now:
title = titlecase(firstvalid(song, ('title',)))
artist = titlecase(firstvalid(song, ('performers', 'authors')))
metadata = {'title' : title,
'artist': artist,
'artUrl' : song['visual'],
'reload' : int(song_end - now + 1)}
print("%s"% json.dumps(metadata))