ytmusicapi/mixins/browsing.py
def search(self,
               query: str,
               filter: str = None,
               limit: int = 20,
               ignore_spelling: bool = False) -> List[Dict]:
        """
        Search YouTube music
        Returns results within the provided category.

        :param query: Query string, i.e. 'Oasis Wonderwall'
        :param filter: Filter for item types. Allowed values:
          'songs', 'videos', 'albums', 'artists', 'playlists', 'uploads'.
          Default: Default search, including all types of items.
        :param limit: Number of search results to return
          Default: 20
        :param ignore_spelling: Whether to ignore YTM spelling suggestions.
          If True, the exact search term will be searched for, and will not be corrected.
          This does not have any effect when the filter is set to 'uploads'.
          Default: False, will use YTM's default behavior of autocorrecting the search.
        :return: List of results depending on filter.
          resultType specifies the type of item (important for default search).
          albums, artists and playlists additionally contain a browseId, corresponding to
          albumId, channelId and playlistId (browseId='VL'+playlistId)

          Example list::

            [
              {
                "videoId": "ZrOKjDZOtkA",
                "title": "Wonderwall (Remastered)",
                "artists": [
                  {
                    "name": "Oasis",
                    "id": "UCmMUZbaYdNH0bEd1PAlAqsA"
                  }
                ],
                "album": {
                  "name": "(What's The Story) Morning Glory? (Remastered)",
                  "id": "MPREb_9nqEki4ZDpp"
                },
                "duration": "4:19",
                "thumbnails": [...],
                "resultType": "song"
              }
            ]
        """
        body = {'query': query}
        endpoint = 'search'
        search_results = []
        filters = ['albums', 'artists', 'playlists', 'songs', 'videos', 'uploads']
        if filter and filter not in filters:
            raise Exception(
                "Invalid filter provided. Please use one of the following filters or leave out the parameter: "
                + ', '.join(filters))

        if filter:
            param1 = 'Eg-KAQwIA'

            if not ignore_spelling:
                param3 = 'MABqChAEEAMQCRAFEAo%3D'
            else:
                param3 = 'MABCAggBagoQBBADEAkQBRAK'

            if filter == 'uploads':
                params = 'agIYAw%3D%3D'
            else:
                if filter == 'videos':
                    param2 = 'BABGAAgACgA'
                elif filter == 'albums':
                    param2 = 'BAAGAEgACgA'
                elif filter == 'artists':
                    param2 = 'BAAGAAgASgA'
                elif filter == 'playlists':
                    param2 = 'BAAGAAgACgB'
                elif filter == 'uploads':
                    self.__check_auth()
                    param2 = 'RABGAEgASgB'
                else:
                    param2 = 'RAAGAAgACgA'
                params = param1 + param2 + param3

            body['params'] = params
        elif ignore_spelling:
            body['params'] = "QgIIAQ%3D%3D"

        response = self._send_request(endpoint, body)

        # no results
        if 'contents' not in response:
            return search_results

        if 'tabbedSearchResultsRenderer' in response['contents']:
            results = response['contents']['tabbedSearchResultsRenderer']['tabs'][int(
                filter == "uploads")]['tabRenderer']['content']
        else:
            results = response['contents']

        results = nav(results, SECTION_LIST)

        # no results
        if len(results) == 1 and 'itemSectionRenderer' in results:
            return search_results

        for res in results:
            if 'musicShelfRenderer' in res:
                results = res['musicShelfRenderer']['contents']

                type = filter[:-1] if filter else None
                search_results.extend(self.parser.parse_search_results(results, type))

                if 'continuations' in res['musicShelfRenderer']:
                    request_func = lambda additionalParams: self._send_request(
                        endpoint, body, additionalParams)

                    parse_func = lambda contents: self.parser.parse_search_results(contents, type)

                    search_results.extend(
                        get_continuations(res['musicShelfRenderer'], 'musicShelfContinuation',
                                          limit - len(search_results), request_func, parse_func))

        return search_results

        Search YouTube music
        Returns results within the provided category.

        :param query: Query string, i.e. 'Oasis Wonderwall'
        :param filter: Filter for item types. Allowed values:
          'songs', 'videos', 'albums', 'artists', 'playlists', 'uploads'.
          Default: Default search, including all types of items.
        :param limit: Number of search results to return
          Default: 20
        :param ignore_spelling: Whether to ignore YTM spelling suggestions.
          If True, the exact search term will be searched for, and will not be corrected.
          This does not have any effect when the filter is set to 'uploads'.
          Default: False, will use YTM's default behavior of autocorrecting the search.
        :return: List of results depending on filter.
          resultType specifies the type of item (important for default search).
          albums, artists and playlists additionally contain a browseId, corresponding to
          albumId, channelId and playlistId (browseId='VL'+playlistId)

          Example list::

            [
              {
                "videoId": "ZrOKjDZOtkA",
                "title": "Wonderwall (Remastered)",
                "artists": [
                  {
                    "name": "Oasis",
                    "id": "UCmMUZbaYdNH0bEd1PAlAqsA"
                  }
                ],
                "album": {
                  "name": "(What's The Story) Morning Glory? (Remastered)",
                  "id": "MPREb_9nqEki4ZDpp"
                },
                "duration": "4:19",
                "thumbnails": [...],
                "resultType": "song"
              }
            ]
        
