This commit is contained in:
Roy Olav Purser 2021-05-09 18:43:28 +02:00
parent 67a7b82efe
commit 870e655038
Signed by: roypur
GPG Key ID: E14D26A036F21656
2 changed files with 37 additions and 2 deletions

11
index.html Normal file
View File

@ -0,0 +1,11 @@
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/video.js/7.12.1/video-js.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/7.12.1/video.min.js"></script>
</head>
<body>
<video class="video-js" data-setup='{}' controls>
<source src="{{ stream }}" type="application/vnd.apple.mpegurl" />
</video>
</body>
</html>

View File

@ -49,6 +49,11 @@ if icecast_server is not None and stream_server is not None:
playlist += f'#EXTINF:0 radio="false", {name}\n' playlist += f'#EXTINF:0 radio="false", {name}\n'
playlist += stream_server + key + "\n" playlist += stream_server + key + "\n"
template = None
with open("index.html", "r") as f:
template = tornado.template.Template(f.read().strip())
def get_proxy_url(proxy, current, path): def get_proxy_url(proxy, current, path):
data = {} data = {}
data["upstream"] = urllib.parse.urljoin(current, path) data["upstream"] = urllib.parse.urljoin(current, path)
@ -64,7 +69,6 @@ def rewrite(current, provider):
proxy = proxies_raw.get(provider) proxy = proxies_raw.get(provider)
resp = requests.head(current, proxies=proxy_req) resp = requests.head(current, proxies=proxy_req)
ctype = resp.headers.get("Content-Type") ctype = resp.headers.get("Content-Type")
print(ctype)
if ctype is None: if ctype is None:
return None return None
else: else:
@ -90,9 +94,29 @@ def rewrite(current, provider):
class MainHandler(tornado.web.RequestHandler): class MainHandler(tornado.web.RequestHandler):
def handle_any(self, write): def handle_any(self, write):
provider = self.get_query_argument("provider", None) provider = self.get_query_argument("provider", None)
render = self.get_query_argument("render", False)
if isinstance(provider, str):
if isinstance(render, str):
if render.lower() == "true":
self.handle_render(provider, write)
else:
self.handle_stream(provider, write)
else:
self.handle_stream(provider, write)
else:
self.set_status(404)
if write:
self.write("stream not found")
def handle_render(self, provider, write):
stream_path = f'{self.request.path}?provider={provider}'
rendered = template.generate(stream=stream_path)
self.write(rendered)
def handle_stream(self, provider, write):
upstream = None upstream = None
proxy = None proxy = None
if provider is not None and provider in providers.keys(): if provider in providers.keys():
proxy = proxies.get(provider) proxy = proxies.get(provider)
src = providers[provider] + self.request.path src = providers[provider] + self.request.path
try: try: