Commit Graph

140 Commits

Author SHA1 Message Date
Aref
51c5bd8d7d
Advanced examples (#986)
* Created a testing suite for the spotipy client.Spotify class

* Delete pyvenv.cfg

* Corrected error in description

* Added some advanced usage examples, some of which involve utilizing basic data analysis methods using other libraries such as Pandas

* Minor formatting fixes

---------

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2024-07-09 20:02:07 +01:00
wouldube
a810edf5da
Corrections to Grammar Errors and Typos in Documentation (#1017)
* Fixed grammar errors and typos.

* Update CHANGELOG.md to mention documentation typo corrections.

---------

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2024-05-30 19:37:39 +01:00
Hugo van Kemenade
85c9d74dc1
Drop support for EOL Python 3.7 (#1065)
* Add python_requires to help pip

* Update supported versions in tox.ini

* Upgrade Python syntax with pyupgrade --py37-plus

* Bump GitHub Actions

* Add Python 3.11 and 3.12 to CI

* Remove six dependency

* Remove redundant dependencies

* Remove redudant Python 3.5 code

* Drop support for EOL Python 3.7

* Upgrade Python syntax with pyupgrade --py38-plus

* Update CHANGELOG

* More f-strings

---------

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2024-05-21 18:32:01 +02:00
Niko
160a57a1d6
Merge pull request #1069 from democat3457/patch-1
Fix unused description parameter in playlist creation example
2024-05-14 11:03:58 +02:00
Jack Dane
97c9917a02 Use the playlist_items function to retrieve tracks.
* It will request the same endpoint as sp.next with the same fields for consistency.
2024-05-06 10:43:21 +01:00
Colin Wong
e3629cdacb
Use unused description parameter in example 2024-01-06 00:20:53 -06:00
Mario Sessa
262e7a0443
Rename simple files (#933) 2023-01-23 12:48:37 +00:00
oliveraw
922d51df02
modified docstring for playlist_add_items to no longer accept IDs 2022-12-16 19:17:37 +00:00
Mason Stephenson
edd3f29a2c
Getting Started Clarifications and Example Code File (#904)
* added URI link to README getting started

* revised comment

* added alternate module installation instruction

* installation troubleshooting comment

* scope clarification comment

* added playlist_add_items.py to examples folder

* reformatted changelog edits

* Relocated added contributions to added section in Changelog

* removed unnecessary library installation instruction

* Clarified alternative installation instruction
2022-12-10 16:27:29 +00:00
Bryan Malyn
7fc08809f0
Add FlaskSessionCacheHandler (#833)
Updated examples/app.py
Updated CHANGELOG.md and appropriate docs.
2022-06-25 20:00:08 +01:00
dnlruiz
a4cfd83946
show_featured_artists.py and update publishing docs (#821)
* show_featured_artists.py and update publishing docs

* Don't update version

Co-authored-by: Stéphane Bruckert <contact@stephanebruckert.com>
2022-06-18 23:26:43 +01:00
Logan O'Connell
13593c54cb
Added a new example: follow_playlist.py (#804)
* Create playlist_all_local_tracks.py

* Delete playlist_all_local_tracks.py

* Create follow_playlist.py
2022-06-18 23:19:27 +01:00
rautskaa
2aeda6a2c2
Adding example for unfollowing/deleting a playlist (#746)
* Adding example for deleting a playlist

* Renaming to unfollow_playlist
2021-11-23 21:48:53 +00:00
yashsinha848
f42024737e
Update artist_discography.py (#664) 2021-04-04 11:52:02 +01:00
yashsinha848
8db120f985
Update simple3.py (#663) 2021-04-04 11:51:55 +01:00
KnallbertLp
fa57f6d3e2
Removed requirement for examples/app.py to specify port multiple times (only SPOTIPY_REDIRECT_URI needs to contain the port) (#636) 2021-01-30 22:10:30 +01:00
Tony Jackson
a7b25d0f6e
Add deprecation warnings to direct users towards using cache_handler (#630)
* Refactor functions into static methods of AuthBase

Functions is_token_expired was a loose function that was added to
SpotifyClientCredentials, SpotifyPKCE, and SpotifyImplicitGrant classes
through a method on each class that passed the call to the loose
is_token_expired function. Function _is_scope_subset was duplicated on
SpotifyClientCredentials, SpotifyPKCE, and SpotifyImplicitGrant classes.

Refactoring is_token_expired and _is_scope_subset to be static methods
on SpotifyAuthBase means both are available for all derived classes and
require less boilerplate.

* Create CacheHandler to abstract caching tokens

Previous code only supported caching to and from json files in a given
directory. In addition, the get_cached_token method mixed getting and
getting the token in the same method.

This change creates a CacheHandler class to abstract out the caching
implementation and allow the user to cache tokens in any way they
see fit. For example, the user could create a MongoCache class to store
and retrieve tokens from a Mongo database and specify that
cache_handler=MongoCache in creating an auth_manager object.

To implement the CacheHandler abstraction, the following changes are
implemented:

The validation code in each get_cached_token method in SpotifyOAuth,
SpotifyPKCE, and SpotifyImplicitGrant is moved into a validate_token
method in each class.

The CacheHandler class is created with get_cached_token and
save_token_to_cache methods.

Previous instances of self.get_cached_token() are now replaced with
self.validate_token(self.cache_handler.get_cached_token()) to preserve
the getting and validation behaviour.

cache_handler is added as an argument to SpotifyOAuth, SpotifyPKCE, and
SpotifyImplicitGrant. Specifying a cache_handler now overrides any
specification of cache_path and/or username.

To preserve backwards compatibility in handling cache files, a
CacheFileHandler class extending CacheHandler is created. If no
cache_handler is specified, the cache_path and username arguments are
used to create an instance of CacheFileHandler. It may be worth
deprecating the cache_path and username fields in favour of using
CacheFileHandler.

Tests are also modified and extended to cover the new functionality. A
sample MemoryCache CacheHandler is created to test getting and saving to
a custom CacheHandler.

* Fix cache_handler subclass check for Python 2

* Split assert message to fix line over max length

* Split cache handlers into cache_handler.py

* flake8 and autopep fixes

* Fix init to allow importing CacheHandler

When spotipy is installed as a package, CacheHandler is not accessible
from a `from spotipy import CacheHandler` statement because the import
is not specified in the __init__.py file. This commit adds CacheHandler
and CacheFileHandler to the init file so the user can import them.

* flake8 fix

* Add cache_path & username deprecation warning

When cache_path or username are specified in the constructors of
SpotifyOAuth, SpotifyPKCE, or SpotifyImplicitGrant, the constructor
creates a CacheFileHandler instance under the hood. The user is
currently able to create a CacheFileHandler instance in two ways:

1.  By creating it outside the SpotifyOAuth (or etc.) constructor and
    passing it as the cache_handler
2.  By passing cache_path and username to the constructor

Ideally, there would be one and only one obvious way to specify a
CacheFileHandler instance and the cache_handler approach allows any
CacheHandler to be used, so passing the cache_path or username to the
constructor should be deprecated.

* Update flask example to use CacheFileHandler

* Update changelog with deprecation warning info

* Restore token caching methods on auth_manager

Change 9550c8fd86 in
https://github.com/plamere/spotipy accidentally broke the caching
functionality in SpotifyOAUth, SpotifyPKCE, and SpotifyImplicitGrant by
removing the get_cached_token and _save_token_info methods from the
auth_manager object. Users with existing codebases that use the
get_cached_token and _save_token_info methods directly will experience
errors if they upgrade spotipy.

This commit restores the get_cached_token and _save_token_info methods
on the three auth_manager classes as aliases for the corresponding
methods in the cache_handler. Deprecation warnings are also added to
the get_cached_token and _save_token_info methods to direct users to
switch to using the new cache_handler approach.

* Add deprecation warning to docstrings

* Rearrange depr. warn for cache_path & username

Rearrange logic so that deprecation warning always triggers if
cache_path or username are specified. Previously, if cache_handler was
specified, no deprecation warning would be raised if cache_path or
username were specified.

In addition, if both cache_handler and cache_path or username are
specified, a new warning will be raised alongside the deprecation
warning to let the user know that the cache_path and username fields
will be ignored in favour of the cache_handler.
2021-01-13 11:34:53 +01:00
Joshua Baunach
ec8a1105b1
Fix examples for saved tracks (#624)
This fixes the examples showin in delete_a_saved_track.py and contains_a_saved_track.py
2020-12-13 02:55:42 +00:00
Miguel Ángel
3f2592d631
Small adjustment on sign_out function (#603)
* Small adjustment on sing_out function

First, thanks for this. It has been a great help. I was having trouble with this function, getting a TypeError (TypeError: can only concatenate str (not "NoneType") to str) because apparently the second os.remove(session_cache_path()) is trying to delete a file that does not exist anymore so this is what worked for me.

* Change description on app.py file

* Update app.py on line 79

Fixed indent
2020-11-11 19:55:29 +00:00
slipstream42
275cd7ea89
Added scope, 'playlist-read-private', to examples that access user playlists using the spotipy api: current_user_playlists() (fixes #591) (#595)
* - Added scope, 'playlist-read-private', to examples that access user playlists using the spotipy api: current_user_playlists() (fixes #591)

* Fix example to use user_playlists again

Co-authored-by: Stephane Bruckert <stephane.bruckert@gmail.com>
2020-10-23 22:57:14 +01:00
fathom9x
bea781d28f
Fixed output of playlist_tracks example (#594)
Co-authored-by: Chris Danger <chris@The-Castle-Tower.local>
2020-10-23 17:35:16 +01:00
Nick
87fe473672
Allow open_browser to be set on creation of auth_manager (SpotifyOAuth/SpotifyPKCE) (#574)
* Fix plamere/spotipy#560

* Adhere to code style

* Update CHANGELOG.md for changes in 939f869bbc

* open_browser passed to get_auth_response should take precedence over the same argument in the constructor

* Update FAQ

* Add information about headless auth

* Add headless auth example
2020-09-12 12:14:08 +01:00
Stéphane Bruckert
d0ca977647
Made cache_path and username optional (#567)
* Made cache_path and username optional

* Update readme and example

* Lint

* Lint

* Feedback / add warning
2020-08-30 23:59:38 +01:00
Mike iLL Kilmer
004df7b2df
A few updates to the example app (#540)
* No username needed + can be used by multiple users

* cleanup

* Remove caches when signing out

* Persist token only once

* Always show auth page

* Add one scope..

* Add a second scope and also a view which utilizes a scope.

* Add a __main__ clause example.

* Include further documentation.

* Move utility function higher in document.

* Add threading to application run call in __main__.

* Add (or reinstate–I thought it had been there) the "me" view.

* Add notes about SPOTIPY_REDIRECT_URI and using alternate port.

And specify that it should be the address that the App runs over.

* Whitespace only.

* Here is an example of importing credentials.

* Delete session_cache file on logout so new user can Authorize.

* Not going to use at this point.

* Update the "me" route method to use new approach to auth.

* Update app.py

Co-authored-by: Stephane Bruckert <contact@stephanebruckert.com>
Co-authored-by: Stephane Bruckert <stephane.bruckert@gmail.com>
2020-07-30 23:05:47 +01:00
Stéphane Bruckert
f136442c2d
Fix Flask example app (#539) 2020-07-26 20:46:35 +01:00
IdmFoundInHim
88cf75b778
Update Playlist Endpoints and Add Following Endpoints (#531)
* Update playlist endpoints to modern format

Deprecate user_playlist_* in favor of the following replacements:
* user_playlist_change_details -> playlist_change_details
* user_playlist_unfollow -> current_user_unfollow_playlist
* user_playlist_add_tracks -> playlist_add_tracks
* user_playlist_replace_tracks -> playlist_replace_tracks
* user_playlist_reorder_tracks -> playlist_reorder_tracks
* user_playlist_remove_all_occurrences_of_tracks -> playlist_remove_all_occurrences_of_tracks
* user_playlist_remove_specific_occurrences_of_tracks -> playlist_remove_specific_occurrences_of_tracks
* user_playlist_follow_playlist -> current_user_follow_playlist
* user_playlist_is_following -> playlist_is_following

* Add current_user_following_artists and current_user_following_users

* Update tests and examples

Resolve TODO in test_user_endpoints.py > SpotifyFollowApiTests.test_user_follows_and_unfollows_user

Use modern playlist endpoints (no username required) in tests and examples.

* Update changelog

* Deprecate playlist_tracks in favor of playlist_items

* Link deprecated functions to new functions and change tracks to items

* Fix references to playlist_tracks

* Change test_playlist_add_items as requested
2020-07-11 11:23:18 +01:00
Mike iLL Kilmer
7eb0eaaebc
Add redirect_uri (#529)
And specify that it should be the address that the App runs over.
2020-07-06 18:58:39 +01:00
Omglolyes
a8b77ac37d
Get all non-local tracks from a spotify playlist (#518)
* Create playlist_all_tracks.py

* Update playlist_all_tracks.py

forgot first items from playlist

* print result instead of returning it

* rename to playlist_all_non_local_tracks

* Update playlist_all_non_local_tracks.py

removed "== True" as it's implied
give an example playlist (global top 50)
more comments
corrected typo

* print only length and excluding instead of entire result
2020-06-30 18:15:25 +01:00
Stephane Bruckert
c7f2edf343 Deprecate util.prompt_for_user_token() 2020-06-14 18:01:14 +01:00
Stephane Bruckert
587baec9b9 Example to use spotipy in an API, closes #287 2020-05-30 16:39:53 +01:00
Dj
b01adba826
Print -> Logging, fixes #84 (#461) 2020-04-03 23:03:09 +01:00
Stephane Bruckert
37b6b5fd80 Add multiple accounts example, solves #446 2020-03-12 00:53:36 +00:00
Stephane Bruckert
28485cfa3e Lint 2020-02-22 11:15:19 +00:00
Stephane Bruckert
9ed584b398 Player endpoints example and test 2020-02-22 11:12:29 +00:00
Stephane Bruckert
60f530842d Fix 2020-02-12 23:14:26 +00:00
Stephane Bruckert
14268a8a2c Add playlist_tracks example 2020-02-12 23:08:42 +00:00
Stefano
4515446a65 Auto-refresh AuthCode flow token. (#435)
* Auto-refresh AuthCode flow token.

* Reformatted.

* Reformatted.

* Removed invalid syntax.

* Removed abstract class SpotifyAuthManager.

* Fix typo on docstrings.

* Optionally try to fetch main input parameters from environment.

Implements the capability of trying to fetch the following parameters from the environment, when they're not directly passed to the authorization handler.
The affected parameters are: client_id, client_secret, redirect_uri.
An SpotifyOauthError is raised if no value gets found.

* Removed f-string for Python2 compatibility.

* Fix line-too-long.

* Remove useless import.

* Add username to docstring.

* Remove redundant return.

* Fix empty lines print statement for backward compatibility with Python2.

* Update simple4 example.

* Set optional 'as_dict' parameter on OAuth 'get_access_token'.

* Update changelog.

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2020-02-10 10:20:02 +00:00
Stephane Bruckert
26db832e24 Temporarily revert #428 2020-01-23 10:06:19 +00:00
Peter
87a72a060f Automatic refresh of Authorization Code Flow Tokens in long-running Applications (#428)
* auto-refresh user token

* example for a long-running user-request app

* wrap long lines

* combine duplicate code into _refresh_token_if_expired method

* add changelog entry
2020-01-22 20:01:30 +00:00
Stephane Bruckert
44911f7285 Fix show_my_saved_tracks example, closes #70 2020-01-17 19:12:26 +00:00
Stephane Bruckert
45c3e5e951 Update/remove outdated examples 2020-01-16 23:47:18 +00:00
Stephane Bruckert
83a1cb54ef Fix doc and readme 2020-01-16 03:54:39 +00:00
Stéphane Bruckert
9b8c90dbe1
Merge branch 'master' into master 2020-01-15 19:16:38 +00:00
Stéphane Bruckert
f54830e272
Add linter, solves #348 (#415) 2020-01-12 13:19:40 +00:00
Stéphane Bruckert
9b3b61bdc4
Merge pull request #224 from foxyblue/clean-examples
Clean examples
2020-01-12 00:48:11 +00:00
Stephane Bruckert
c4b302b4e2 Fix example 2020-01-12 00:22:57 +00:00
Stéphane Bruckert
2be6763d0d
Merge pull request #303 from wdr1/patch-1
Update create_playlist.py
2020-01-12 00:10:03 +00:00
Stephane Bruckert
6ab96c3c91 Clean up + missing tests 2020-01-11 23:30:57 +00:00
Ryan Lee
c610090a7c Upload user_saved_albums_delete.py 2020-01-11 19:56:32 +00:00
Harrison
d8d9f290fb remove unneccesary whitespaces, shorten some lines, and add name to contibutors 2020-01-11 19:56:00 +00:00