Top

spotify.v1.album module

from spotify import values
from spotify.object.copyright import Copyright
from spotify.object.image import Image
from spotify.page import Page
from spotify.resource import Resource, UpgradableInstance
from spotify.v1.album.track import TrackList, TrackPage


class AlbumContext(Resource):

    def __init__(self, version, id):
        """
        Album context

        :param V1 version: Spotify API Version
        :param str id: Album id
        """
        super(AlbumContext, self).__init__(version)
        self.id = id

        self._tracks = None

    @property
    def tracks(self):
        """
        Tracks list context

        :return: Tracks list context
        """
        if self._tracks is None:
            self._tracks = TrackList(self.version, self.id)

        return self._tracks

    def fetch(self, market=values.UNSET):
        """
        Fetch the album metadata

        :param str market: Market locale
        :return: Fetched album instance
        :rtype: AlbumInstance
        """
        params = values.of({
            'market': market
        })
        response = self.version.request('GET', '/albums/{}'.format(self.id), params=params)
        return AlbumInstance(self.version, response.json())


class AlbumInstance(UpgradableInstance):

    @property
    def album_type(self):
        return self.property('album_type')

    @property
    def artists(self):
        from spotify.v1.artist import ArtistInstance
        return [ArtistInstance(self.version, artist) for artist in self.property('artists')]

    @property
    def available_markets(self):
        return self.property('available_markets')

    @property
    def copyrights(self):
        return [Copyright.from_json(copyright) for copyright in self.property('copyrights')]

    @property
    def external_ids(self):
        return self.property('external_ids')

    @property
    def external_urls(self):
        return self.property('external_urls')

    @property
    def genres(self):
        return self.property('genres')

    @property
    def id(self):
        return self.property('id')

    @property
    def images(self):
        return [Image.from_json(image) for image in self.property('images')]

    @property
    def name(self):
        return self.property('name')

    @property
    def popularity(self):
        return self.property('popularity')

    @property
    def release_date(self):
        return self.property('release_date')

    @property
    def release_date_precision(self):
        return self.property('release_date_precision')

    @property
    def tracks(self):
        return TrackPage(self.version, self.property('tracks'), 'items')

    @property
    def type(self):
        return self.property('type')

    @property
    def uri(self):
        return self.property('uri')


class AlbumList(Resource):

    def get(self, id):
        """
        Get the Album context

        :param str id: ID of the album
        :return: Album context
        :rtype: AlbumContext
        """
        return AlbumContext(self.version, id)

    def list(self, ids, market=values.UNSET):
        """
        List albums

        :param List[str] ids: List of albums ids
        :param str market: Market locale
        :return: Page of Albums
        :rtype: AlbumPage
        """
        params = values.of({
            'ids': ','.join(ids),
            'market': market
        })
        response = self.version.request('GET', '/albums', params=params)
        return AlbumPage(self.version, response.json(), 'albums')


class AlbumPage(Page):

    @property
    def instance_class(self):
        """
        Returns the AlbumInstance class

        :return: AlbumInstance class
        """
        return AlbumInstance

Classes

class AlbumContext

class AlbumContext(Resource):

    def __init__(self, version, id):
        """
        Album context

        :param V1 version: Spotify API Version
        :param str id: Album id
        """
        super(AlbumContext, self).__init__(version)
        self.id = id

        self._tracks = None

    @property
    def tracks(self):
        """
        Tracks list context

        :return: Tracks list context
        """
        if self._tracks is None:
            self._tracks = TrackList(self.version, self.id)

        return self._tracks

    def fetch(self, market=values.UNSET):
        """
        Fetch the album metadata

        :param str market: Market locale
        :return: Fetched album instance
        :rtype: AlbumInstance
        """
        params = values.of({
            'market': market
        })
        response = self.version.request('GET', '/albums/{}'.format(self.id), params=params)
        return AlbumInstance(self.version, response.json())

Ancestors (in MRO)

Instance variables

var id

var tracks

Tracks list context

:return: Tracks list context

Methods

def __init__(

self, version, id)

Album context

:param V1 version: Spotify API Version :param str id: Album id

def __init__(self, version, id):
    """
    Album context
    :param V1 version: Spotify API Version
    :param str id: Album id
    """
    super(AlbumContext, self).__init__(version)
    self.id = id
    self._tracks = None

def fetch(

self, market='UNSET')

Fetch the album metadata

:param str market: Market locale :return: Fetched album instance :rtype: AlbumInstance

def fetch(self, market=values.UNSET):
    """
    Fetch the album metadata
    :param str market: Market locale
    :return: Fetched album instance
    :rtype: AlbumInstance
    """
    params = values.of({
        'market': market
    })
    response = self.version.request('GET', '/albums/{}'.format(self.id), params=params)
    return AlbumInstance(self.version, response.json())

