Skip to content

Commit

Permalink
Improve handling of search keyboard input when navigating through win…
Browse files Browse the repository at this point in the history
…dow history

- Also allow bookmarks/favourites to be created for Quick Search
- Remove need to store search query in data cache
  • Loading branch information
MoojMidge committed Dec 18, 2024
1 parent 33db289 commit c92298f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
24 changes: 11 additions & 13 deletions resources/lib/youtube_plugin/kodion/abstract_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,17 @@ def on_search(provider, context, re_match):
query = None
# came from page 1 of search query by '..'/back
# user doesn't want to input on this path
old_path = context.get_infolabel('Container.FolderPath')
if (not params.get('refresh')
and context.is_plugin_path(
context.get_infolabel('Container.FolderPath'),
((PATHS.SEARCH, 'query',),
(PATHS.SEARCH, 'input',)),
)):
data_cache = context.get_data_cache()
cached = data_cache.get_item('search_query', data_cache.ONE_DAY)
if cached:
query = to_unicode(cached)
else:
and context.is_plugin_folder()
and context.is_plugin_path(old_path)):
old_path, old_params = context.parse_uri(old_path)
if old_path.startswith(PATHS.SEARCH):
query = old_params.get('q', False)

if query:
query = to_unicode(query)
elif query is None:
result, input_query = ui.on_keyboard_input(
localize('search.title')
)
Expand All @@ -425,9 +425,7 @@ def on_search(provider, context, re_match):
context.set_path(PATHS.SEARCH, 'query')
result, options = provider.on_search_run(context, query=query)
if not options:
options = {
provider.RESULT_CACHE_TO_DISC: command != 'input_prompt',
}
options = {provider.RESULT_CACHE_TO_DISC: False}
return result, options

context.set_content(CONTENT.LIST_CONTENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,3 +907,8 @@ def wakeup(self, target, timeout=None, payload=None):
self.log_error('Wakeup |{0}| timed out in {1}ms'
.format(target, timeout))
return False

def is_plugin_folder(self, folder_name=None):
if folder_name is None:
folder_name = xbmc.getInfoLabel('Container.FolderName')
return folder_name == self._plugin_name
11 changes: 3 additions & 8 deletions resources/lib/youtube_plugin/youtube/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,9 +867,6 @@ def _search_channel_or_playlist(self,
return None

def on_search_run(self, context, query):
data_cache = context.get_data_cache()
data_cache.del_item('search_query')

# Search by url to access unlisted videos
if query.startswith(('https://', 'http://')):
return self.on_uri2addon(provider=self, context=context, uri=query)
Expand Down Expand Up @@ -1000,11 +997,9 @@ def on_search_run(self, context, query):
if not json_data:
return False, None

# Store current search query for Kodi window history navigation
if not params.get('incognito'):
if not params.get('channel_id'):
context.get_search_history().add_item(search_params)
data_cache.set_item('search_query', query)
# Store current search query
if not params.get('incognito') and not params.get('channel_id'):
context.get_search_history().add_item(search_params)

result.extend(v3.response_to_items(
self, context, json_data,
Expand Down

0 comments on commit c92298f

Please sign in to comment.