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:
parent
1fd93dcfb6
commit
1971121add
2 changed files with 16 additions and 2 deletions
|
|
@ -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
|
||||
################
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue