Skip to content

Commit

Permalink
Merge pull request #906 from MoojMidge/master
Browse files Browse the repository at this point in the history
v7.1.0+beta.4
  • Loading branch information
MoojMidge authored Sep 23, 2024
2 parents d6bd540 + 46f14ae commit 6c14221
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 67 deletions.
3 changes: 2 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.youtube" name="YouTube" version="7.1.0+beta.3" provider-name="anxdpanic, bromix, MoojMidge">
<addon id="plugin.video.youtube" name="YouTube" version="7.1.0+beta.4" provider-name="anxdpanic, bromix, MoojMidge">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="2.27.1"/>
<import addon="inputstream.adaptive" version="19.0.0"/>
<import addon="script.module.inputstreamhelper" version="0.2.2" optional="true"/>
<import addon="script.module.pysocks" optional="true"/>
</requires>
<extension point="xbmc.python.pluginsource" library="resources/lib/plugin.py">
<provides>video</provides>
Expand Down
14 changes: 14 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## v7.1.0+beta.4
### Fixed
- Fix playback history related context menu items not being shown #904
- Fix new resume details not being saved in plugin local playback history #904

### Changed
- Allow default thumbnail selection fallbacks for all results
- Simplify handling of local history
- Incognito will no longer prevent existing local history from being shown
- Incognito will continue to prevent any update to local history

### New
- Add support for proxy settings #884

## v7.1.0+beta.3
### Fixed
- Fix various timing and sync issues with script, service, plugin and Kodi settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
CONNECT_TIMEOUT = 'requests.timeout.connect' # (int)
READ_TIMEOUT = 'requests.timeout.read' # (int)

PROXY_SOURCE = 'requests.proxy.source' # (int)
PROXY_ENABLED = 'requests.proxy.enabled' # (bool)
PROXY_TYPE = 'requests.proxy.type' # (int)
PROXY_SERVER = 'requests.proxy.server' # (str)
PROXY_PORT = 'requests.proxy.port' # (int)
PROXY_USERNAME = 'requests.proxy.username' # (str)
PROXY_PASSWORD = 'requests.proxy.password' # (str)

HTTPD_PORT = 'kodion.http.port' # (int)
HTTPD_LISTEN = 'kodion.http.listen' # (str)
HTTPD_WHITELIST = 'kodion.http.ip.whitelist' # (str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def run(self):
status=(segment_end, segment_end, segment_end, 'stopped'),
)
if use_local_history:
self._context.get_playback_history().update_item(self.video_id,
play_data)
self._context.get_playback_history().set_item(self.video_id,
play_data)

