Skip to content

Commit 5e0d4f8

Browse files
authored
Merge pull request #1423 from MoojMidge/v7.4
v7.4.2+beta.2
2 parents 2d1504d + fd31302 commit 5e0d4f8

8 files changed

Lines changed: 100 additions & 59 deletions

File tree

addon.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="plugin.video.youtube" name="YouTube" version="7.4.2+beta.1" provider-name="anxdpanic, bromix, MoojMidge">
2+
<addon id="plugin.video.youtube" name="YouTube" version="7.4.2+beta.2" provider-name="anxdpanic, bromix, MoojMidge">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="script.module.requests" version="2.27.1"/>

changelog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v7.4.2+beta.2
2+
### Fixed
3+
- Ensure updated context is used in client instance when rerouting to existing provider handler methods #1418
4+
- Fix required ID potentially not being passed to YouTubeDataClient.(add|remove)_video_from_playlist() #1418
5+
6+
### Changed
7+
- Update parsing of plugin urls for path params and ID lists #1418
8+
19
## v7.4.2+beta.1
210
### Fixed
311
- Skip unplayable live manifests #1377

resources/lib/youtube_plugin/kodion/abstract_provider.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,34 +312,38 @@ def reroute(self, context, path=None, params=None, uri=None):
312312
self.log.debug('Rerouting - Fallback route not required')
313313
return False, {self.FALLBACK: False}
314314

315-
refresh = context.refresh_requested(params=params)
315+
new_context = context.clone(
316+
new_path=path,
317+
new_params=params,
318+
)
319+
320+
refresh = new_context.refresh_requested()
316321
if (refresh or (
317322
params == current_params
318323
and path.rstrip('/') == current_path.rstrip('/')
319324
)):
320325
if refresh and refresh < 0:
321326
del params['refresh']
322327
else:
323-
params['refresh'] = context.refresh_requested(
328+
params['refresh'] = new_context.refresh_requested(
324329
force=True,
325330
on=True,
326-
params=params,
327331
)
328332
else:
329333
params['refresh'] = 0
330334

331335
result = None
332-
uri = context.create_uri(path, params)
336+
uri = new_context.get_uri()
333337
if window_cache:
334338
function_cache = context.get_function_cache()
335339
with ui.on_busy():
336340
result, options = function_cache.run(
337341
self.navigate,
338342
_refresh=True,
339343
_scope=function_cache.SCOPE_NONE,
340-
context=context.clone(path, params),
344+
context=new_context,
341345
)
342-
if not result:
346+
if not result and not isinstance(result, (tuple, list)):
343347
self.log.debug(('No results', 'URI: %s'), uri)
344348
return False
345349

resources/lib/youtube_plugin/kodion/context/abstract_context.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ class AbstractContext(object):
184184
))
185185
_NON_EMPTY_STRING_PARAMS = set()
186186

187+
_PATH_PARAMS = {
188+
'channel': CHANNEL_ID,
189+
'playlist': PLAYLIST_ID,
190+
}
191+
187192
def __init__(self, path='/', params=None, plugin_id=''):
188193
self._access_manager = None
189194
self._uuid = None
@@ -205,7 +210,7 @@ def __init__(self, path='/', params=None, plugin_id=''):
205210
self._version = 'UNKNOWN'
206211

207212
self._param_string = ''
208-
self._params = params or {}
213+
self._params = {}
209214
if params:
210215
self.parse_params(params)
211216

@@ -511,9 +516,8 @@ def set_path(self, *path, **kwargs):
511516
parts = kwargs.get('parts')
512517
path = unquote(path[0])
513518
if parts is None:
514-
path = path.split('/')
515519
path, parts = self.create_path(
516-
*path,
520+
*path.split('/'),
517521
parts=True,
518522
parser=kwargs.get('parser')
519523
)
@@ -525,6 +529,8 @@ def set_path(self, *path, **kwargs):
525529
if kwargs.get('update_uri', True):
526530
self.update_uri()
527531

532+
return path
533+
528534
def get_original_params(self):
529535
return self._param_string
530536

@@ -537,19 +543,42 @@ def get_param(self, name, default=None):
537543
def pop_param(self, name, default=None):
538544
return self._params.pop(name, default)
539545

540-
def parse_uri(self, uri, parse_params=True, update=False):
546+
@classmethod
547+
def parse_path(cls, path):
548+
params = {}
549+
path_params = cls._PATH_PARAMS
550+
path = path.rstrip('/')
551+
while path:
552+
param, _, next_part = path.partition('/')
553+
if not next_part:
554+
break
555+
556+
if param in path_params:
557+
value = next_part.partition('/')[0]
558+
if value:
559+
params[path_params[param]] = value
560+
561+
path = next_part
562+
563+
return params
564+
565+
def parse_uri(self, uri, parse_params=True, parse_path=True, update=False):
541566
uri = urlsplit(uri)
542567
path = uri.path
543-
if parse_params:
544-
params = self.parse_params(
545-
dict(parse_qsl(uri.query, keep_blank_values=True)),
546-
update=False,
547-
)
548-
if update:
549-
self._params = params
550-
self.set_path(path)
551-
else:
552-
params = uri.query
568+
if not parse_params:
569+
return path, uri.query
570+
571+
params = dict(parse_qsl(uri.query, keep_blank_values=True))
572+
573+
if parse_path:
574+
params.update(self.parse_path(path))
575+
576+
params = self.parse_params(params, update=False)
577+
578+
if update:
579+
self._params = params
580+
self.set_path(path)
581+
553582
return path, params
554583

