add sources
This commit is contained in:
parent
7374cfed9d
commit
9b46ae4683
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
|
sources.m3u8
|
||||||
|
@ -2,9 +2,16 @@ FROM alpine:edge as base
|
|||||||
RUN ["apk", "add", "--no-cache", "--repository", "https://dl-cdn.alpinelinux.org/alpine/edge/testing", "streamlink", "py3-tornado"]
|
RUN ["apk", "add", "--no-cache", "--repository", "https://dl-cdn.alpinelinux.org/alpine/edge/testing", "streamlink", "py3-tornado"]
|
||||||
RUN ["mkdir", "/app"]
|
RUN ["mkdir", "/app"]
|
||||||
COPY ["stream.py", "/app/stream.py"]
|
COPY ["stream.py", "/app/stream.py"]
|
||||||
|
RUN ["chmod", "755", "/app/stream.py"]
|
||||||
|
|
||||||
|
FROM base as sources
|
||||||
|
COPY ["sources.py", "/app/sources.py"]
|
||||||
|
COPY ["tv.m3u8", "/app/tv.m3u8"]
|
||||||
|
RUN ["python3", "/app/sources.py"]
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=base / /
|
COPY --from=base / /
|
||||||
|
COPY --from=sources /app/sources.m3u8 /app/sources.m3u8
|
||||||
|
|
||||||
USER 1444:1444
|
USER 1444:1444
|
||||||
ENTRYPOINT ["/app/stream.py"]
|
ENTRYPOINT ["/app/stream.py"]
|
||||||
|
29
sources.py
Executable file
29
sources.py
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
#!/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)
|
23
stream.py
23
stream.py
@ -35,9 +35,7 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
if resp is not None:
|
if resp is not None:
|
||||||
src = resp.url
|
src = resp.url
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if write:
|
print(e)
|
||||||
self.write(e)
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
streams = proxy.streams(src)
|
streams = proxy.streams(src)
|
||||||
@ -47,20 +45,27 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
endpoint = stream.url
|
endpoint = stream.url
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if write:
|
print(str(e))
|
||||||
self.write(str(e))
|
endpoint = None
|
||||||
return
|
|
||||||
if endpoint is None:
|
if endpoint is None:
|
||||||
if write:
|
self.set_status(404, reason="stream not found")
|
||||||
self.write("stream not found")
|
|
||||||
else:
|
else:
|
||||||
self.redirect(endpoint, status=303)
|
self.redirect(endpoint, status=303)
|
||||||
def get(self):
|
def get(self):
|
||||||
self.handle_any(True)
|
self.handle_any(True)
|
||||||
def head(self):
|
def head(self):
|
||||||
self.handle_any(False)
|
self.handle_any(False)
|
||||||
|
|
||||||
|
class FileHandler(tornado.web.RequestHandler):
|
||||||
|
def get(self):
|
||||||
|
self.set_header("Content-Type", "text/plain; charset=utf-8")
|
||||||
|
with open("/app/sources.m3u8", "r") as f:
|
||||||
|
self.write(f.read())
|
||||||
try:
|
try:
|
||||||
app_web = tornado.web.Application([(tornado.routing.AnyMatches(), MainHandler)])
|
handlers = []
|
||||||
|
handlers.append((tornado.routing.PathMatches("/sources.m3u8"), FileHandler))
|
||||||
|
handlers.append((tornado.routing.AnyMatches(), MainHandler))
|
||||||
|
app_web = tornado.web.Application(handlers)
|
||||||
app_web.listen(8080)
|
app_web.listen(8080)
|
||||||
tornado.ioloop.IOLoop.current().start()
|
tornado.ioloop.IOLoop.current().start()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
8
tv.m3u8
Normal file
8
tv.m3u8
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#EXTINF:0 radio="false", NRK 1
|
||||||
|
https://stream.purser.it/direkte/nrk1?provider=nrk
|
||||||
|
#EXTINF:0 radio="false", NRK 2
|
||||||
|
https://stream.purser.it/direkte/nrk2?provider=nrk
|
||||||
|
#EXTINF:0 radio="false", NRK 3
|
||||||
|
https://stream.purser.it/direkte/nrk3?provider=nrk
|
||||||
|
#EXTINF:0 radio="false", NRK Super
|
||||||
|
https://stream.purser.it/direkte/nrksuper?provider=nrk
|
Loading…
x
Reference in New Issue
Block a user