Skip to content

Commit

Permalink
Fallback to search listing when search query is empty
Browse files Browse the repository at this point in the history
- Also ensure correct category label is used when navigating back to search listing
  • Loading branch information
MoojMidge committed Nov 5, 2024
1 parent bf17d8c commit f026248
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
12 changes: 8 additions & 4 deletions resources/lib/youtube_plugin/kodion/abstract_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def on_bookmarks(provider, context, re_match):
def on_watch_later(provider, context, re_match):
raise NotImplementedError()

def on_search_run(self, context, search_text):
def on_search_run(self, context, query):
raise NotImplementedError()

@staticmethod
Expand All @@ -333,7 +333,10 @@ def on_search(provider, context, re_match):

if not command or command == 'query':
query = to_unicode(params.get('q', ''))
return provider.on_search_run(context=context, search_text=query)
if query:
return provider.on_search_run(context=context, query=query)
command = 'list'
context.set_path(PATHS.SEARCH, command)

if command == 'remove':
query = to_unicode(params.get('q', ''))
Expand Down Expand Up @@ -383,11 +386,12 @@ def on_search(provider, context, re_match):

context.set_path(PATHS.SEARCH, 'query')
return (
provider.on_search_run(context=context, search_text=query),
provider.on_search_run(context=context, query=query),
{provider.RESULT_CACHE_TO_DISC: command != 'input_prompt'},
)

context.set_content(CONTENT.LIST_CONTENT)
context.set_content(CONTENT.LIST_CONTENT,
category_label=context.localize('search'))
result = []

location = context.get_param('location', False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def get_items(self, process=None):
return result

@staticmethod
def _make_id(search_text):
return md5(search_text.encode('utf-8')).hexdigest()
def _make_id(query):
return md5(query.encode('utf-8')).hexdigest()

def add_item(self, query):
if isinstance(query, dict):
Expand Down
26 changes: 12 additions & 14 deletions resources/lib/youtube_plugin/youtube/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,25 +785,23 @@ def _search_channel_or_playlist(self, context, identifier):
return v3.response_to_items(self, context, json_data)
return False

def on_search_run(self, context, search_text):
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 search_text.startswith(('https://', 'http://')):
return self.on_uri2addon(provider=self,
context=context,
uri=search_text)
if context.is_plugin_path(search_text):
return UriItem(search_text)

result = self._search_channel_or_playlist(context, search_text)
if result: # found a channel or playlist matching search_text
if query.startswith(('https://', 'http://')):
return self.on_uri2addon(provider=self, context=context, uri=query)
if context.is_plugin_path(query):
return UriItem(query)

result = self._search_channel_or_playlist(context, query)
if result: # found a channel or playlist matching search query
return result
result = []

context.set_param('q', search_text)
context.set_param('category_label', search_text)
context.set_param('q', query)
context.set_param('category_label', query)

params = context.get_params()
channel_id = params.get('channel_id') or params.get('channelId')
Expand Down Expand Up @@ -899,7 +897,7 @@ def on_search_run(self, context, search_text):
result.append(completed_item)

search_params = {
'q': search_text,
'q': query,
'channelId': channel_id,
'type': search_type,
'eventType': event_type,
Expand All @@ -925,7 +923,7 @@ def on_search_run(self, context, search_text):
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', search_text)
data_cache.set_item('search_query', query)

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

0 comments on commit f026248

Please sign in to comment.