|
@@ -0,0 +1,63 @@
|
|
1
|
+#!/usr/bin/python3
|
|
2
|
+
|
|
3
|
+import requests
|
|
4
|
+
|
|
5
|
+api_url = 'http://www.fipradio.fr/livemeta/7'
|
|
6
|
+
|
|
7
|
+def get_all():
|
|
8
|
+
|
|
9
|
+ r = requests.get(api_url)
|
|
10
|
+ if r.status_code != 200:
|
|
11
|
+ msg = "Got status code %d for %s"
|
|
12
|
+ msg %= (r.status_code, api_url)
|
|
13
|
+ raise RuntimeError(msg)
|
|
14
|
+
|
|
15
|
+ return r.json()
|
|
16
|
+
|
|
17
|
+def get_current():
|
|
18
|
+ datas = get_all()
|
|
19
|
+ position = datas['levels'][0]['position']
|
|
20
|
+ item_id = datas['levels'][0]['items'][position]
|
|
21
|
+ item = datas['steps'][item_id]
|
|
22
|
+
|
|
23
|
+ return item
|
|
24
|
+
|
|
25
|
+def format_current():
|
|
26
|
+ item = get_current()
|
|
27
|
+ infos = """Title :\t\t{title}
|
|
28
|
+Authors :\t{author}
|
|
29
|
+Album :\t\t{album}
|
|
30
|
+Visual :\t{image}
|
|
31
|
+Youtube :\t{youtube}
|
|
32
|
+"""
|
|
33
|
+
|
|
34
|
+ return infos.format( title = item['title'].title(),
|
|
35
|
+ author = item['authors'].title(),
|
|
36
|
+ album = item['titreAlbum'].title(),
|
|
37
|
+ image = item['visual'],
|
|
38
|
+ youtube = item['lienYoutube'])
|
|
39
|
+
|
|
40
|
+def icecast_infos():
|
|
41
|
+ item = get_current()
|
|
42
|
+ infos = """{title} - {author} ({album})"""
|
|
43
|
+ return infos.format( title = item['title'].title(),
|
|
44
|
+ author = item['authors'].title(),
|
|
45
|
+ album = item['titreAlbum'].title())
|
|
46
|
+
|
|
47
|
+def icecast_url_update(host, mount, login = None, password = None):
|
|
48
|
+ infos = icecast_infos()
|
|
49
|
+ url = "http://{host}/admin/medata?mount={mount}&mode=updinfo&song={infos}"
|
|
50
|
+ url = url.format( host = host,
|
|
51
|
+ mount = mount,
|
|
52
|
+ infos = infos)
|
|
53
|
+ auth = None
|
|
54
|
+ if login is not None and password is not None:
|
|
55
|
+ auth = (login, password)
|
|
56
|
+ res = requests.get(url, auth)
|
|
57
|
+
|
|
58
|
+ if r.status_code != 200:
|
|
59
|
+ msg = "Got status code %d for %s"
|
|
60
|
+ msg %= (r.status_code, url)
|
|
61
|
+ raise RuntimeError(msg)
|
|
62
|
+
|
|
63
|
+print(icecast_infos())
|