mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 01:03:53 +00:00
remove unneccesary whitespaces, shorten some lines, and add name to contibutors
This commit is contained in:
parent
43a4de0314
commit
d8d9f290fb
@ -5,7 +5,7 @@ Welcome to Spotipy!
|
|||||||
===================================
|
===================================
|
||||||
*Spotipy* is a lightweight Python library for the `Spotify Web API
|
*Spotipy* is a lightweight Python library for the `Spotify Web API
|
||||||
<https://developer.spotify.com/web-api/>`_. With *Spotipy*
|
<https://developer.spotify.com/web-api/>`_. With *Spotipy*
|
||||||
you get full access to all of the music data provided by the Spotify platform.
|
you get full access to all of the music data provided by the Spotify platform.
|
||||||
|
|
||||||
Here's a quick example of using *Spotipy* to list the names of all the albums
|
Here's a quick example of using *Spotipy* to list the names of all the albums
|
||||||
released by the artist 'Birdy'::
|
released by the artist 'Birdy'::
|
||||||
@ -106,17 +106,17 @@ Even if your script does not have an accessible URL you need to specify one
|
|||||||
when registering your application where the spotify authentication API will
|
when registering your application where the spotify authentication API will
|
||||||
redirect to after successful login. The URL doesn't need to work or be
|
redirect to after successful login. The URL doesn't need to work or be
|
||||||
accessible, you can specify "http://localhost/", after successful login you
|
accessible, you can specify "http://localhost/", after successful login you
|
||||||
just need to copy the "http://localhost/?code=..." URL from your browser
|
just need to copy the "http://localhost/?code=..." URL from your browser
|
||||||
and paste it to the console where your script is running.
|
and paste it to the console where your script is running.
|
||||||
|
|
||||||
Register your app at
|
Register your app at
|
||||||
`My Applications
|
`My Applications
|
||||||
<https://developer.spotify.com/my-applications/#!/applications>`_.
|
<https://developer.spotify.com/my-applications/#!/applications>`_.
|
||||||
|
|
||||||
|
|
||||||
*spotipy* supports two authorization flows:
|
*spotipy* supports two authorization flows:
|
||||||
|
|
||||||
- The **Authorization Code flow** This method is suitable for long-running applications
|
- The **Authorization Code flow** This method is suitable for long-running applications
|
||||||
which the user logs into once. It provides an access token that can be refreshed.
|
which the user logs into once. It provides an access token that can be refreshed.
|
||||||
|
|
||||||
- The **Client Credentials flow** The method makes it possible
|
- The **Client Credentials flow** The method makes it possible
|
||||||
@ -132,14 +132,14 @@ user. You can pass your app credentials directly into the method as arguments::
|
|||||||
|
|
||||||
util.prompt_for_user_token(username,scope,client_id='your-spotify-client-id',client_secret='your-spotify-client-secret',redirect_uri='your-app-redirect-url')
|
util.prompt_for_user_token(username,scope,client_id='your-spotify-client-id',client_secret='your-spotify-client-secret',redirect_uri='your-app-redirect-url')
|
||||||
|
|
||||||
or if you are reluctant to immortalize your app credentials in your source code,
|
or if you are reluctant to immortalize your app credentials in your source code,
|
||||||
you can set environment variables like so::
|
you can set environment variables like so::
|
||||||
|
|
||||||
export SPOTIPY_CLIENT_ID='your-spotify-client-id'
|
export SPOTIPY_CLIENT_ID='your-spotify-client-id'
|
||||||
export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
|
export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
|
||||||
export SPOTIPY_REDIRECT_URI='your-app-redirect-url'
|
export SPOTIPY_REDIRECT_URI='your-app-redirect-url'
|
||||||
|
|
||||||
Call ``util.prompt_for_user_token`` method with the username and the
|
Call ``util.prompt_for_user_token`` method with the username and the
|
||||||
desired scope (see `Using
|
desired scope (see `Using
|
||||||
Scopes <https://developer.spotify.com/web-api/using-scopes/>`_ for information
|
Scopes <https://developer.spotify.com/web-api/using-scopes/>`_ for information
|
||||||
about scopes) and credentials. This will coordinate the user authorization via
|
about scopes) and credentials. This will coordinate the user authorization via
|
||||||
@ -195,8 +195,8 @@ class SpotifyClientCredentials that can be used to authenticate requests like so
|
|||||||
playlists = None
|
playlists = None
|
||||||
|
|
||||||
Client credentials flow is appropriate for requests that do not require access to a
|
Client credentials flow is appropriate for requests that do not require access to a
|
||||||
user's private data. Even if you are only making calls that do not require
|
user's private data. Even if you are only making calls that do not require
|
||||||
authorization, using this flow yields the benefit of a higher rate limit
|
authorization, using this flow yields the benefit of a higher rate limit
|
||||||
|
|
||||||
IDs URIs and URLs
|
IDs URIs and URLs
|
||||||
=======================
|
=======================
|
||||||
@ -260,7 +260,7 @@ Shows the contents of every playlist owned by a user::
|
|||||||
def show_tracks(tracks):
|
def show_tracks(tracks):
|
||||||
for i, item in enumerate(tracks['items']):
|
for i, item in enumerate(tracks['items']):
|
||||||
track = item['track']
|
track = item['track']
|
||||||
print(" %d %32.32s %s" % (i, track['artists'][0]['name'],
|
print(" %d %32.32s %s" % (i, track['artists'][0]['name'],
|
||||||
track['name']))
|
track['name']))
|
||||||
|
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ Shows the contents of every playlist owned by a user::
|
|||||||
print()
|
print()
|
||||||
print(playlist['name'])
|
print(playlist['name'])
|
||||||
print (' total tracks', playlist['tracks']['total'])
|
print (' total tracks', playlist['tracks']['total'])
|
||||||
results = sp.user_playlist(username, playlist['id'],
|
results = sp.user_playlist(username, playlist['id'],
|
||||||
fields="tracks,next")
|
fields="tracks,next")
|
||||||
tracks = results['tracks']
|
tracks = results['tracks']
|
||||||
show_tracks(tracks)
|
show_tracks(tracks)
|
||||||
@ -298,7 +298,7 @@ More Examples
|
|||||||
There are many more examples of how to use *Spotipy* in the `Examples
|
There are many more examples of how to use *Spotipy* in the `Examples
|
||||||
Directory <https://github.com/plamere/spotipy/tree/master/examples>`_ on Github
|
Directory <https://github.com/plamere/spotipy/tree/master/examples>`_ on Github
|
||||||
|
|
||||||
API Reference
|
API Reference
|
||||||
==============
|
==============
|
||||||
|
|
||||||
:mod:`client` Module
|
:mod:`client` Module
|
||||||
@ -336,7 +336,7 @@ You can ask questions about Spotipy on Stack Overflow. Don’t forget to add t
|
|||||||
|
|
||||||
http://stackoverflow.com/questions/ask
|
http://stackoverflow.com/questions/ask
|
||||||
|
|
||||||
If you think you've found a bug, let us know at
|
If you think you've found a bug, let us know at
|
||||||
`Spotify Issues <https://github.com/plamere/spotipy/issues>`_
|
`Spotify Issues <https://github.com/plamere/spotipy/issues>`_
|
||||||
|
|
||||||
|
|
||||||
@ -344,24 +344,25 @@ Contribute
|
|||||||
==========
|
==========
|
||||||
Spotipy authored by Paul Lamere (plamere) with contributions by:
|
Spotipy authored by Paul Lamere (plamere) with contributions by:
|
||||||
|
|
||||||
- Daniel Beaudry // danbeaudry
|
- Daniel Beaudry // danbeaudry
|
||||||
- Faruk Emre Sahin // fsahin
|
- Faruk Emre Sahin // fsahin
|
||||||
- George // rogueleaderr
|
- George // rogueleaderr
|
||||||
- Henry Greville // sethaurus
|
- Henry Greville // sethaurus
|
||||||
- Hugo // hugovk
|
- Hugo // hugovk
|
||||||
- José Manuel Pérez // JMPerez
|
- José Manuel Pérez // JMPerez
|
||||||
- Lucas Nunno // lnunno
|
- Lucas Nunno // lnunno
|
||||||
- Lynn Root // econchick
|
- Lynn Root // econchick
|
||||||
- Matt Dennewitz // mattdennewitz
|
- Matt Dennewitz // mattdennewitz
|
||||||
- Matthew Duck // mattduck
|
- Matthew Duck // mattduck
|
||||||
- Michael Thelin // thelinmichael
|
- Michael Thelin // thelinmichael
|
||||||
- Ryan Choi // ryankicks
|
- Ryan Choi // ryankicks
|
||||||
- Simon Metson // drsm79
|
- Simon Metson // drsm79
|
||||||
- Steve Winton // swinton
|
- Steve Winton // swinton
|
||||||
- Tim Balzer // timbalzer
|
- Tim Balzer // timbalzer
|
||||||
- corycorycory // corycorycory
|
- corycorycory // corycorycory
|
||||||
- Nathan Coleman // nathancoleman
|
- Nathan Coleman // nathancoleman
|
||||||
- Michael Birtwell // mbirtwell
|
- Michael Birtwell // mbirtwell
|
||||||
|
- Harrison Hayes // Harrison97
|
||||||
|
|
||||||
License
|
License
|
||||||
=======
|
=======
|
||||||
|
|||||||
@ -35,7 +35,7 @@ def show_artist_albums(id):
|
|||||||
unique = set() # skip duplicate albums
|
unique = set() # skip duplicate albums
|
||||||
for album in albums:
|
for album in albums:
|
||||||
name = album['name'].lower()
|
name = album['name'].lower()
|
||||||
if not name in unique:
|
if not name in unique:
|
||||||
print(name)
|
print(name)
|
||||||
unique.add(name)
|
unique.add(name)
|
||||||
show_album_tracks(album)
|
show_album_tracks(album)
|
||||||
|
|||||||
@ -10,7 +10,7 @@ if len(sys.argv) > 2:
|
|||||||
username = sys.argv[1]
|
username = sys.argv[1]
|
||||||
tids = sys.argv[2:]
|
tids = sys.argv[2:]
|
||||||
else:
|
else:
|
||||||
print("Usage: %s username track-id ..." % (sys.argv[0],))
|
print("Usage: %s username track-id ..." % (sys.argv[0],))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
token = util.prompt_for_user_token(username, scope)
|
token = util.prompt_for_user_token(username, scope)
|
||||||
|
|||||||
@ -26,6 +26,6 @@ if token:
|
|||||||
for i, item in enumerate(results['items']):
|
for i, item in enumerate(results['items']):
|
||||||
print (i, item['name'], '//', item['artists'][0]['name'])
|
print (i, item['name'], '//', item['artists'][0]['name'])
|
||||||
print ()
|
print ()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Can't get token for", username)
|
print("Can't get token for", username)
|
||||||
|
|||||||
@ -60,4 +60,4 @@ if __name__ == '__main__':
|
|||||||
import sys
|
import sys
|
||||||
title = ' '.join(sys.argv[1:])
|
title = ' '.join(sys.argv[1:])
|
||||||
make_chain(sys.argv[1].lower())
|
make_chain(sys.argv[1].lower())
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# Gets all the public playlists for the given
|
# Gets all the public playlists for the given
|
||||||
# user. Uses Client Credentials flow
|
# user. Uses Client Credentials flow
|
||||||
#
|
#
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import spotipy
|
import spotipy
|
||||||
|
|||||||
@ -389,7 +389,7 @@ class Spotify(object):
|
|||||||
|
|
||||||
def playlist(self, playlist_id, fields=None, market=None):
|
def playlist(self, playlist_id, fields=None, market=None):
|
||||||
""" Gets playlist by id
|
""" Gets playlist by id
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- playlist - the id of the playlist
|
- playlist - the id of the playlist
|
||||||
- fields - which fields to return
|
- fields - which fields to return
|
||||||
@ -400,7 +400,7 @@ class Spotify(object):
|
|||||||
|
|
||||||
return self._get("playlists/%s" % (plid), fields=fields)
|
return self._get("playlists/%s" % (plid), fields=fields)
|
||||||
|
|
||||||
|
|
||||||
def user_playlist_tracks(self, user, playlist_id=None, fields=None,
|
def user_playlist_tracks(self, user, playlist_id=None, fields=None,
|
||||||
limit=100, offset=0, market=None):
|
limit=100, offset=0, market=None):
|
||||||
""" Get full details of the tracks of a playlist owned by a user.
|
""" Get full details of the tracks of a playlist owned by a user.
|
||||||
@ -546,9 +546,11 @@ class Spotify(object):
|
|||||||
Parameters:
|
Parameters:
|
||||||
- user - the id of the user
|
- user - the id of the user
|
||||||
- playlist_id - the id of the playlist
|
- playlist_id - the id of the playlist
|
||||||
- tracks - an array of objects containing Spotify URIs of the tracks to remove with their current positions in the playlist. For example:
|
- tracks - an array of objects containing Spotify URIs of the
|
||||||
[ { "uri":"4iV5W9uYEdYUVa79Axb7Rh", "positions":[2] },
|
tracks to remove with their current positions in the
|
||||||
{ "uri":"1301WleyT98MSxVHPZCA6M", "positions":[7] } ]
|
playlist. For example:
|
||||||
|
[ { "uri":"4iV5W9uYEdYUVa79Axb7Rh", "positions":[2] },
|
||||||
|
{ "uri":"1301WleyT98MSxVHPZCA6M", "positions":[7] } ]
|
||||||
- snapshot_id - optional id of the playlist snapshot
|
- snapshot_id - optional id of the playlist snapshot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -583,7 +585,8 @@ class Spotify(object):
|
|||||||
Parameters:
|
Parameters:
|
||||||
- playlist_owner_id - the user id of the playlist owner
|
- playlist_owner_id - the user id of the playlist owner
|
||||||
- playlist_id - the id of the playlist
|
- playlist_id - the id of the playlist
|
||||||
- user_ids - the ids of the users that you want to check to see if they follow the playlist. Maximum: 5 ids.
|
- user_ids - the ids of the users that you want to check to see
|
||||||
|
if they follow the playlist. Maximum: 5 ids.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self._get("users/{}/playlists/{}/followers/contains?ids={}".format(playlist_owner_id, playlist_id, ','.join(user_ids)))
|
return self._get("users/{}/playlists/{}/followers/contains?ids={}".format(playlist_owner_id, playlist_id, ','.join(user_ids)))
|
||||||
@ -705,7 +708,7 @@ class Spotify(object):
|
|||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- limit - the number of entities to return
|
- limit - the number of entities to return
|
||||||
'''
|
'''
|
||||||
return self._get('me/player/recently-played', limit=limit)
|
return self._get('me/player/recently-played', limit=limit)
|
||||||
|
|
||||||
def current_user_saved_albums_delete(self, albums=[]):
|
def current_user_saved_albums_delete(self, albums=[]):
|
||||||
@ -760,7 +763,7 @@ class Spotify(object):
|
|||||||
- ids - a list of artist IDs
|
- ids - a list of artist IDs
|
||||||
'''
|
'''
|
||||||
return self._delete('me/following?type=artist&ids=' + ','.join(ids))
|
return self._delete('me/following?type=artist&ids=' + ','.join(ids))
|
||||||
|
|
||||||
def user_unfollow_users(self, ids=[]):
|
def user_unfollow_users(self, ids=[]):
|
||||||
''' Unfollow one or more users
|
''' Unfollow one or more users
|
||||||
Parameters:
|
Parameters:
|
||||||
|
|||||||
@ -25,7 +25,7 @@ CLIENT_CREDS_ENV_VARS = {
|
|||||||
def prompt_for_user_token(username, scope=None, client_id = None,
|
def prompt_for_user_token(username, scope=None, client_id = None,
|
||||||
client_secret = None, redirect_uri = None, cache_path = None):
|
client_secret = None, redirect_uri = None, cache_path = None):
|
||||||
''' prompts the user to login if necessary and returns
|
''' prompts the user to login if necessary and returns
|
||||||
the user token suitable for use with the spotipy.Spotify
|
the user token suitable for use with the spotipy.Spotify
|
||||||
constructor
|
constructor
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
@ -57,13 +57,13 @@ def prompt_for_user_token(username, scope=None, client_id = None,
|
|||||||
export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
|
export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
|
||||||
export SPOTIPY_REDIRECT_URI='your-app-redirect-url'
|
export SPOTIPY_REDIRECT_URI='your-app-redirect-url'
|
||||||
|
|
||||||
Get your credentials at
|
Get your credentials at
|
||||||
https://developer.spotify.com/my-applications
|
https://developer.spotify.com/my-applications
|
||||||
''')
|
''')
|
||||||
raise spotipy.SpotifyException(550, -1, 'no credentials set')
|
raise spotipy.SpotifyException(550, -1, 'no credentials set')
|
||||||
|
|
||||||
cache_path = cache_path or ".cache-" + username
|
cache_path = cache_path or ".cache-" + username
|
||||||
sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, redirect_uri,
|
sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, redirect_uri,
|
||||||
scope=scope, cache_path=cache_path)
|
scope=scope, cache_path=cache_path)
|
||||||
|
|
||||||
# try to get a valid token for this user, from the cache,
|
# try to get a valid token for this user, from the cache,
|
||||||
@ -98,7 +98,7 @@ def prompt_for_user_token(username, scope=None, client_id = None,
|
|||||||
response = input("Enter the URL you were redirected to: ")
|
response = input("Enter the URL you were redirected to: ")
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print()
|
print()
|
||||||
|
|
||||||
code = sp_oauth.parse_response_code(response)
|
code = sp_oauth.parse_response_code(response)
|
||||||
token_info = sp_oauth.get_access_token(code)
|
token_info = sp_oauth.get_access_token(code)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user