platypush/plugins/music/spotify/__init__.py
def search(self, query: Optional[Union[str, dict]] = None, limit: int = 50, offset: int = 0, type: str = 'track',
               **filter) -> Iterable[dict]:
        """
        Search for tracks matching a certain criteria.

        :param query: Search filter. It can either be a free-text or a structured query. In the latter case the
            following fields are supported:

                - ``any``: Search for anything that matches this text.
                - ``uri``: Search the following Spotify ID/URI or list of IDs/URIs.
                - ``artist``: Filter by artist.
                - ``track``: Filter by track name.
                - ``album``: Filter by album name.
                - ``year``: Filter by year (dash-separated ranges are supported).

        :param limit: Maximum number of results (default: 50).
        :param offset: Return results starting from this index (default: 0).
        :param type: Type of results to be returned. Supported: ``album``, ``artist``, ``playlist``, ``track``, ``show``
            and ``episode`` (default: ``track``).
        :param filter: Alternative key-value way of representing a structured query.
        :return:
            If ``type=track``:
                .. schema:: spotify.SpotifyTrackSchema(many=True)
            If ``type=album``:
                .. schema:: spotify.SpotifyAlbumSchema(many=True)
            If ``type=artist``:
                .. schema:: spotify.SpotifyArtistSchema(many=True)
            If ``type=playlist``:
                .. schema:: spotify.SpotifyPlaylistSchema(many=True)
            If ``type=episode``:
                .. schema:: spotify.SpotifyEpisodeSchema(many=True)
            If ``type=show``:
                .. schema:: spotify.SpotifyShowSchema(many=True)

        """
        uri = {
            **(query if isinstance(query, dict) else {}),
            **filter,
        }.get('uri', [])

        uris = uri.split(',') if isinstance(uri, str) else uri
        params = {
            'ids': ','.join([uri.split(':')[-1].strip() for uri in uris]),
        } if uris else {
            'q': self._make_filter(query, **filter),
            'type': type,
        }

        response = self._spotify_paginate_results(
            f'/v1/{type + "s" if uris else "search"}',
            limit=limit,
            offset=offset,
            type=type,
            params=params,
        )

        if type == 'track':
            return sorted(
                SpotifyTrackSchema(many=True).dump(response),
                key=lambda track: (
                    track.get('artist'),
                    track.get('date'),
                    track.get('album'),
                    track.get('track'),
                    track.get('title'),
                    track.get('popularity'),
                )
            )

        schema_class = None
        if type == 'playlist':
            schema_class = SpotifyPlaylistSchema
        if type == 'album':
            schema_class = SpotifyAlbumSchema
        if type == 'artist':
            schema_class = SpotifyArtistSchema
        if type == 'episode':
            schema_class = SpotifyEpisodeSchema
        if type == 'show':
            schema_class = SpotifyShowSchema

        if schema_class:
            return schema_class(many=True).dump(response)

        return response

        Search for tracks matching a certain criteria.

        :param query: Search filter. It can either be a free-text or a structured query. In the latter case the
            following fields are supported:

                - ``any``: Search for anything that matches this text.
                - ``uri``: Search the following Spotify ID/URI or list of IDs/URIs.
                - ``artist``: Filter by artist.
                - ``track``: Filter by track name.
                - ``album``: Filter by album name.
                - ``year``: Filter by year (dash-separated ranges are supported).

        :param limit: Maximum number of results (default: 50).
        :param offset: Return results starting from this index (default: 0).
        :param type: Type of results to be returned. Supported: ``album``, ``artist``, ``playlist``, ``track``, ``show``
            and ``episode`` (default: ``track``).
        :param filter: Alternative key-value way of representing a structured query.
        :return:
            If ``type=track``:
                .. schema:: spotify.SpotifyTrackSchema(many=True)
            If ``type=album``:
                .. schema:: spotify.SpotifyAlbumSchema(many=True)
            If ``type=artist``:
                .. schema:: spotify.SpotifyArtistSchema(many=True)
            If ``type=playlist``:
                .. schema:: spotify.SpotifyPlaylistSchema(many=True)
            If ``type=episode``:
                .. schema:: spotify.SpotifyEpisodeSchema(many=True)
            If ``type=show``:
                .. schema:: spotify.SpotifyShowSchema(many=True)

        
Search for tracks matching a certain criteria.
Search for tracks matching a certain criteria .
def search(self, query: Optional[Union[str, dict]] = None, limit: int = 50, offset: int = 0, type: str = 'track',
               **filter) -> Iterable[dict]:
        uri = {
            **(query if isinstance(query, dict) else {}),
            **filter,
        }.get('uri', [])
        uris = uri.split(',') if isinstance(uri, str) else uri
        params = {
            'ids': ','.join([uri.split(':')[-1].strip() for uri in uris]),
        } if uris else {
            'q': self._make_filter(query, **filter),
            'type': type,
        }
        response = self._spotify_paginate_results(
            f'/v1/{type + "s" if uris else "search"}',
            limit=limit,
            offset=offset,
            type=type,
            params=params,
        )
        if type == 'track':
            return sorted(
                SpotifyTrackSchema(many=True).dump(response),
                key=lambda track: (
                    track.get('artist'),
                    track.get('date'),
                    track.get('album'),
                    track.get('track'),
                    track.get('title'),
                    track.get('popularity'),
                )
            )
        schema_class = None
        if type == 'playlist':
            schema_class = SpotifyPlaylistSchema
        if type == 'album':
            schema_class = SpotifyAlbumSchema
        if type == 'artist':
            schema_class = SpotifyArtistSchema
        if type == 'episode':
            schema_class = SpotifyEpisodeSchema
        if type == 'show':
            schema_class = SpotifyShowSchema
        if schema_class:
            return schema_class(many=True).dump(response)
        return response