Search YouTube music
Returns results within the provided category.
Search YouTube music Returns results within the provided category .
def search(self,
               query: str,
               filter: str = None,
               limit: int = 20,
               ignore_spelling: bool = False) -> List[Dict]:
        body = {'query': query}
        endpoint = 'search'
        search_results = []
        filters = ['albums', 'artists', 'playlists', 'songs', 'videos', 'uploads']
        if filter and filter not in filters:
            raise Exception(
                "Invalid filter provided. Please use one of the following filters or leave out the parameter: "
                + ', '.join(filters))
        if filter:
            param1 = 'Eg-KAQwIA'
            if not ignore_spelling:
                param3 = 'MABqChAEEAMQCRAFEAo%3D'
            else:
                param3 = 'MABCAggBagoQBBADEAkQBRAK'
            if filter == 'uploads':
                params = 'agIYAw%3D%3D'
            else:
                if filter == 'videos':
                    param2 = 'BABGAAgACgA'
                elif filter == 'albums':
                    param2 = 'BAAGAEgACgA'
                elif filter == 'artists':
                    param2 = 'BAAGAAgASgA'
                elif filter == 'playlists':
                    param2 = 'BAAGAAgACgB'
                elif filter == 'uploads':
                    self.__check_auth()
                    param2 = 'RABGAEgASgB'
                else:
                    param2 = 'RAAGAAgACgA'
                params = param1 + param2 + param3
            body['params'] = params
        elif ignore_spelling:
            body['params'] = "QgIIAQ%3D%3D"
        response = self._send_request(endpoint, body)
        if 'contents' not in response:
            return search_results
        if 'tabbedSearchResultsRenderer' in response['contents']:
            results = response['contents']['tabbedSearchResultsRenderer']['tabs'][int(
                filter == "uploads")]['tabRenderer']['content']
        else:
            results = response['contents']
        results = nav(results, SECTION_LIST)
        if len(results) == 1 and 'itemSectionRenderer' in results:
            return search_results
        for res in results:
            if 'musicShelfRenderer' in res:
                results = res['musicShelfRenderer']['contents']
                type = filter[:-1] if filter else None
                search_results.extend(self.parser.parse_search_results(results, type))
                if 'continuations' in res['musicShelfRenderer']:
                    request_func = lambda additionalParams: self._send_request(
                        endpoint, body, additionalParams)
                    parse_func = lambda contents: self.parser.parse_search_results(contents, type)
                    search_results.extend(
                        get_continuations(res['musicShelfRenderer'], 'musicShelfContinuation',
                                          limit - len(search_results), request_func, parse_func))
        return search_results
