stream-api/sources.py
2021-05-01 20:01:24 +02:00

30 lines
1014 B
Python
Executable File

#!/usr/bin/env python3
import xml.dom.minidom
import requests
playlist = None
try:
resp = requests.get("https://git.purser.it/roypur/icecast-relay/raw/branch/master/icecast.xml")
dom = xml.dom.minidom.parseString(resp.text)
except Exception as e:
print(e)
else:
playlist = "#EXTM3U\n"
mounts = dom.getElementsByTagName("mount")
for mount in mounts:
mount_names = mount.getElementsByTagName("mount-name")
stream_names = mount.getElementsByTagName("stream-name")
if len(mount_names) == 1 and len(stream_names) == 1:
mount_name = mount_names[0].firstChild.nodeValue
stream_name = stream_names[0].firstChild.nodeValue
playlist += f'#EXTINF:0 radio="true", {stream_name}\n'
playlist += "https://icecast.purser.it:7000" + mount_name + "\n"
if playlist is not None:
with open("/app/tv.m3u8", "r") as f:
tv = f.read()
with open("/app/sources.m3u8", "w+") as f:
f.write(playlist)
f.write(tv)