proxy file
This commit is contained in:
parent
850e4d8cd8
commit
2d0d9a920e
25
stream.py
25
stream.py
@ -86,14 +86,12 @@ def get_proxy_url(proxy, current, path):
|
||||
presp = requests.post(proxy_server, json=data)
|
||||
return presp.text
|
||||
|
||||
def rewrite(current, provider, proxy):
|
||||
def upstream_type(current, proxy):
|
||||
resp = requests.head(current, proxies=proxy.req)
|
||||
ctype = resp.headers.get("Content-Type")
|
||||
if ctype is None:
|
||||
return None
|
||||
else:
|
||||
if "mpegurl" not in ctype.lower():
|
||||
return None
|
||||
return resp.headers.get("Content-Type", "binary/octet-stream")
|
||||
|
||||
def rewrite(current, provider, proxy, ctype):
|
||||
|
||||
resp = requests.get(current, proxies=proxy.req)
|
||||
ndata = None
|
||||
if resp.text is not None:
|
||||
@ -203,7 +201,20 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
if write:
|
||||
self.write("Stream not found.")
|
||||
else:
|
||||
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:
|
||||
self.redirect(upstream, status=303)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user