Exemplo n.º 1
0
    def test_repr_of_members_intact(self):
        list_in = [{'i': 1}, {'i': 2}]

        builtin = [Data(**i) for i in list_in]
        serialisable = ModelList(Data(**i) for i in list_in)

        self.assertEqual(repr(builtin), repr(serialisable))
Exemplo n.º 2
0
    def playback_devices(self) -> List[Device]:
        """
        Get a user's available devices.

        Requires the user-read-playback-state scope.

        Returns
        -------
        ModelList
            list of device objects
        """
        json = self._get('me/player/devices')
        return ModelList(Device(**d) for d in json['devices'])
Exemplo n.º 3
0
    def artists(self, artist_ids: list) -> ModelList:
        """
        Get information for multiple artists.

        Parameters
        ----------
        artist_ids
            list of artist IDs

        Returns
        -------
        ModelList
            list of full artist objects
        """
        json = self._get('artists/?ids=' + ','.join(artist_ids))
        return ModelList(FullArtist(**a) for a in json['artists'])
Exemplo n.º 4
0
    def tracks_audio_features(self, track_ids: list) -> ModelList:
        """
        Get audio feature information for multiple tracks.

        Feature information for a track may be ``None`` if not available.

        Returns
        -------
        ModelList
            list of audio features objects
        """
        json = self._get('audio-features?ids=' + ','.join(track_ids))
        return ModelList(
            AudioFeatures(**a) if a is not None else None
            for a in json['audio_features']
        )
Exemplo n.º 5
0
    def playlist_cover_image(self, playlist_id: str) -> ModelList:
        """
        Get cover image of a playlist. Note: returns a list of images.

        Parameters
        ----------
        playlist_id
            playlist ID

        Returns
        -------
        ModelList
            list of cover images
        """
        json = self._get(f'playlists/{playlist_id}/images')
        return ModelList(Image(**i) for i in json)
Exemplo n.º 6
0
    def artist_top_tracks(self, artist_id: str, market: str) -> ModelList:
        """
        Get an artist's top 10 tracks by country.

        Parameters
        ----------
        artist_id
            the artist ID
        market
            an ISO 3166-1 alpha-2 country code or 'from_token'

        Returns
        -------
        ModelList
            list of full track objects
        """
        json = self._get(f'artists/{artist_id}/top-tracks', country=market)
        return ModelList(FullTrack(**t) for t in json['tracks'])
Exemplo n.º 7
0
    def albums(self, album_ids: list, market: str = None) -> ModelList:
        """
        Get multiple albums.

        Parameters
        ----------
        album_ids
            list of album IDs (1..20)
        market
            an ISO 3166-1 alpha-2 country code or 'from_token'

        Returns
        -------
        ModelList
            list of full album objects
        """
        json = self._get('albums/?ids=' + ','.join(album_ids), market=market)
        return ModelList(FullAlbum(**a) for a in json['albums'])
Exemplo n.º 8
0
    def artist_related_artists(self, artist_id: str) -> ModelList:
        """
        Get artists similar to an identified artist.

        Similarity is based on analysis of
        the Spotify community's listening history.

        Parameters
        ----------
        artist_id
            artist ID

        Returns
        -------
        ModelList
            list of full artist objects
        """
        json = self._get(f'artists/{artist_id}/related-artists')
        return ModelList(FullArtist(**a) for a in json['artists'])
Exemplo n.º 9
0
    def tracks(
            self,
            track_ids: list,
            market: str = None
    ) -> ModelList:
        """
        Get information for multiple tracks.

        Parameters
        ----------
        track_ids
            the track IDs
        market
            an ISO 3166-1 alpha-2 country code or 'from_token'

        Returns
        -------
        ModelList
            list of track objects
        """
        json = self._get('tracks/?ids=' + ','.join(track_ids), market=market)
        return ModelList(FullTrack(**t) for t in json['tracks'])
Exemplo n.º 10
0
 def post_func(json: dict):
     json = json if from_item is None else json[from_item]
     return ModelList(type_(**i) if i is not None else None for i in json)
Exemplo n.º 11
0
def join_lists(responses):
    return sum(responses, ModelList())
Exemplo n.º 12
0
 def test_list_of_dataclasses_serialised(self):
     list_in = [{'i': 1}, {'i': 2}]
     data = ModelList(Data(**i) for i in list_in)
     list_out = json.loads(str(data))
     self.assertListEqual(list_in, list_out)