From 8adbfe6f6deb8defe485a5648660809372a3b738 Mon Sep 17 00:00:00 2001 From: Paul Lamere Date: Sat, 15 Nov 2014 07:20:11 -0500 Subject: [PATCH] Added playlist tracks method. Updated tests. --- deploy | 13 +++++++++++++ setup.py | 2 +- spotipy/client.py | 19 ++++++++++++++++--- tests/authtests.py | 21 ++++++++++++++++++--- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/deploy b/deploy index b4808f9..f18302a 100755 --- a/deploy +++ b/deploy @@ -2,5 +2,18 @@ # sudo python setup.py develop --uninstall # sudo python setup.py install +# How do deploy +# - run tests +# - push to github +# - Adjust version number in setup.py +# - Update README.md with updated version info +# - leave development mode +# sudo python setup.py develop --uninstall +# sudo python setup.py install +# - upload dist +# sudo python setup.py sdist upload +# docs should automatically be updated. verify them at +# http://spotipy.readthedocs.org/en/latest/ + sudo python setup.py sdist upload diff --git a/setup.py b/setup.py index ba653a3..387532e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name='spotipy', - version='2.1.0', + version='2.2.0', description='simple client for the Spotify Web API', author="@plamere", author_email="paul@echonest.com", diff --git a/spotipy/client.py b/spotipy/client.py index 6a53d4e..99476e6 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -279,7 +279,6 @@ class Spotify(object): def user_playlist(self, user, playlist_id = None, fields=None): ''' Gets playlist of a user - Parameters: - user - the id of the user - playlist_id - the id of the playlist @@ -288,8 +287,22 @@ class Spotify(object): if playlist_id == None: return self._get("users/%s/starred" % (user), fields=fields) plid = self._get_id('playlist', playlist_id) - return self._get("users/%s/playlists/%s" % (user, plid), - fields=fields) + return self._get("users/%s/playlists/%s" % (user, plid), fields=fields) + + def user_playlist_tracks(self, user, playlist_id = None, fields=None, + limit=100, offset=0): + ''' Get full details of the tracks of a playlist owned by a user. + + Parameters: + - user - the id of the user + - playlist_id - the id of the playlist + - fields - which fields to return + - limit - the maximum number of tracks to return + - offset - the index of the first track to return + ''' + plid = self._get_id('playlist', playlist_id) + return self._get("users/%s/playlists/%s/tracks" % (user, plid), + limit=limit, offset=offset, fields=fields) def user_playlist_create(self, user, name, public=True): ''' Creates a playlist for a user diff --git a/tests/authtests.py b/tests/authtests.py index 046f0db..348c30a 100644 --- a/tests/authtests.py +++ b/tests/authtests.py @@ -19,7 +19,6 @@ class AuthTestSpotipy(unittest.TestCase): These tests require user authentication ''' - playlist = "spotify:user:plamere:playlist:2oCEWyyAPbZp9xhVSxZavx" four_tracks = ["spotify:track:6RtPijgfPKROxEzTHNRiDp", "spotify:track:7IHOIqZUUInxjVkko181PB", @@ -55,8 +54,6 @@ class AuthTestSpotipy(unittest.TestCase): user = spotify.me() self.assertTrue(user['id'] == username) - - @unittest.expectedFailure def test_user_playlists(self): playlists = spotify.user_playlists(username, limit=5) self.assertTrue('items' in playlists) @@ -67,6 +64,24 @@ class AuthTestSpotipy(unittest.TestCase): self.assertTrue(len(playlists['items']) == 5) + def test_user_playlist_tracks(self): + playlists = spotify.user_playlists(username, limit=5) + self.assertTrue('items' in playlists) + for playlist in playlists['items']: + user = playlist['owner']['id'] + pid = playlist['id'] + results = spotify.user_playlist_tracks(user, pid) + self.assertTrue(len(results['items']) > 0) + + def user_playlist_tracks(self, user, playlist_id = None, fields=None, + limit=100, offset=0): + + # known API issue currently causes this test to fail + # the issue is that the API doesn't currently respect the + # limit paramter + + self.assertTrue(len(playlists['items']) == 5) + def test_current_user_saved_tracks(self): tracks = spotify.current_user_saved_tracks() self.assertTrue(len(tracks['items']) > 0)