From 9a964aa0727ca03c9f89d430620e9d1284faf108 Mon Sep 17 00:00:00 2001 From: MoojMidge <56883549+MoojMidge@users.noreply.github.com> Date: Fri, 26 Apr 2024 07:36:09 +1000 Subject: [PATCH] Add Jump to page... context menu item to Next page item #715 - Will prompt for page of listing to jump to - Can also be used to jump directly to a page of a listing #317 - plugin://plugin.video.youtube/goto_page// --- .../resource.language.en_gb/strings.po | 4 +++ .../kodion/abstract_provider.py | 27 +++++++++++++++++++ .../kodion/constants/const_paths.py | 1 + .../kodion/context/xbmc/xbmc_context.py | 3 ++- .../youtube_plugin/kodion/items/menu_items.py | 10 +++++++ .../kodion/items/next_page_item.py | 16 ++++++----- .../youtube/helper/yt_playlist.py | 2 +- 7 files changed, 54 insertions(+), 9 deletions(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 80d336e8a..75b69e577 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -1528,3 +1528,7 @@ msgstr "" msgctxt "#30805" msgid "Use adaptive streaming formats with external player" msgstr "" + +msgctxt "#30806" +msgid "Jump to page..." +msgstr "" diff --git a/resources/lib/youtube_plugin/kodion/abstract_provider.py b/resources/lib/youtube_plugin/kodion/abstract_provider.py index 72414fef3..af9269b53 100644 --- a/resources/lib/youtube_plugin/kodion/abstract_provider.py +++ b/resources/lib/youtube_plugin/kodion/abstract_provider.py @@ -16,6 +16,7 @@ from .exceptions import KodionException from .items import ( DirectoryItem, + NextPageItem, NewSearchItem, SearchHistoryItem, ) @@ -42,6 +43,13 @@ def __init__(self): '(?P/[^?]+?)(?:/*[?].+|/*)$' )), self.reroute) + self.register_path(r''.join(( + '^', + paths.GOTO_PAGE, + '(?P/[0-9]+)?' + '(?P/[^?]+?)(?:/*[?].+|/*)$' + )), self._internal_goto_page) + self.register_path(r''.join(( '^', paths.WATCH_LATER, @@ -176,6 +184,25 @@ def on_root(self, context, re_match): def _internal_root(self, context, re_match): return self.on_root(context, re_match) + def _internal_goto_page(self, context, re_match): + page = re_match.group('page') + if page: + page = int(page.lstrip('/')) + else: + result, page = context.get_ui().on_numeric_input( + context.localize('page.choose'), 1 + ) + if not result: + return False + + path = re_match.group('path') + params = context.get_params() + page_token = NextPageItem.create_page_token( + page, params.get('items_per_page', 50) + ) + params = dict(params, page=page, page_token=page_token) + return self.reroute(context, path=path, params=params) + def reroute(self, context, re_match=None, path=None, params=None): if re_match: path = re_match.group('path') diff --git a/resources/lib/youtube_plugin/kodion/constants/const_paths.py b/resources/lib/youtube_plugin/kodion/constants/const_paths.py index 96dec3bdc..5791f26d3 100644 --- a/resources/lib/youtube_plugin/kodion/constants/const_paths.py +++ b/resources/lib/youtube_plugin/kodion/constants/const_paths.py @@ -13,6 +13,7 @@ BOOKMARKS = '/kodion/bookmarks' EXTERNAL_SEARCH = '/search' +GOTO_PAGE = '/kodion/goto_page' ROUTE = '/kodion/route' SEARCH = '/kodion/search' WATCH_LATER = '/kodion/watch_later' diff --git a/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py b/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py index eb5b9c099..8fbc11783 100644 --- a/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py +++ b/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py @@ -133,8 +133,9 @@ class XbmcContext(AbstractContext): 'my_subscriptions.filter.remove': 30588, 'my_subscriptions.filter.removed': 30590, 'my_subscriptions.filtered': 30584, - 'next_page': 30106, 'none': 30561, + 'page.next': 30106, + 'page.choose': 30806, 'playlist.added_to': 30714, 'playlist.create': 30522, 'playlist.play.all': 30531, diff --git a/resources/lib/youtube_plugin/kodion/items/menu_items.py b/resources/lib/youtube_plugin/kodion/items/menu_items.py index 0318235a8..0a1ec5638 100644 --- a/resources/lib/youtube_plugin/kodion/items/menu_items.py +++ b/resources/lib/youtube_plugin/kodion/items/menu_items.py @@ -559,3 +559,13 @@ def goto_quick_search(context): (paths.ROUTE, paths.SEARCH, 'input',), )) ) + + +def goto_page(context): + return ( + context.localize('page.choose'), + 'RunPlugin({0})'.format(context.create_uri( + (paths.GOTO_PAGE, context.get_path(),), + context.get_params(), + )) + ) diff --git a/resources/lib/youtube_plugin/kodion/items/next_page_item.py b/resources/lib/youtube_plugin/kodion/items/next_page_item.py index c1f0fb260..55886c9f7 100644 --- a/resources/lib/youtube_plugin/kodion/items/next_page_item.py +++ b/resources/lib/youtube_plugin/kodion/items/next_page_item.py @@ -19,25 +19,27 @@ def __init__(self, context, params, image=None, fanart=None): if 'refresh' in params: del params['refresh'] - self.next_page = params.get('page', 2) - self.items_per_page = params.pop('items_per_page', 50) + page = params.get('page', 2) + items_per_page = params.get('items_per_page', 50) if 'page_token' not in params: - params['page_token'] = self.calculate_next_page_token( - self.next_page, self.items_per_page - ) + params['page_token'] = self.create_page_token(page, items_per_page) super(NextPageItem, self).__init__( - context.localize('next_page') % self.next_page, + context.localize('page.next') % page, context.create_uri(context.get_path(), params), image=image, category_label='__inherit__', ) + self.next_page = page + self.items_per_page = items_per_page + if fanart: self.set_fanart(fanart) context_menu = [ menu_items.refresh(context), + menu_items.goto_page(context), menu_items.goto_home(context), menu_items.goto_quick_search(context), menu_items.separator(), @@ -45,7 +47,7 @@ def __init__(self, context, params, image=None, fanart=None): self.set_context_menu(context_menu) @classmethod - def calculate_next_page_token(cls, page, items_per_page): + def create_page_token(cls, page, items_per_page=50): low = 'AEIMQUYcgkosw048' high = 'ABCDEFGHIJKLMNOP' len_low = len(low) diff --git a/resources/lib/youtube_plugin/youtube/helper/yt_playlist.py b/resources/lib/youtube_plugin/youtube/helper/yt_playlist.py index 6d49d1c50..eb22e0d18 100644 --- a/resources/lib/youtube_plugin/youtube/helper/yt_playlist.py +++ b/resources/lib/youtube_plugin/youtube/helper/yt_playlist.py @@ -223,7 +223,7 @@ def _process_select_playlist(provider, context): if page_token: next_page = current_page + 1 items.append(( - ui.bold(context.localize('next_page') % next_page), '', + ui.bold(context.localize('page.next') % next_page), '', 'playlist.next', 'DefaultFolder.png', ))