new session for each request

This commit is contained in:
Roy Olav Purser 2021-05-13 10:04:39 +02:00
parent 6005208d7f
commit e9f9bc0fbf
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -21,15 +21,18 @@ providers["twitch"] = "https://twitch.tv"
class ProxyElem(): class ProxyElem():
def __init__(self, proxy): def __init__(self, proxy):
self.stream = streamlink.Streamlink()
self.proxy = proxy self.proxy = proxy
self.req = {} self.req = {}
self.stream.set_option("http-timeout", 2.0)
if proxy is not None: if proxy is not None:
self.stream.set_option("https-proxy", "socks5://" + proxy)
self.stream.set_option("http-proxy", "socks5://" + proxy)
self.req["http"] = "socks5://" + proxy self.req["http"] = "socks5://" + proxy
self.req["https"] = "socks5://" + proxy self.req["https"] = "socks5://" + proxy
def stream(self):
session = streamlink.Streamlink()
session.set_option("http-timeout", 2.0)
is self.proxy is not None:
session.set_option("https-proxy", "socks5://" + self.proxy)
session.set_option("http-proxy", "socks5://" + self.proxy)
return session
def __repr__(self): def __repr__(self):
return str(self.proxy) return str(self.proxy)
@ -206,7 +209,8 @@ class MainHandler(tornado.web.RequestHandler):
break break
if proxy is not None: if proxy is not None:
try: try:
streams = proxy.stream.streams(src) logger.info(proxy)
streams = proxy.stream().streams(src)
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
else: else: