Skip to content

Commit

Permalink
Prompt to install pysocks dependency if socks proxy is being used anx…
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Sep 23, 2024
1 parent ea049dc commit 46f14ae
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions resources/lib/youtube_plugin/kodion/settings/abstract_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def proxy_settings(self, value=None, as_mapping=True):
self.set_bool(setting_name, setting_value)
return value

proxy_source = self.get_int(SETTINGS.PROXY_SOURCE, 0)
proxy_source = self.get_int(SETTINGS.PROXY_SOURCE, 1)
if not proxy_source:
return None

Expand Down Expand Up @@ -314,6 +314,28 @@ def proxy_settings(self, value=None, as_mapping=True):
if proxy_source == 1 and not settings[SETTINGS.PROXY_ENABLED]['value']:
return None

scheme = self._PROXY_TYPE_SCHEME[settings[SETTINGS.PROXY_TYPE]['value']]
if scheme.startswith('socks'):
from ..compatibility import xbmc, xbmcaddon

pysocks = None
install_attempted = False
while not pysocks:
try:
pysocks = xbmcaddon.Addon('script.module.pysocks')
except RuntimeError:
if install_attempted:
break
xbmc.executebuiltin(
'InstallAddon(script.module.pysocks)',
wait=True,
)
install_attempted = True
if pysocks:
del pysocks
else:
return None

host = settings[SETTINGS.PROXY_SERVER]['value']
if not host:
return None
Expand All @@ -335,12 +357,7 @@ def proxy_settings(self, value=None, as_mapping=True):
else:
auth_string = ''

proxy_string = ''.join((
self._PROXY_TYPE_SCHEME[settings[SETTINGS.PROXY_TYPE]['value']],
'://',
auth_string,
host_port_string,
))
proxy_string = ''.join((scheme, '://', auth_string, host_port_string))
return {
'http': proxy_string,
'https': proxy_string,
Expand Down

0 comments on commit 46f14ae

Please sign in to comment.