mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-02 13:42:40 +00:00
Added playlist tracks method. Updated tests.
This commit is contained in:
parent
278b7d3005
commit
8adbfe6f6d
13
deploy
13
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
|
||||
|
||||
|
2
setup.py
2
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",
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user