def search ( self , query : str , filter : str = None , limit : int = 20 , ignore_spelling : bool = False ) -> List [ Dict ] : body = { 'query' : query } endpoint = 'search' search_results = [ ] filters = [ 'albums' , 'artists' , 'playlists' , 'songs' , 'videos' , 'uploads' ] if filter and filter not in filters : raise Exception ( "Invalid filter provided. Please use one of the following filters or leave out the parameter: " + ', ' . join ( filters ) ) if filter : param1 = 'Eg-KAQwIA' if not ignore_spelling : param3 = 'MABqChAEEAMQCRAFEAo%3D' else : param3 = 'MABCAggBagoQBBADEAkQBRAK' if filter == 'uploads' : params = 'agIYAw%3D%3D' else : if filter == 'videos' : param2 = 'BABGAAgACgA' elif filter == 'albums' : param2 = 'BAAGAEgACgA' elif filter == 'artists' : param2 = 'BAAGAAgASgA' elif filter == 'playlists' : param2 = 'BAAGAAgACgB' elif filter == 'uploads' : self . __check_auth ( ) param2 = 'RABGAEgASgB' else : param2 = 'RAAGAAgACgA' params = param1 + param2 + param3 body [ 'params' ] = params elif ignore_spelling : body [ 'params' ] = "QgIIAQ%3D%3D" response = self . _send_request ( endpoint , body ) if 'contents' not in response : return search_results if 'tabbedSearchResultsRenderer' in response [ 'contents' ] : results = response [ 'contents' ] [ 'tabbedSearchResultsRenderer' ] [ 'tabs' ] [ int ( filter == "uploads" ) ] [ 'tabRenderer' ] [ 'content' ] else : results = response [ 'contents' ] results = nav ( results , SECTION_LIST ) if len ( results ) == 1 and 'itemSectionRenderer' in results : return search_results for res in results : if 'musicShelfRenderer' in res : results = res [ 'musicShelfRenderer' ] [ 'contents' ] type = filter [ : - 1 ] if filter else None search_results . extend ( self . parser . parse_search_results ( results , type ) ) if 'continuations' in res [ 'musicShelfRenderer' ] : request_func = lambda additionalParams : self . _send_request ( endpoint , body , additionalParams ) parse_func = lambda contents : self . parser . parse_search_results ( contents , type ) search_results . extend ( get_continuations ( res [ 'musicShelfRenderer' ] , 'musicShelfContinuation' , limit - len ( search_results ) , request_func , parse_func ) ) return search_results
Search YouTube music
Returns results within the provided category.
Search YouTube music Returns results within the provided category .
"""
        Search YouTube music
        Returns results within the provided category.

        :param query: Query string, i.e. 'Oasis Wonderwall'
        :param filter: Filter for item types. Allowed values:
          'songs', 'videos', 'albums', 'artists', 'playlists', 'uploads'.
          Default: Default search, including all types of items.
        :param limit: Number of search results to return
          Default: 20
        :param ignore_spelling: Whether to ignore YTM spelling suggestions.
          If True, the exact search term will be searched for, and will not be corrected.
          This does not have any effect when the filter is set to 'uploads'.
          Default: False, will use YTM's default behavior of autocorrecting the search.
        :return: List of results depending on filter.
          resultType specifies the type of item (important for default search).
          albums, artists and playlists additionally contain a browseId, corresponding to
          albumId, channelId and playlistId (browseId='VL'+playlistId)

          Example list::

            [
              {
                "videoId": "ZrOKjDZOtkA",
                "title": "Wonderwall (Remastered)",
                "artists": [
                  {
                    "name": "Oasis",
                    "id": "UCmMUZbaYdNH0bEd1PAlAqsA"
                  }
                ],
                "album": {
                  "name": "(What's The Story) Morning Glory? (Remastered)",
                  "id": "MPREb_9nqEki4ZDpp"
                },
                "duration": "4:19",
                "thumbnails": [...],
                "resultType": "song"
              }
            ]
        """ # no results # no results
List of results depending on filter.
resultType specifies the type of item (important for default search).
albums, artists and playlists additionally contain a browseId, corresponding to
albumId, channelId and playlistId (browseId='VL'+playlistId)

Example list:.

[
{
"videoId": "ZrOKjDZOtkA",
"title": "Wonderwall (Remastered)",
"artists": [
{
"name": "Oasis",
"id": "UCmMUZbaYdNH0bEd1PAlAqsA"
}
],
"album": {
"name": "(What's The Story) Morning Glory.
List of results depending on filter . resultType specifies the type of item ( important for default search ) . albums artists and playlists additionally contain a browseId corresponding to albumId channelId and playlistId ( browseId = ' VL ' + playlistId ) Example list : . [ { " videoId " : " ZrOKjDZOtkA " " title " : " Wonderwall ( Remastered ) " " artists " : [ { " name " : " Oasis " " id " : " UCmMUZbaYdNH0bEd1PAlAqsA " } ] " album " : { " name " : " ( What ' s The Story ) Morning Glory .
self
query
str
Query string, i.e. 'Oasis Wonderwall'
Query string i . e . ' Oasis Wonderwall '
filter
str
Filter for item types. Allowed values:
'songs', 'videos', 'albums', 'artists', 'playlists', 'uploads'.
Default: Default search, including all types of items.
Filter for item types . Allowed values : ' songs ' ' videos ' ' albums ' ' artists ' ' playlists ' ' uploads ' . Default : Default search including all types of items .
limit
int
Number of search results to return
Default: 20
Number of search results to return Default : 20
ignore_spelling
bool
Whether to ignore YTM spelling suggestions.
If True, the exact search term will be searched for, and will not be corrected.
This does not have any effect when the filter is set to 'uploads'.
Default: False, will use YTM's default behavior of autocorrecting the search.
Whether to ignore YTM spelling suggestions . If True the exact search term will be searched for and will not be corrected . This does not have any effect when the filter is set to ' uploads ' . Default : False will use YTM ' s default behavior of autocorrecting the search .