class AlbumInstance

class AlbumInstance(UpgradableInstance):

    @property
    def album_type(self):
        return self.property('album_type')

    @property
    def artists(self):
        from spotify.v1.artist import ArtistInstance
        return [ArtistInstance(self.version, artist) for artist in self.property('artists')]

    @property
    def available_markets(self):
        return self.property('available_markets')

    @property
    def copyrights(self):
        return [Copyright.from_json(copyright) for copyright in self.property('copyrights')]

    @property
    def external_ids(self):
        return self.property('external_ids')

    @property
    def external_urls(self):
        return self.property('external_urls')

    @property
    def genres(self):
        return self.property('genres')

    @property
    def id(self):
        return self.property('id')

    @property
    def images(self):
        return [Image.from_json(image) for image in self.property('images')]

    @property
    def name(self):
        return self.property('name')

    @property
    def popularity(self):
        return self.property('popularity')

    @property
    def release_date(self):
        return self.property('release_date')

    @property
    def release_date_precision(self):
        return self.property('release_date_precision')

    @property
    def tracks(self):
        return TrackPage(self.version, self.property('tracks'), 'items')

    @property
    def type(self):
        return self.property('type')

    @property
    def uri(self):
        return self.property('uri')

Ancestors (in MRO)

  • AlbumInstance
  • spotify.resource.UpgradableInstance
  • spotify.resource.Instance
  • spotify.resource.Resource
  • __builtin__.object

Instance variables

var album_type

var artists

var available_markets

var copyrights

var external_ids

var external_urls

var genres

var href

var id

var images

var name

var popularity

var release_date

var release_date_precision

var tracks

var type

var uri

Methods

def __init__(

self, version, properties)

def __init__(self, version, properties):
    super(UpgradableInstance, self).__init__(version, properties)

def property(

self, name, default=None)

def property(self, name, default=None):
    prop = super(UpgradableInstance, self).property(name)
    if prop:
        return prop
    self.upgrade()
    return super(UpgradableInstance, self).property(name)

def upgrade(

self)

def upgrade(self):
    response = self.version.client.request('GET', self.href)
    self.properties = response.json()

class AlbumList

class AlbumList(Resource):

    def get(self, id):
        """
        Get the Album context

        :param str id: ID of the album
        :return: Album context
        :rtype: AlbumContext
        """
        return AlbumContext(self.version, id)

    def list(self, ids, market=values.UNSET):
        """
        List albums

        :param List[str] ids: List of albums ids
        :param str market: Market locale
        :return: Page of Albums
        :rtype: AlbumPage
        """
        params = values.of({
            'ids': ','.join(ids),
            'market': market
        })
        response = self.version.request('GET', '/albums', params=params)
        return AlbumPage(self.version, response.json(), 'albums')

Ancestors (in MRO)

  • AlbumList
  • spotify.resource.Resource
  • __builtin__.object

Methods

def __init__(

self, version)

def __init__(self, version):
    self.version = version

def get(

self, id)

Get the Album context

:param str id: ID of the album :return: Album context :rtype: AlbumContext

def get(self, id):
    """
    Get the Album context
    :param str id: ID of the album
    :return: Album context
    :rtype: AlbumContext
    """
    return AlbumContext(self.version, id)

def list(

self, ids, market='UNSET')

List albums

:param List[str] ids: List of albums ids :param str market: Market locale :return: Page of Albums :rtype: AlbumPage

def list(self, ids, market=values.UNSET):
    """
    List albums
    :param List[str] ids: List of albums ids
    :param str market: Market locale
    :return: Page of Albums
    :rtype: AlbumPage
    """
    params = values.of({
        'ids': ','.join(ids),
        'market': market
    })
    response = self.version.request('GET', '/albums', params=params)
    return AlbumPage(self.version, response.json(), 'albums')

class AlbumPage

class AlbumPage(Page):

    @property
    def instance_class(self):
        """
        Returns the AlbumInstance class

        :return: AlbumInstance class
        """
        return AlbumInstance

Ancestors (in MRO)

  • AlbumPage
  • spotify.page.Page
  • spotify.resource.Resource
  • __builtin__.object

Instance variables

var instance_class

Returns the AlbumInstance class

:return: AlbumInstance class

Methods

def __init__(

self, version, data, key)

def __init__(self, version, data, key):
    super(Page, self).__init__(version)
    self._key = key
    self._items = iter([self.instance_class(self.version, item) for item in data.get(key, [])])
    del data[key]
    self._meta = data

def has_next_page(

self)

def has_next_page(self):
    return 'next' in self._meta and self._meta['next'] is not None

def next_page(

self)

def next_page(self):
    response = self.version.request(self._meta['next'])
    return self.__class__(
        self.version,
        response.json(),
        self._key
    )

Sub-modules