fix proxy elem

This commit is contained in:
Roy Olav Purser 2022-01-30 14:38:34 +01:00
parent dca80369de
commit d7bab22280
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -13,6 +13,7 @@ import expiringdict
import subprocess import subprocess
import json import json
import re import re
import config
try: try:
streamlink_sessions = {} streamlink_sessions = {}
@ -122,8 +123,7 @@ class StreamProvider():
self.upstream = upstream self.upstream = upstream
self.proxy = None self.proxy = None
self.logger = logger self.logger = logger
proxy = str(proxy) if isinstance(proxy, config.ProxyElem):
if len(proxy) > 5:
self.proxy = proxy self.proxy = proxy
def extract_mime(self, upstream): def extract_mime(self, upstream):
try: try:
@ -156,10 +156,10 @@ class StreamProvider():
if not isinstance(data.upstream(), str) or isinstance(data.ctype(), str): if not isinstance(data.upstream(), str) or isinstance(data.ctype(), str):
return data return data
proxies = None proxies = None
if isinstance(self.proxy, str): if self.proxy is not None and self.proxy.proxy is not None:
proxies = {} proxies = {}
proxies["http"] = "socks5://" + self.proxy proxies["http"] = "socks5://" + self.proxy.proxy
proxies["https"] = "socks5://" + self.proxy proxies["https"] = "socks5://" + self.proxy.proxy
ctype = None ctype = None
upstream = data.upstream() upstream = data.upstream()
try: try:
@ -188,10 +188,10 @@ class StreamlinkRunner(StreamProvider):
def stream(self): def stream(self):
try: try:
session = None session = None
if self.proxy is None: if self.proxy is None or self.proxy.proxy is None:
session = streamlink_default_session session = streamlink_default_session
else: else:
session = streamlink_sessions.get(self.proxy) session = streamlink_sessions.get(self.proxy.proxy)
media = session.resolve_url(self.upstream) media = session.resolve_url(self.upstream)
streams = None streams = None
if isinstance(media, tuple): if isinstance(media, tuple):
@ -214,8 +214,9 @@ class YoutubeRunner(StreamProvider):
try: try:
opts = {} opts = {}
opts["logger"] = DummyLogger() 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: with youtube_dl.YoutubeDL(opts) as ydl:
info = ydl.extract_info(self.upstream, download=False) info = ydl.extract_info(self.upstream, download=False)
vformats = info.get("formats") vformats = info.get("formats")