Ejemplo n.º 1
0
    def release_date(self):
        """ The date the album was **first** released.

        Returns:
            A tuple with up to 3 ints. The tuple will be one of the following

            - (year,)
            - (year, month)
            - (year, month, day)

        Note:
            If the album was first released in March 2010 in Europe, and
            then 2 months later (May) was released to the rest of the world,
            this function will return the March 2010 date.

            We considered instead returning a Python datetime.date object.
            However since Spotify may not return a month or day, we cannot use
            a datetime.date object.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        # Spotify returns date in format Y-M-D
        date = utils.get_field(self, 'release_date').split('-')

        # Convert to ints
        date = [int(elem) for elem in date]
        return tuple(date)
Ejemplo n.º 2
0
    def uri(self):
        """
        Returns:
            str: The album's Spotify uri.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        return utils.get_field(self, 'uri')
Ejemplo n.º 3
0
    def explicit(self):
        """
        Returns:
            bool: True if the track has explicit lyrics, and False otherwise.

        Calls endpoints:
            - GET     /v1/tracks/{id}
        """
        return utils.get_field(self, 'explicit')
Ejemplo n.º 4
0
    def name(self):
        """
        Returns:
            str: The name of the album as it appears on Spotify.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        return utils.get_field(self, 'name')
Ejemplo n.º 5
0
    def name(self):
        """
        Returns:
            str: The user's display name as it appears on Spotify

        Calls endpoints:
            - GET     /v1/users/{id}
        """
        return utils.get_field(self, 'display_name')
Ejemplo n.º 6
0
    def label(self):
        """
        Returns:
            str: The name of the label for this album.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        return utils.get_field(self, 'label')
Ejemplo n.º 7
0
    def __len__(self):
        """
        Returns:
            int: The length of the track in milliseconds

        Calls endpoints:
            - GET     /v1/tracks/{id}
        """
        return utils.get_field(self, 'duration_ms')
Ejemplo n.º 8
0
    def uri(self):
        """
        Returns:
            str: the user's Spotify uri.

        Calls endpoints:
            - GET     /v1/users/{id}
        """
        return utils.get_field(self, 'uri')
Ejemplo n.º 9
0
    def href(self):
        """ Get the user's href.

        Returns:
            str: a link to the Web API endpoint containing the user's profile.

        Calls endpoints:
            - GET     /v1/users/{id}
        """
        return utils.get_field(self, 'href')
Ejemplo n.º 10
0
    def href(self):
        """ Get the album's href.

        Returns:
            str: A link to the Web API endpoint providing full album details.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        return utils.get_field(self, 'href')
Ejemplo n.º 11
0
    def copyrights(self):
        """
        Returns:
            List[Copyright]: The copyright statement(s) for this album.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        result = utils.get_field(self, 'copyrights')
        return [Copyright(elem) for elem in result]
Ejemplo n.º 12
0
    def available_markets(self):
        """
        Returns:
            List[str]: A list of the :term:`markets <Market>` this track is
            available in.

        Calls endpoints:
            - GET     /v1/tracks/{id}
        """
        return utils.get_field(self, 'available_markets')
Ejemplo n.º 13
0
    def images(self):
        """
        Returns:
            List[Image]: The album's cover art in various sizes, widest first.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        result = utils.get_field(self, 'images')
        return [Image(elem) for elem in result]
Ejemplo n.º 14
0
    def genres(self):
        """ Get the genres for this album as categorized by Spotify.

        Returns:
            List[str]: A list of genre names. Could be empty if the album is not
            yet classified.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        return utils.get_field(self, 'genres')
Ejemplo n.º 15
0
    def popularity(self):
        """ Get the popularity of the track as calculated by Spotify.

        Returns:
            int: The popularity is between 0 and 100 (inclusive), with 100 being
            the most popular. This number is calculated in Spotify's backend.

        Calls endpoints:
            - GET     /v1/tracks/{id}
        """
        return utils.get_field(self, 'popularity')
