From d7bab222807a7cea605824b28d6630097d26aa72 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sun, 30 Jan 2022 14:38:34 +0100 Subject: [PATCH] fix proxy elem --- backend/stream_providers.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/backend/stream_providers.py b/backend/stream_providers.py index 12e19c6..00c6695 100755 --- a/backend/stream_providers.py +++ b/backend/stream_providers.py @@ -13,6 +13,7 @@ import expiringdict import subprocess import json import re +import config try: streamlink_sessions = {} @@ -122,8 +123,7 @@ class StreamProvider(): self.upstream = upstream self.proxy = None self.logger = logger - proxy = str(proxy) - if len(proxy) > 5: + if isinstance(proxy, config.ProxyElem): self.proxy = proxy def extract_mime(self, upstream): try: @@ -156,10 +156,10 @@ class StreamProvider(): if not isinstance(data.upstream(), str) or isinstance(data.ctype(), str): return data proxies = None - if isinstance(self.proxy, str): + if self.proxy is not None and self.proxy.proxy is not None: proxies = {} - proxies["http"] = "socks5://" + self.proxy - proxies["https"] = "socks5://" + self.proxy + proxies["http"] = "socks5://" + self.proxy.proxy + proxies["https"] = "socks5://" + self.proxy.proxy ctype = None upstream = data.upstream() try: @@ -188,10 +188,10 @@ class StreamlinkRunner(StreamProvider): def stream(self): try: session = None - if self.proxy is None: + if self.proxy is None or self.proxy.proxy is None: session = streamlink_default_session else: - session = streamlink_sessions.get(self.proxy) + session = streamlink_sessions.get(self.proxy.proxy) media = session.resolve_url(self.upstream) streams = None if isinstance(media, tuple): @@ -214,8 +214,9 @@ class YoutubeRunner(StreamProvider): try: opts = {} opts["logger"] = DummyLogger() - if isinstance(self.proxy, str): - opts["proxy"] = "socks5://" + self.proxy + + if self.proxy is not None and self.proxy.proxy is not None: + opts["proxy"] = "socks5://" + self.proxy.proxy with youtube_dl.YoutubeDL(opts) as ydl: info = ydl.extract_info(self.upstream, download=False) vformats = info.get("formats")