proxy fallback
This commit is contained in:
parent
be0a868861
commit
6771bb774b
37
stream.py
37
stream.py
@ -28,8 +28,17 @@ class ProxyElem():
|
|||||||
|
|
||||||
proxies = {}
|
proxies = {}
|
||||||
for key in providers:
|
for key in providers:
|
||||||
proxy = os.environ.get(key.upper() + "_PROXY")
|
proxies[key] = []
|
||||||
proxies[key] = ProxyElem(proxy)
|
current = []
|
||||||
|
for i in range(0,9):
|
||||||
|
proxy = os.environ.get(f'{key}_proxy{i}'.upper())
|
||||||
|
if proxy is not None:
|
||||||
|
current.append(proxy)
|
||||||
|
if len(current) == 0:
|
||||||
|
proxies[key].append(ProxyElem(None))
|
||||||
|
else:
|
||||||
|
for proxy in current:
|
||||||
|
proxies[key].append(ProxyElem(proxy))
|
||||||
|
|
||||||
playlist = None
|
playlist = None
|
||||||
icecast_server = os.environ.get("ICECAST_SERVER")
|
icecast_server = os.environ.get("ICECAST_SERVER")
|
||||||
@ -154,18 +163,23 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
upstream = None
|
upstream = None
|
||||||
proxy = None
|
proxy = None
|
||||||
if provider in providers.keys():
|
if provider in providers.keys():
|
||||||
proxy = proxies.get(provider)
|
|
||||||
path = self.request.path
|
path = self.request.path
|
||||||
if provider == "youtube":
|
if provider == "youtube":
|
||||||
path = path.strip("/")
|
path = path.strip("/")
|
||||||
src = providers[provider] + self.request.path
|
src = providers[provider] + self.request.path
|
||||||
try:
|
proxy = None
|
||||||
resp = requests.head(src, allow_redirects=True)
|
proxy_list = proxies.get(provider)
|
||||||
if resp is not None:
|
if isinstance(proxy_list, list):
|
||||||
src = resp.url
|
for proxy_temp in proxy_list:
|
||||||
except Exception as e:
|
try:
|
||||||
print(e)
|
resp = requests.head(src, allow_redirects=True, proxies=proxy_temp.req)
|
||||||
else:
|
if resp is not None:
|
||||||
|
src = resp.url
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
else:
|
||||||
|
proxy = proxy_temp
|
||||||
|
if proxy is not None:
|
||||||
try:
|
try:
|
||||||
streams = proxy.stream.streams(src)
|
streams = proxy.stream.streams(src)
|
||||||
for key in reversed(streams):
|
for key in reversed(streams):
|
||||||
@ -174,8 +188,7 @@ class MainHandler(tornado.web.RequestHandler):
|
|||||||
upstream = stream.url
|
upstream = stream.url
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print(e)
|
||||||
upstream = None
|
|
||||||
if upstream is None:
|
if upstream is None:
|
||||||
self.set_status(404)
|
self.set_status(404)
|
||||||
if write:
|
if write:
|
||||||
|
Loading…
Reference in New Issue
Block a user