reuse streamlink sessions
This commit is contained in:
parent
278de926e3
commit
0505fee331
@ -111,6 +111,13 @@ for key in providers:
|
||||
for proxy in current:
|
||||
proxies[key].append(ProxyElem(proxy))
|
||||
|
||||
proxy_keys = []
|
||||
for proxy_provider in proxies.values():
|
||||
for proxy in proxy_provider:
|
||||
if isinstance(proxy, ProxyElem) and isinstance(proxy.proxy, str):
|
||||
proxy_keys.append(proxy.proxy)
|
||||
stream_providers.setup(proxy_keys)
|
||||
|
||||
class UpstreamHandler():
|
||||
def __init__(self):
|
||||
self.provider = None
|
||||
|
@ -5,7 +5,13 @@ import asyncio
|
||||
import html.parser
|
||||
import re
|
||||
|
||||
ytimg_pattern = re.compile(r'(https:\/\/[a-z0-9.]+ytimg\.com\/.+\/)[a-z0-9]+(\.[a-z0-9]+)')
|
||||
streamlink_sessions = {}
|
||||
streamlink_default_session = streamlink.Streamlink()
|
||||
def setup(proxies):
|
||||
for proxy in proxies:
|
||||
streamlink_sessions[proxy] = streamlink.Streamlink()
|
||||
streamlink_sessions[proxy].set_option("http-proxy", proxy)
|
||||
streamlink_sessions[proxy].set_option("https-proxy", proxy)
|
||||
|
||||
class DummyLogger():
|
||||
def debug(self, msg):
|
||||
@ -88,11 +94,13 @@ class StreamProvider():
|
||||
class StreamlinkRunner(StreamProvider):
|
||||
def stream(self):
|
||||
try:
|
||||
session = streamlink.Streamlink()
|
||||
if self.proxy is not None:
|
||||
session.set_option("https-proxy", self.proxy)
|
||||
session.set_option("http-proxy", self.proxy)
|
||||
streams = session.streams(self.upstream)
|
||||
session = None
|
||||
if self.proxy is None:
|
||||
session = streamlink_default_session
|
||||
else:
|
||||
session = streamlink_sessions.get(self.proxy)
|
||||
media = session.resolve_url(self.upstream)
|
||||
streams = media.streams()
|
||||
if streams is not None:
|
||||
for key in reversed(streams):
|
||||
stream = streams.get(key)
|
||||
|
Loading…
Reference in New Issue
Block a user