self._context.send_notification(PLAYBACK_STOPPED, self.playback_data)
self._context.log_debug('Playback stopped [{video_id}]:'
Expand Down
5 changes: 4 additions & 1 deletion resources/lib/youtube_plugin/kodion/network/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class BaseRequestsClass(object):
def __init__(self, context, exc_type=None):
settings = context.get_settings()
self._verify = settings.verify_ssl()
self._timeout = settings.get_timeout()
self._timeout = settings.requests_timeout()
self._proxy = settings.proxy_settings()

if isinstance(exc_type, tuple):
self._default_exc = (RequestException,) + exc_type
Expand Down Expand Up @@ -89,6 +90,8 @@ def request(self, url, method='GET',
timeout = self._timeout
if verify is None:
verify = self._verify
if proxies is None:
proxies = self._proxy
if allow_redirects is None:
allow_redirects = True

Expand Down
163 changes: 160 additions & 3 deletions resources/lib/youtube_plugin/kodion/settings/abstract_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import sys

from ..constants import SETTINGS
from ..utils import current_system_version, validate_ip_address
from ..utils import (
current_system_version,
get_kodi_setting_value,
validate_ip_address,
)


class AbstractSettings(object):
Expand Down Expand Up @@ -194,18 +198,171 @@ def safe_search(self):
def age_gate(self):
return self.get_bool(SETTINGS.AGE_GATE, True)

def verify_ssl(self):
def verify_ssl(self, value=None):
if value is not None:
return self.set_bool(SETTINGS.VERIFY_SSL, value)

if sys.version_info <= (2, 7, 9):
verify = False
else:
verify = self.get_bool(SETTINGS.VERIFY_SSL, True)
return verify

def get_timeout(self):
def requests_timeout(self, value=None):
if value is not None:
self.set_int(SETTINGS.CONNECT_TIMEOUT, value[0])
self.set_int(SETTINGS.READ_TIMEOUT, value[1])
return value

connect_timeout = self.get_int(SETTINGS.CONNECT_TIMEOUT, 9) + 0.5
read_timout = self.get_int(SETTINGS.READ_TIMEOUT, 27)
return connect_timeout, read_timout

_PROXY_TYPE_SCHEME = {
0: 'http',
1: 'socks4',
2: 'socks4a',
3: 'socks5',
4: 'socks5h',
5: 'https',
}

_PROXY_SETTINGS = {
SETTINGS.PROXY_ENABLED: {
'value': None,
'type': bool,
'default': False,
'kodi_name': 'network.usehttpproxy',
},
SETTINGS.PROXY_TYPE: {
'value': None,
'type': int,
'default': 0,
'kodi_name': 'network.httpproxytype',
},
SETTINGS.PROXY_SERVER: {
'value': None,
'type': str,
'default': '',
'kodi_name': 'network.httpproxyserver',
},
SETTINGS.PROXY_PORT: {
'value': None,
'type': int,
'default': 8080,
'kodi_name': 'network.httpproxyport',
},
SETTINGS.PROXY_USERNAME: {
'value': None,
'type': str,
'default': '',
'kodi_name': 'network.httpproxyusername',
},
SETTINGS.PROXY_PASSWORD: {
'value': None,
'type': str,
'default': '',
'kodi_name': 'network.httpproxypassword',
},
}

def proxy_settings(self, value=None, as_mapping=True):
if value is not None:
for setting_name, setting in value.items():
setting_value = setting.get('value')
if setting_value is None:
continue

setting_type = setting.get('type', int)
if setting_type is int:
self.set_int(setting_name, setting_value)
elif setting_type is str:
self.set_string(setting_name, setting_value)
else:
self.set_bool(setting_name, setting_value)
return value

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

settings = {}
for setting_name, setting in self._PROXY_SETTINGS.items():
setting_default = setting.get('default')
setting_type = setting.get('type', int)
if proxy_source == 1:
setting_value = get_kodi_setting_value(
setting.get('kodi_name'),
process=setting_type,
) or setting_default
elif setting_type is int:
setting_value = self.get_int(setting_name, setting_default)
elif setting_type is str:
setting_value = self.get_string(setting_name, setting_default)
else:
setting_value = self.get_bool(setting_name, setting_default)

settings[setting_name] = {
'value': setting_value,
'type': setting_type,
'default': setting_default,
}

if not as_mapping:
return settings

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

port = settings[SETTINGS.PROXY_PORT]['value']
if port:
host_port_string = ':'.join((host, str(port)))
else:
host_port_string = host

username = settings[SETTINGS.PROXY_USERNAME]['value']
if username:
password = settings[SETTINGS.PROXY_PASSWORD]['value']
if password:
auth_string = ':'.join((username, password))
else:
auth_string = username
auth_string += '@'
else:
auth_string = ''

proxy_string = ''.join((scheme, '://', auth_string, host_port_string))
return {
'http': proxy_string,
'https': proxy_string,
}

def allow_dev_keys(self):
return self.get_bool(SETTINGS.ALLOW_DEV_KEYS, False)

Expand Down
37 changes: 17 additions & 20 deletions resources/lib/youtube_plugin/youtube/helper/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,32 @@


def tv_videos_to_items(provider, context, json_data):
incognito = context.get_param('incognito')
settings = context.get_settings()
use_play_data = not incognito and settings.use_local_history()
item_filter = settings.item_filter()

item_params = {
'video_id': None,
}
if incognito:
if context.get_param('incognito'):
item_params['incognito'] = True

video_id_dict = {}
channel_item_dict = {}
channel_items_dict = {}

for item in json_data.get('items', []):
video_id = item['id']
item_params['video_id'] = video_id
video_item = VideoItem(
video_id_dict[video_id] = VideoItem(
item['title'], context.create_uri((PATHS.PLAY,), item_params)
)
if incognito:
video_item.set_play_count(0)
video_id_dict[video_id] = video_item

utils.update_video_infos(provider,
context,
video_id_dict,
channel_items_dict=channel_item_dict,
use_play_data=use_play_data,
item_filter=item_filter)
utils.update_fanarts(provider, context, channel_item_dict)

item_filter = context.get_settings().item_filter()

utils.update_video_infos(
provider,
context,
video_id_dict,
channel_items_dict=channel_items_dict,
item_filter=item_filter,
)
utils.update_fanarts(provider, context, channel_items_dict)

if item_filter:
result = utils.filter_videos(video_id_dict.values(), **item_filter)
Expand Down Expand Up @@ -80,7 +77,7 @@ def saved_playlists_to_items(provider, context, json_data):
title = item['title']
channel_id = item['channel_id']
playlist_id = item['id']
image = utils.get_thumbnail(thumb_size, item.get('thumbnails', {}))
image = utils.get_thumbnail(thumb_size, item.get('thumbnails'))

if channel_id:
item_uri = context.create_uri(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ def get_video_items(self, provider, context, skip_title=False):
if self._video_items:
return self._video_items

use_play_data = not context.get_param('incognito', False)

channel_id_dict = {}
utils.update_video_infos(provider, context, self._video_id_dict,
channel_items_dict=channel_id_dict,
use_play_data=use_play_data)
utils.update_video_infos(
provider,
context,
self._video_id_dict,
channel_items_dict=channel_id_dict,
)
utils.update_fanarts(provider, context, channel_id_dict)

self._video_items = [
Expand Down
Loading

0 comments on commit 6c14221

Please sign in to comment.