Skip to content

Commit

Permalink
remove optional param
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Dec 31, 2023
1 parent 8495df0 commit 89f2ee9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
6 changes: 2 additions & 4 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,14 @@ def test_get_search_suggestions(self):
result = self.yt.get_search_suggestions("fade", detailed_runs=True)
self.assertGreaterEqual(len(result), 0)

def test_auth_search_suggestions(self):
# 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)
# get more results
historical = self.yt_auth.get_search_suggestions("b", detailed_runs=True, include_history=True)
self.assertGreater(len(historical), len(results))
self.assertTrue(any(item["fromHistory"] for item in results))
self.assertTrue(any(not item["fromHistory"] for item in results))

################
# EXPLORE
Expand Down
8 changes: 2 additions & 6 deletions ytmusicapi/mixins/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ def parse_func(contents):

return search_results

def get_search_suggestions(
self, query: str, detailed_runs=False, include_history=False
) -> Union[List[str], List[Dict]]:
def get_search_suggestions(self, query: str, detailed_runs=False) -> Union[List[str], List[Dict]]:
"""
Get Search Suggestions
Expand All @@ -265,8 +263,6 @@ def get_search_suggestions(
suggestion along with the complete text (like many search services
usually bold the text typed by the user).
Default: False, returns the list of search suggestions in plain text.
:param include_history: Whether to return suggestions based on historical/previously
searched items. Only relevant to detailed_runs.
:return: List of search suggestion results depending on ``detailed_runs`` param.
Example response when ``query`` is 'fade' and ``detailed_runs`` is set to ``False``::
Expand Down Expand Up @@ -328,6 +324,6 @@ def get_search_suggestions(
endpoint = "music/get_search_suggestions"

response = self._send_request(endpoint, body)
search_suggestions = parse_search_suggestions(response, detailed_runs, include_history)
search_suggestions = parse_search_suggestions(response, detailed_runs)

return search_suggestions
11 changes: 5 additions & 6 deletions ytmusicapi/parsers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _get_param2(filter):
return filter_params[filter]


def parse_search_suggestions(results, detailed_runs, history):
def parse_search_suggestions(results, detailed_runs):
if not results.get("contents", [{}])[0].get("searchSuggestionsSectionRenderer", {}).get("contents", []):
return []

Expand All @@ -220,18 +220,17 @@ def parse_search_suggestions(results, detailed_runs, history):

for raw_suggestion in raw_suggestions:
if "historySuggestionRenderer" in raw_suggestion:
if history:
suggestion_content = raw_suggestion["historySuggestionRenderer"]
else:
continue
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 89f2ee9

Please sign in to comment.