mirror of
https://github.com/c0de-archive/spotipy.git
synced 2024-11-05 07:27:47 +00:00
Documentation and support for Your Music methods
This commit is contained in:
parent
2d98c30d01
commit
1ebbac6de7
@ -64,6 +64,10 @@ A full set of examples can be found in the [Spotipy examples directory](https://
|
|||||||
- **user_playlist_add_tracks(self, user, playlist_id, tracks, position=None)** - Adds tracks to a playlist
|
- **user_playlist_add_tracks(self, user, playlist_id, tracks, position=None)** - Adds tracks to a playlist
|
||||||
- **user_playlist_create(self, user, name, public=True)** - Creates a playlist for a user
|
- **user_playlist_create(self, user, name, public=True)** - Creates a playlist for a user
|
||||||
- **user_playlists(self, user)** - Gets playlists of a user
|
- **user_playlists(self, user)** - Gets playlists of a user
|
||||||
|
- **current_user(self)** - Get detailed profile information about the current user.
|
||||||
|
- **current_user_saved_tracks(self, limit=20, offset=0)** - Gets a list of the tracks saved in the current authorized user's "Your Music" library
|
||||||
|
- **current_user_saved_tracks_delete(self, limit=20, offset=0)** - Remove tracks from the current authorized user's "Your Music" library
|
||||||
|
- **current_user_saved_tracks_add(self, limit=20, offset=0)** - Add tracks to the current authorized user's "Your Music" library
|
||||||
|
|
||||||
Refer to the [Spotify API documentation](https://developer.spotify.com/spotify-web-api/) for details on the methods and parameters.
|
Refer to the [Spotify API documentation](https://developer.spotify.com/spotify-web-api/) for details on the methods and parameters.
|
||||||
|
|
||||||
|
28
examples/add_a_saved_track.py
Normal file
28
examples/add_a_saved_track.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
# Add tracks to 'Your Collection' of saved tracks
|
||||||
|
|
||||||
|
import pprint
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import spotipy
|
||||||
|
import spotipy.oauth2 as oauth2
|
||||||
|
import util
|
||||||
|
|
||||||
|
scope = 'user-library-modify'
|
||||||
|
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
username = sys.argv[1]
|
||||||
|
tids = sys.argv[2:]
|
||||||
|
else:
|
||||||
|
print "Usage: %s username track-id ..." % (sys.argv[0],)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
token = util.prompt_for_user_token(username, scope)
|
||||||
|
|
||||||
|
if token:
|
||||||
|
sp = spotipy.Spotify(auth=token)
|
||||||
|
sp.trace = False
|
||||||
|
results = sp.current_user_saved_tracks_add(ids=tids)
|
||||||
|
pprint.pprint(results)
|
||||||
|
else:
|
||||||
|
print "Can't get token for", username
|
27
examples/delete_a_saved_track.py
Normal file
27
examples/delete_a_saved_track.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Delete a track from 'Your Collection' of saved tracks
|
||||||
|
|
||||||
|
import pprint
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import spotipy
|
||||||
|
import spotipy.oauth2 as oauth2
|
||||||
|
import util
|
||||||
|
|
||||||
|
scope = 'user-library-modify'
|
||||||
|
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
username = sys.argv[1]
|
||||||
|
tids = sys.argv[2:]
|
||||||
|
else:
|
||||||
|
print "Usage: %s username track-id ..." % (sys.argv[0],)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
token = util.prompt_for_user_token(username, scope)
|
||||||
|
|
||||||
|
if token:
|
||||||
|
sp = spotipy.Spotify(auth=token)
|
||||||
|
sp.trace = False
|
||||||
|
results = sp.current_user_saved_tracks_delete(ids=tids)
|
||||||
|
pprint.pprint(results)
|
||||||
|
else:
|
||||||
|
print "Can't get token for", username
|
2
setup.py
2
setup.py
@ -3,7 +3,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='SpotipyWebApi',
|
name='SpotipyWebApi',
|
||||||
version='1.46',
|
version='1.48',
|
||||||
description='simple client for the Spotify Web API',
|
description='simple client for the Spotify Web API',
|
||||||
author="@plamere",
|
author="@plamere",
|
||||||
author_email="paul@echonest.com",
|
author_email="paul@echonest.com",
|
||||||
|
@ -67,11 +67,14 @@ class Spotify(object):
|
|||||||
print(verb, r.url)
|
print(verb, r.url)
|
||||||
if not (r.status_code >= 200 and r.status_code < 300):
|
if not (r.status_code >= 200 and r.status_code < 300):
|
||||||
raise SpotifyException(r.status_code, -1, u'the requested resource could not be found: ' + r.url)
|
raise SpotifyException(r.status_code, -1, u'the requested resource could not be found: ' + r.url)
|
||||||
|
if len(r.text) > 0:
|
||||||
results = r.json()
|
results = r.json()
|
||||||
if self.trace:
|
if self.trace:
|
||||||
print('RESP', results)
|
print('RESP', results)
|
||||||
print()
|
print()
|
||||||
return results
|
return results
|
||||||
|
else:
|
||||||
|
return {}
|
||||||
|
|
||||||
def get(self, method, args=None, **kwargs):
|
def get(self, method, args=None, **kwargs):
|
||||||
if args:
|
if args:
|
||||||
|
Loading…
Reference in New Issue
Block a user