From 89f2ee91c5e0ec9abdab1a26e0f99b7fd108857b Mon Sep 17 00:00:00 2001 From: sigma67 Date: Sun, 31 Dec 2023 13:15:53 +0100 Subject: [PATCH] remove optional param --- tests/test.py | 6 ++---- ytmusicapi/mixins/search.py | 8 ++------ ytmusicapi/parsers/search.py | 11 +++++------ 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/tests/test.py b/tests/test.py index 3a6d468d..e9a7f4b1 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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 diff --git a/ytmusicapi/mixins/search.py b/ytmusicapi/mixins/search.py index 8480754f..783a48b3 100644 --- a/ytmusicapi/mixins/search.py +++ b/ytmusicapi/mixins/search.py @@ -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 @@ -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``:: @@ -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 diff --git a/ytmusicapi/parsers/search.py b/ytmusicapi/parsers/search.py index af6d10e4..05bde37c 100644 --- a/ytmusicapi/parsers/search.py +++ b/ytmusicapi/parsers/search.py @@ -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 [] @@ -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)