Update icecast2 FIP relay using HTTP/Json API http://zmpd.zered.net:8042/fip-metadata.mp3
python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fip_current.py 1.8KB

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