Move get_search_suggestions from browsing to search.

This commit is contained in:
Om Gupta 2023-04-05 11:21:05 +05:30 • committed by sigma67
commit 4fdad5be04
4 changed files with 115 additions and 112 deletions

View file

@ -198,3 +198,25 @@ def get_search_params(filter, scope, ignore_spelling):
def _get_param2(filter):
filter_params = {'songs': 'I', 'videos': 'Q', 'albums': 'Y', 'artists': 'g', 'playlists': 'o'}
return filter_params[filter]
def parse_search_suggestions(results, detailed_runs):
if not results.get('contents', [{}])[0].get('searchSuggestionsSectionRenderer', {}).get(
'contents', []):
return []
raw_suggestions = results['contents'][0]['searchSuggestionsSectionRenderer']['contents']
suggestions = []
for raw_suggestion in raw_suggestions:
suggestion_content = raw_suggestion['searchSuggestionRenderer']
text = suggestion_content['navigationEndpoint']['searchEndpoint']['query']
runs = suggestion_content['suggestion']['runs']
if detailed_runs:
suggestions.append({'text': text, 'runs': runs})
else:
suggestions.append(text)
return suggestions