Support for offset/limit with album/album_tracks API

This commit is contained in:
jsundram 2015-06-03 20:54:49 -07:00
parent c075f80470
commit bbed19fdaa
5 changed files with 64 additions and 45 deletions

View File

@ -2,7 +2,7 @@ v1.40, June 12, 2014 -- Initial public release.
v1.42, June 19, 2014 -- Removed dependency on simplejson
v1.43, June 27, 2014 -- Fixed JSON handling issue
v1.44, July 3, 2014 -- Added show_tracks.py exampole
v1.45, July 7, 2014 -- Support for related artists endpoint. Don't used
v1.45, July 7, 2014 -- Support for related artists endpoint. Don't use
cache auth codes when scope changes
v1.50, August 14, 2014 -- Refactored util out of examples and into the main
package
@ -10,6 +10,7 @@ v2.301, August 19, 2014 -- Upgraded version number to take precedence over
previously botched release (sigh)
v2.310, August 20, 2014 -- Added playlist replace and remove methods. Added auth
tests. Improved API docs
v2.310, January 05, 2015 -- Added session support
v2.3.1, March 28, 2015 -- auto retry support
v2.3.5, April 28, 2015 -- fixed bug in auto retry support
v2.310, January 5, 2015 -- Added session support
v2.3.1, March 28, 2015 -- Auto retry support
v2.3.5, April 28, 2015 -- Fixed bug in auto retry support
v2.3.6, June 3, 2015 -- Support for offset/limit with album/album_tracks API

View File

@ -55,7 +55,7 @@ If you have suggestions, bugs or other issues specific to this library, file the
- v1.42, June 19, 2014 -- Removed dependency on simplejson
- v1.43, June 27, 2014 -- Fixed JSON handling issue
- v1.44, July 3, 2014 -- Added show tracks.py example
- v1.45, July 7, 2014 -- Support for related artists endpoint. Don't used cache auth codes when scope changes
- v1.45, July 7, 2014 -- Support for related artists endpoint. Don't use cache auth codes when scope changes
- v1.49, July 23, 2014 -- Support for "Your Music" tracks (add, delete, get), with examples
- v1.50, August 14, 2014 -- Refactored util out of examples and into the main package
- v1.301, August 19, 2014 -- Upgraded version number to take precedence over previously botched release (sigh)
@ -68,3 +68,4 @@ If you have suggestions, bugs or other issues specific to this library, file the
- v2.3.2 - March 31, 2015 -- Added auto retry logic
- v2.3.3 - April 1, 2015 -- added client credential flow
- v2.3.5 - April 28, 2015 -- Fixed bug in auto retry logic
- v2.3.6 - June 3, 2015 -- Support for offset/limit with album/album_tracks API

View File

@ -2,7 +2,7 @@ from setuptools import setup
setup(
name='spotipy',
version='2.3.5',
version='2.3.6',
description='simple client for the Spotify Web API',
author="@plamere",
author_email="paul@echonest.com",

View File

@ -254,25 +254,29 @@ class Spotify(object):
trid = self._get_id('artist', artist_id)
return self._get('artists/' + trid + '/related-artists')
def album(self, album_id):
def album(self, album_id, limit=50, offset=0):
''' returns a single album given the album's ID, URIs or URL
Parameters:
- album_id - the album ID, URI or URL
- limit - the number of items to return
- offset - the index of the first item to return
'''
trid = self._get_id('album', album_id)
return self._get('albums/' + trid)
return self._get('albums/' + trid, limit=limit, offset=offset)
def album_tracks(self, album_id):
def album_tracks(self, album_id, limit=50, offset=0):
''' Get Spotify catalog information about an album's tracks
Parameters:
- album_id - the album ID, URI or URL
- limit - the number of items to return
- offset - the index of the first item to return
'''
trid = self._get_id('album', album_id)
return self._get('albums/' + trid + '/tracks/')
return self._get('albums/' + trid + '/tracks/', limit=limit, offset=offset)
def albums(self, albums):
''' returns a list of albums given the album IDs, URIs, or URLs

View File

@ -15,6 +15,8 @@ class TestSpotipy(unittest.TestCase):
weezer_urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu'
pablo_honey_urn = 'spotify:album:6AZv3m27uyRxi8KyJSfUxL'
radiohead_urn = 'spotify:artist:4Z8W4fKeB5YxbusRsdQVPb'
angeles_haydn_urn = 'spotify:album:1vAbqAeuJVWNAe7UR00bdM'
bad_id = 'BAD_ID'
@ -38,6 +40,17 @@ class TestSpotipy(unittest.TestCase):
results = self.spotify.album_tracks(self.pinkerton_urn)
self.assertTrue(len(results['items']) == 10)
def test_album_tracks_many(self):
results = self.spotify.album_tracks(self.angeles_haydn_urn)
tracks = results['items']
total, received = results['total'], len(tracks)
while received < total:
results = self.spotify.album_tracks(self.angeles_haydn_urn, offset=received)
tracks.extend(results['items'])
received = len(tracks)
self.assertEqual(received, total)
def test_albums(self):
results = self.spotify.albums([self.pinkerton_urn, self.pablo_honey_urn])
self.assertTrue('albums' in results)