proxy file

This commit is contained in:
Roy Olav Purser 2021-05-12 00:15:01 +02:00
parent 850e4d8cd8
commit 2d0d9a920e
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -86,14 +86,12 @@ def get_proxy_url(proxy, current, path):
presp = requests.post(proxy_server, json=data) presp = requests.post(proxy_server, json=data)
return presp.text return presp.text
def rewrite(current, provider, proxy): def upstream_type(current, proxy):
resp = requests.head(current, proxies=proxy.req) resp = requests.head(current, proxies=proxy.req)
ctype = resp.headers.get("Content-Type") return resp.headers.get("Content-Type", "binary/octet-stream")
if ctype is None:
return None def rewrite(current, provider, proxy, ctype):
else:
if "mpegurl" not in ctype.lower():
return None
resp = requests.get(current, proxies=proxy.req) resp = requests.get(current, proxies=proxy.req)
ndata = None ndata = None
if resp.text is not None: if resp.text is not None:
@ -203,7 +201,20 @@ class MainHandler(tornado.web.RequestHandler):
if write: if write:
self.write("Stream not found.") self.write("Stream not found.")
else: else:
data = rewrite(upstream, provider, proxy) ctype = upstream_type(upstream, proxy)
if "mpgurl" in ctype:
data = rewrite(upstream, provider, proxy)
else:
ldata = {}
ldata["upstream"] = upstream
ldata["proxy"] = proxy.proxy
ldata["proxied"] = isinstance(proxy.proxy, str)
links = [ldata]
resp = requests.post(proxy_server, json=links)
if isinstance(resp.text, list):
new_links = json.loads(resp.text)
if len(new_links) == 1:
upstream = new_links.pop()
if data is None: if data is None:
self.redirect(upstream, status=303) self.redirect(upstream, status=303)
else: else: