Skip to content

Commit

Permalink
Search issue 494 (#495)
Browse files Browse the repository at this point in the history
* search_suggestions: fix handle history when authenticated

* search_suggestions: test historical option does something

* remove optional param

---------

Co-authored-by: sigma67 <[email protected]>
  • Loading branch information
jcbirdwell and sigma67 authored Dec 31, 2023
1 parent 1fd93dc commit 1971121
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ def test_get_search_suggestions(self):
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
################
Expand Down
9 changes: 7 additions & 2 deletions ytmusicapi/parsers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 1971121

Please sign in to comment.