(query: str)
return suggestions
Returns a list of suggestions for the given query from Youtube.
Returns a list of suggestions for the given query from Youtube.
Returns a list of suggestions for the given query from Youtube .
def get_search_suggestions(query: str) -> List[str]:
        """Returns a list of suggestions for the given query from Youtube."""
        with youtube_session() as session:
            params = {
                "client": "youtube",
                "q": query[:100],  # queries longer than 100 characters are not accepted
                "xhr": "t",  # this makes the response be a json file
            }
            response = session.get(
                "https://clients1.google.com/complete/search", params=params
            )
        suggestions = json.loads(response.text)
        # first entry is the query, the second one contains the suggestions
        suggestions = suggestions[1]
        # suggestions are given as tuples
        # extract the string and skip the query if it occurs identically
        suggestions = [
            entry[0]
            for entry in suggestions
            if entry[0] != query and not song_utils.is_forbidden(entry[0])
        ]
        return suggestions
def get_search_suggestions ( query : str ) -> List [ str ] : with youtube_session ( ) as session : params = { "client" : "youtube" , "q" : query [ : 100 ] , # queries longer than 100 characters are not accepted "xhr" : "t" , # this makes the response be a json file } response = session . get ( "https://clients1.google.com/complete/search" , params = params ) suggestions = json . loads ( response . text ) # first entry is the query, the second one contains the suggestions suggestions = suggestions [ 1 ] # suggestions are given as tuples # extract the string and skip the query if it occurs identically suggestions = [ entry [ 0 ] for entry in suggestions if entry [ 0 ] != query and not song_utils . is_forbidden ( entry [ 0 ] ) ] return suggestions