Search issue 494 (#495)

* search_suggestions: fix handle history when authenticated

* search_suggestions: test historical option does something

* remove optional param

---------

Co-authored-by: sigma67 <ytmusicapi@gmail.com>
This commit is contained in:
John Birdwell 2023-12-31 06:16:48 -06:00 • committed by GitHub
commit 1971121add
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -322,6 +322,15 @@ class TestYTMusic(unittest.TestCase):
result = self.yt.get_search_suggestions("fade", detailed_runs=True)
self.assertGreaterEqual(len(result), 0)
# add search term to history
first_pass = self.yt_auth.search("b")
self.assertGreater(len(first_pass), 0)
# get results
results = self.yt_auth.get_search_suggestions("b", detailed_runs=True)
self.assertGreater(len(results), 0)
self.assertTrue(any(item["fromHistory"] for item in results))
self.assertTrue(any(not item["fromHistory"] for item in results))
################
# EXPLORE
################

View file

@ -219,13 +219,18 @@ def parse_search_suggestions(results, detailed_runs):
suggestions = []
for raw_suggestion in raw_suggestions:
suggestion_content = raw_suggestion["searchSuggestionRenderer"]
if "historySuggestionRenderer" in raw_suggestion:
suggestion_content = raw_suggestion["historySuggestionRenderer"]
from_history = True
else:
suggestion_content = raw_suggestion["searchSuggestionRenderer"]
from_history = False
text = suggestion_content["navigationEndpoint"]["searchEndpoint"]["query"]
runs = suggestion_content["suggestion"]["runs"]
if detailed_runs:
suggestions.append({"text": text, "runs": runs})
suggestions.append({"text": text, "runs": runs, "fromHistory": from_history})
else:
suggestions.append(text)