Skip to content

Commit

Permalink
Add Jump to page... context menu item to Next page item anxdpanic#715
Browse files Browse the repository at this point in the history
- Will prompt for page of listing to jump to
- Can also be used to jump directly to a page of a listing anxdpanic#317
  - plugin://plugin.video.youtube/goto_page/<PAGE>/<PATH>
  • Loading branch information
MoojMidge committed Apr 28, 2024
1 parent e559d53 commit 476f396
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 9 deletions.
4 changes: 4 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -1528,3 +1528,7 @@ msgstr ""
msgctxt "#30805"
msgid "Use adaptive streaming formats with external player"
msgstr ""

msgctxt "#30806"
msgid "Jump to page..."
msgstr ""
27 changes: 27 additions & 0 deletions resources/lib/youtube_plugin/kodion/abstract_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .exceptions import KodionException
from .items import (
DirectoryItem,
NextPageItem,
NewSearchItem,
SearchHistoryItem,
)
Expand All @@ -42,6 +43,13 @@ def __init__(self):
'(?P<path>/[^?]+?)(?:/*[?].+|/*)$'
)), self.reroute)

self.register_path(r''.join((
'^',
paths.GOTO_PAGE,
'(?P<page>/[0-9]+)?'
'(?P<path>/[^?]+?)(?:/*[?].+|/*)$'
)), self._internal_goto_page)

self.register_path(r''.join((
'^',
paths.WATCH_LATER,
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions resources/lib/youtube_plugin/kodion/items/menu_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
))
)
16 changes: 9 additions & 7 deletions resources/lib/youtube_plugin/kodion/items/next_page_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,35 @@ 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(),
]
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)
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/youtube_plugin/youtube/helper/yt_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
))
Expand Down

0 comments on commit 476f396

Please sign in to comment.