Ejemplo n.º 16
0
    def popularity(self):
        """ Get the popularity of the album as calculated by Spotify.

        Returns:
            int: The popularity between 0 and 100 (inclusive), with 100 being
            the most popular. This number is calculated using the popularity of
            each track.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        return utils.get_field(self, 'popularity')
Ejemplo n.º 17
0
    def artists(self):
        """
        Returns:
            List[Artist]: a list of the artist(s) on this track.

        Calls endpoints:
            - GET     /v1/tracks/{id}
        """
        if self._artists is None:
            artists = utils.get_field(self, 'artists')
            self._artists = [Artist(self._session, art) for art in artists]

        return self._artists
Ejemplo n.º 18
0
    def album(self):
        """
        Returns:
            Album: The album this track is on:

        Calls endpoints:
            - GET     /v1/tracks/{id}
        """
        if self._album is None:
            album = utils.get_field(self, 'album')
            self._album = Album(self._session, album)

        return self._album
Ejemplo n.º 19
0
    def available_markets(self):
        """ Get the country codes of the :term:`markets <Market>` this album is
        available in.

        The album is considered available in a market when at least one of its
        tracks is available in that market.

        Returns:
            List[str]: A list of the available country codes.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        return utils.get_field(self, 'available_markets')
Ejemplo n.º 20
0
    def artists(self):
        """
        Returns:
            List[Artist]: The artist(s) who wrote this album.

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        if self._artists is not None:
            return self._artists

        artists = utils.get_field(self, 'artists')
        self._artists = [Artist(self._session, artist) for artist in artists]

        return self._artists
Ejemplo n.º 21
0
    def image(self):
        """ Get the User's profile picture.

        Returns:
            Union[Image, None]: An image object if the User has a profile
            picture, else None.

        Calls endpoints:
            - GET     /v1/users/{id}
        """
        result = utils.get_field(self, 'images')

        if len(result) > 1:
            raise utils.SpotifyError('User has more than one profile picture!')

        return None if len(result) == 0 else Image(result[0])
Ejemplo n.º 22
0
    def disc_number(self):
        """ Get the track's disc number (0 indexed).

        Note:
            On Spotify (and in most music software) disc number is 1-indexed.
            This method intentionally makes it 0 indexed for consistency with
            the rest of the library.

        Returns:
            int: The number of the disc on which this track appears. This is
            usually 0, unless an album has multiple discs.

        Calls endpoints:
            - GET     /v1/tracks/{id}
        """
        result = utils.get_field(self, 'disc_number')
        return result - 1
Ejemplo n.º 23
0
    def type(self):
        """ Get the type of this album.

        Returns:
            One of

            - sp.SINGLE
            - sp.COMPILATION
            - sp.ALBUMS

        Calls endpoints:
            - GET     /v1/albums/{id}
        """
        types = {
            'single': const.SINGLE,
            'compilation': const.COMPILATION,
            'album': const.ALBUMS
        }
        return types[utils.get_field(self, 'album_type')]
Ejemplo n.º 24
0
    def track_number(self):
        """ Get the track's number (0 indexed).

        Note:
            On Spotify (and in most music software) track number is 1-indexed.
            This method intentionally makes it 0 indexed for consistency with
            the rest of the library.

            This decision was made so that Track.track_number() is consistent
            with Album.__get_item__().

            Ex: for some 0 <= num < len(Album), Album[num].track_number() == num

        Returns:
            int: The track's number in the album. If an album has several discs,
            the track number is the number of this track on the disc it appears.


        Calls endpoints:
            - GET     /v1/tracks/{id}
        """
        result = utils.get_field(self, 'track_number')
        return result - 1
Ejemplo n.º 25
0
 def spotify_id(self):
     """
     Returns:
         str: The Spotify id of this artist.
     """
     return utils.get_field(self, 'id')