add proxy

This commit is contained in:
Roy Olav Purser 2021-05-08 19:12:21 +02:00
parent c1ab35efa3
commit 16aede77b5
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -21,7 +21,7 @@ for key in providers:
proxy = os.environ.get(key.upper() + "_PROXY")
proxies[key].set_option("http-timeout", 2.0)
if proxy is not None:
#proxies[key].set_option("https-proxy", proxy)
proxies[key].set_option("https-proxy", proxy)
splitted = proxy.split(":", 1)
if len(splitted) == 2:
proxies_raw[key] = splitted[1].lstrip("/")
@ -46,7 +46,7 @@ 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"
def rewrite(current, endpoint, proxy):
def rewrite(current, proxy):
resp = requests.get(current)
ndata = resp.text
if resp.text is not None and proxy_server is not None:
@ -66,7 +66,7 @@ def rewrite(current, endpoint, proxy):
class MainHandler(tornado.web.RequestHandler):
def handle_any(self, write):
provider = self.get_query_argument("provider", None)
endpoint = None
upstream = None
proxy = None
proxy_raw = None
if provider is not None and provider in providers.keys():
@ -85,18 +85,18 @@ class MainHandler(tornado.web.RequestHandler):
for key in reversed(streams):
stream = streams.get(key)
if hasattr(stream, "url"):
endpoint = stream.url
upstream = stream.url
break
except Exception as e:
print(str(e))
endpoint = None
if endpoint is None:
upstream = None
if upstream is None:
self.set_status(404)
if write:
self.write("stream not found")
else:
rewrite(endpoint, "", proxy_raw)
self.redirect(endpoint, status=303)
rewrite(upstream, proxy_raw)
self.redirect(upstream, status=303)
def get(self):
self.handle_any(True)
def head(self):