add html
This commit is contained in:
parent
67a7b82efe
commit
870e655038
11
index.html
Normal file
11
index.html
Normal 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>
|
28
stream.py
28
stream.py
@ -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 += 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):
|
||||
data = {}
|
||||
data["upstream"] = urllib.parse.urljoin(current, path)
|
||||
@ -64,7 +69,6 @@ def rewrite(current, provider):
|
||||
proxy = proxies_raw.get(provider)
|
||||
resp = requests.head(current, proxies=proxy_req)
|
||||
ctype = resp.headers.get("Content-Type")
|
||||
print(ctype)
|
||||
if ctype is None:
|
||||
return None
|
||||
else:
|
||||
@ -90,9 +94,29 @@ def rewrite(current, provider):
|
||||
class MainHandler(tornado.web.RequestHandler):
|
||||
def handle_any(self, write):
|
||||
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
|
||||
proxy = None
|
||||
if provider is not None and provider in providers.keys():
|
||||
if provider in providers.keys():
|
||||
proxy = proxies.get(provider)
|
||||
src = providers[provider] + self.request.path
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user