555584
def parse_params(self, params, update=True, parser=None):

resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
FOLDER_NAME,
3535
FOLDER_URI,
3636
PLAYLIST_ID,
37+
PLAYLIST_IDS,
3738
PLAY_FORCE_AUDIO,
3839
SERVICE_IPC,
3940
SERVICE_RUNNING_FLAG,
4041
SORT,
4142
URI,
4243
VIDEO_ID,
44+
VIDEO_IDS,
4345
)
4446
from ...json_store import APIKeyStore, AccessManager
4547
from ...player import XbmcPlaylistPlayer
@@ -477,29 +479,34 @@ def init(self):
477479
self._plugin_handle = -1
478480
return
479481

482+
self._param_string = ''
483+
self._params = {}
484+
480485
# first the path of the uri
481-
self.set_path(
486+
path = self.set_path(
482487
urlsplit(uri).path,
483488
force=True,
484489
parser=XbmcContextUI.get_infolabel,
485490
update_uri=False,
486491
)
492+
params = self.parse_path(path)
487493

488494
# after that try to get the params
489495
if num_args > 2:
490-
params = to_unicode(sys.argv[2][1:])
491-
self._param_string = params
492-
self._params = {}
493-
if params:
494-
self.parse_params(
495-
dict(parse_qsl(params, keep_blank_values=True)),
496-
parser=XbmcContextUI.get_infolabel,
497-
)
496+
_params = to_unicode(sys.argv[2][1:])
497+
if _params:
498+
self._param_string = _params
499+
params.update(dict(parse_qsl(_params, keep_blank_values=True)))
498500

499501
# then Kodi resume status
500502
if num_args > 3 and sys.argv[3].lower() == 'resume:true':
501-
self._params['resume'] = True
503+
params['resume'] = True
502504

505+
if params:
506+
self.parse_params(
507+
params,
508+
parser=XbmcContextUI.get_infolabel,
509+
)
503510
self.update_uri()
504511

505512
def get_region(self):
@@ -1120,35 +1127,24 @@ def refresh_requested(self, force=False, on=False, off=False, params=None):
11201127
def parse_item_ids(self,
11211128
uri='',
11221129
from_listitem=True,
1123-
_ids={'video': VIDEO_ID,
1124-
'channel': CHANNEL_ID,
1125-
'playlist': PLAYLIST_ID}):
1126-
item_ids = {}
1130+
_ids=(VIDEO_ID,
1131+
VIDEO_IDS,
1132+
CHANNEL_ID,
1133+
# CHANNEL_IDS, # not currently supported
1134+
PLAYLIST_ID,
1135+
PLAYLIST_IDS)):
11271136
if not uri and from_listitem:
11281137
uri = XbmcContextUI.get_listitem_info(URI)
11291138
if not uri or not self.is_plugin_path(uri):
1130-
return item_ids
1131-
uri = urlsplit(uri)
1139+
return {}
11321140

1133-
path = uri.path.rstrip('/')
1134-
while path:
1135-
id_type, _, next_part = path.partition('/')
1136-
if not next_part:
1137-
break
1138-
1139-
if id_type in _ids:
1140-
id_value = next_part.partition('/')[0]
1141-
if id_value:
1142-
item_ids[_ids[id_type]] = id_value
1143-
1144-
path = next_part
1145-
1146-
params = dict(parse_qsl(uri.query))
1147-
for name in _ids.values():
1148-
id_value = params.get(name)
1149-
if not id_value and from_listitem:
1150-
id_value = XbmcContextUI.get_listitem_property(name)
1151-
if id_value:
1152-
item_ids[name] = id_value
1141+
uri = urlsplit(uri)
1142+
item_ids = self.parse_path(uri.path)
1143+
_params = dict(parse_qsl(uri.query))
1144+
_prop = XbmcContextUI.get_listitem_property if from_listitem else False
1145+
for name in _ids:
1146+
value = _params.get(name) or _prop and _prop(name)
1147+
if value:
1148+
item_ids[name] = value
11531149

11541150
return item_ids

resources/lib/youtube_plugin/kodion/monitors/player_monitor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ def run(self):
291291
command='remove',
292292
category='video',
293293
playlist_id=watch_later_id,
294-
video_id=playlist_item_id,
294+
video_id=video_id,
295+
playlist_item_id=playlist_item_id,
295296
video_name='',
296297
confirmed=True,
297298
)

resources/lib/youtube_plugin/kodion/network/requests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ def init(cls,
218218
def reinit(self, **kwargs):
219219
self.__init__(**kwargs)
220220

221+
def context_changed(self, context):
222+
return self._context != context
223+
221224
def __enter__(self):
222225
return self
223226

resources/lib/youtube_plugin/youtube/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def get_client(self, context, refresh=False):
222222
_,
223223
) = access_manager.get_access_tokens(dev_id)
224224

225-
if client:
225+
if client and not client.context_changed(context):
226226
if api_last_origin != origin:
227227
access_manager.set_last_origin(origin)
228228
self.log.info(('API key origin changed - Resetting client',

0 commit comments

Comments
 (0)