def search ( self , query : Optional [ Union [ str , dict ] ] = None , limit : int = 50 , offset : int = 0 , type : str = 'track' , ** filter ) -> Iterable [ dict ] : uri = { ** ( query if isinstance ( query , dict ) else { } ) , ** filter , } . get ( 'uri' , [ ] ) uris = uri . split ( ',' ) if isinstance ( uri , str ) else uri params = { 'ids' : ',' . join ( [ uri . split ( ':' ) [ - 1 ] . strip ( ) for uri in uris ] ) , } if uris else { 'q' : self . _make_filter ( query , ** filter ) , 'type' : type , } response = self . _spotify_paginate_results ( f'/v1/{type + "s" if uris else "search"}' , limit = limit , offset = offset , type = type , params = params , ) if type == 'track' : return sorted ( SpotifyTrackSchema ( many = True ) . dump ( response ) , key = lambda track : ( track . get ( 'artist' ) , track . get ( 'date' ) , track . get ( 'album' ) , track . get ( 'track' ) , track . get ( 'title' ) , track . get ( 'popularity' ) , ) ) schema_class = None if type == 'playlist' : schema_class = SpotifyPlaylistSchema if type == 'album' : schema_class = SpotifyAlbumSchema if type == 'artist' : schema_class = SpotifyArtistSchema if type == 'episode' : schema_class = SpotifyEpisodeSchema if type == 'show' : schema_class = SpotifyShowSchema if schema_class : return schema_class ( many = True ) . dump ( response ) return response
Search for tracks matching a certain criteria.
Search for tracks matching a certain criteria .
"""
        Search for tracks matching a certain criteria.

        :param query: Search filter. It can either be a free-text or a structured query. In the latter case the
            following fields are supported:

                - ``any``: Search for anything that matches this text.
                - ``uri``: Search the following Spotify ID/URI or list of IDs/URIs.
                - ``artist``: Filter by artist.
                - ``track``: Filter by track name.
                - ``album``: Filter by album name.
                - ``year``: Filter by year (dash-separated ranges are supported).

        :param limit: Maximum number of results (default: 50).
        :param offset: Return results starting from this index (default: 0).
        :param type: Type of results to be returned. Supported: ``album``, ``artist``, ``playlist``, ``track``, ``show``
            and ``episode`` (default: ``track``).
        :param filter: Alternative key-value way of representing a structured query.
        :return:
            If ``type=track``:
                .. schema:: spotify.SpotifyTrackSchema(many=True)
            If ``type=album``:
                .. schema:: spotify.SpotifyAlbumSchema(many=True)
            If ``type=artist``:
                .. schema:: spotify.SpotifyArtistSchema(many=True)
            If ``type=playlist``:
                .. schema:: spotify.SpotifyPlaylistSchema(many=True)
            If ``type=episode``:
                .. schema:: spotify.SpotifyEpisodeSchema(many=True)
            If ``type=show``:
                .. schema:: spotify.SpotifyShowSchema(many=True)

        """
If ``type=track``:
schema:: spotify.SpotifyTrackSchema(many=True)
If ``type=album``:
schema:: spotify.SpotifyAlbumSchema(many=True)
If ``type=artist``:
schema:: spotify.SpotifyArtistSchema(many=True)
If ``type=playlist``:
schema:: spotify.SpotifyPlaylistSchema(many=True)
If ``type=episode``:
schema:: spotify.SpotifyEpisodeSchema(many=True)
If ``type=show``:
schema:: spotify.SpotifyShowSchema(many=True)
If ` ` type = track ` ` : schema :: spotify . SpotifyTrackSchema ( many = True ) If ` ` type = album ` ` : schema :: spotify . SpotifyAlbumSchema ( many = True ) If ` ` type = artist ` ` : schema :: spotify . SpotifyArtistSchema ( many = True ) If ` ` type = playlist ` ` : schema :: spotify . SpotifyPlaylistSchema ( many = True ) If ` ` type = episode ` ` : schema :: spotify . SpotifyEpisodeSchema ( many = True ) If ` ` type = show ` ` : schema :: spotify . SpotifyShowSchema ( many = True )
self
query
Optional[Union[str, dict]]
Search filter. It can either be a free-text or a structured query. In the latter case the
following fields are supported.

``any``: Search for anything that matches this text.
``uri``: Search the following Spotify ID/URI or list of IDs/URIs.
``artist``: Filter by artist.
``track``: Filter by track name.
``album``: Filter by album name.
``year``: Filter by year (dash-separated ranges are supported).
Search filter . It can either be a free - text or a structured query . In the latter case the following fields are supported . ` ` any ` ` : Search for anything that matches this text . ` ` uri ` ` : Search the following Spotify ID / URI or list of IDs / URIs . ` ` artist ` ` : Filter by artist . ` ` track ` ` : Filter by track name . ` ` album ` ` : Filter by album name . ` ` year ` ` : Filter by year ( dash - separated ranges are supported ) .
limit
int
Maximum number of results (default: 50).
Maximum number of results ( default : 50 ) .
offset
int
Return results starting from this index (default: 0).
Return results starting from this index ( default : 0 ) .
type
str
Type of results to be returned.
Type of results to be returned .
filter
Alternative key-value way of representing a structured query.
Alternative key - value way of representing a structured query .