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 += 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:
|
||||||
|
Loading…
Reference in New Issue
Block a user