Initial commit
This commit is contained in:
commit
0848820588
2 changed files with 65 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
*.pyc
|
||||||
|
.*.swp
|
||||||
63
fip_current.py
Executable file
63
fip_current.py
Executable file
|
|
@ -0,0 +1,63 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
api_url = 'http://www.fipradio.fr/livemeta/7'
|
||||||
|
|
||||||
|
def get_all():
|
||||||
|
|
||||||
|
r = requests.get(api_url)
|
||||||
|
if r.status_code != 200:
|
||||||
|
msg = "Got status code %d for %s"
|
||||||
|
msg %= (r.status_code, api_url)
|
||||||
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
def get_current():
|
||||||
|
datas = get_all()
|
||||||
|
position = datas['levels'][0]['position']
|
||||||
|
item_id = datas['levels'][0]['items'][position]
|
||||||
|
item = datas['steps'][item_id]
|
||||||
|
|
||||||
|
return item
|
||||||
|
|
||||||
|
def format_current():
|
||||||
|
item = get_current()
|
||||||
|
infos = """Title :\t\t{title}
|
||||||
|
Authors :\t{author}
|
||||||
|
Album :\t\t{album}
|
||||||
|
Visual :\t{image}
|
||||||
|
Youtube :\t{youtube}
|
||||||
|
"""
|
||||||
|
|
||||||
|
return infos.format( title = item['title'].title(),
|
||||||
|
author = item['authors'].title(),
|
||||||
|
album = item['titreAlbum'].title(),
|
||||||
|
image = item['visual'],
|
||||||
|
youtube = item['lienYoutube'])
|
||||||
|
|
||||||
|
def icecast_infos():
|
||||||
|
item = get_current()
|
||||||
|
infos = """{title} - {author} ({album})"""
|
||||||
|
return infos.format( title = item['title'].title(),
|
||||||
|
author = item['authors'].title(),
|
||||||
|
album = item['titreAlbum'].title())
|
||||||
|
|
||||||
|
def icecast_url_update(host, mount, login = None, password = None):
|
||||||
|
infos = icecast_infos()
|
||||||
|
url = "http://{host}/admin/medata?mount={mount}&mode=updinfo&song={infos}"
|
||||||
|
url = url.format( host = host,
|
||||||
|
mount = mount,
|
||||||
|
infos = infos)
|
||||||
|
auth = None
|
||||||
|
if login is not None and password is not None:
|
||||||
|
auth = (login, password)
|
||||||
|
res = requests.get(url, auth)
|
||||||
|
|
||||||
|
if r.status_code != 200:
|
||||||
|
msg = "Got status code %d for %s"
|
||||||
|
msg %= (r.status_code, url)
|
||||||
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
|
print(icecast_infos())
|
||||||
Loading…
Add table
Add a link
Reference in a new issue