Commit Graph

292 Commits

Author SHA1 Message Date
Nick
22e3b7406d
Update current_user_follow_playlist (#1040)
* Update current_user_follow_playlist

The API specifies a `public` parameter as seen [here](https://developer.spotify.com/documentation/web-api/reference/follow-playlist)

* Update CHANGELOG.md

---------

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2024-05-30 19:43:10 +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
andrewcara
62a27a20e0
Added MemcacheCacheHandler (#1042)
* Added MemcacheCacheHandler

* Import MemcacheError where used

* Update index.rst

---------

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2024-05-30 19:01:16 +01:00
Niko
939b7557a5
Updated _regex_spotify_url to ignore /intl-<countrycode> in Spotify links (#1100)
* Updated _regex_spotify_url to ignore /intl-<countrycode> in Spotify links

* Updated documentation link and added some additional information
2024-05-22 12:43:04 +02: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
3b5708f5a0
Update spotipy/client.py
Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2024-05-17 14:38:19 +02:00
Niko
52f2b923ba
Removing whitespace (new IDE, sorry) 2024-05-17 12:46:23 +02:00
Niko
f4c2b90a29
Made sure that the line column is not over 99. 2024-05-17 12:41:57 +02:00
Niko
0a8e7f635e
Added missing comma to artist_albums 2024-05-17 12:37:54 +02:00
Niko
2e54f2c138
Replaced argument "album_type" with "include_groups" in "Spotify.artist_albums" 2024-05-17 12:35:23 +02:00
Niko
6d8d9d1f9b
Merge branch 'master' into bug/inheriting-exceptions-in-init 2024-05-15 16:16:08 +02:00
Dan Joseph
1416d47cba
Audiobook Support and CI Workflow Update (#1036)
* Implement audiobook endpoints

* Update GitHub CI Workflow: Removed Python v2.7

* Update GitHub CI Workflow: Removed Python v3.6

* Add integration tests for audiobook endpoints
2023-10-31 01:32:46 +00:00
John Cheng
6cc817af85 ignore if _session does not exist 2023-04-11 23:29:37 -04:00
Richard Ngo-Lam
fe438c0432
Update search_markets method to apply the total parameter to all types, add tests (#901)
* Update search_markets method to apply the total parameter to all types, fixes #534

* Add integration tests for searching multiple types in multiple markets

* Update search_markets method to apply the total parameter to all types, add tests

---------

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2023-03-15 23:46:08 +00:00
Ludwig Johansson
f2d23e2219
Fix regex to support detailed URI #947 (#949)
* Fix regex to support detailed URI as #947

* Added changes to changelog
2023-03-15 15:17:02 +00:00
Andrii Yurchuk
572195617b
Fix SpotifyPKCE docstring (#942) 2023-02-14 14:00:59 +00:00
Shawn Cruz
b3f308d289
Add encoder_cls argument to CacheFileHandler (#941)
Fixes
2023-02-12 22:58:55 +00:00
Stephane Bruckert
beec3dad1f Fix flake8 2023-01-23 18:54:40 +00:00
Shaderbug
b1db0b63d9
Merge pull request from GHSA-q764-g6fm-555v
* Improve URL and URI handling

* Back to SpotifyException for backward-compatibility

* fix copy paste typo

* TODO v3 comments

Co-authored-by: Stephane Bruckert <stephane.bruckert@gmail.com>
2023-01-23 18:50:07 +00:00
Archie Baldry
d884ae13c2
Fix typo in start_playback function (#930) 2023-01-15 23:30:37 +00:00
oliveraw
922d51df02
modified docstring for playlist_add_items to no longer accept IDs 2022-12-16 19:17:37 +00:00
Bruno Alla
fa44fed76d
Fix a few typos in comments & strings (#866) 2022-10-29 14:23:43 +01:00
Job Doesburg
be759d3f50
Implement get-queue endpoint (#854) 2022-10-29 13:01:25 +01: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
Stephane Bruckert
61c8cda006 Fix lint 2022-06-18 23:24:49 +01:00
kanari1
6164dbb628
Fixed and clarified docstrings for client.py (#820)
* fixed docstring for current_user_following_users_function

* Edited docstrings for playlist_cover_image, user_playlist, user_playlist_replace_tracks, user_playlist_reorder_tracks functions

* expanded docstring description of playlist_change_details function to include changes to collaborative state and/or description
2022-06-18 23:20:37 +01:00
ivyadam
5175f19851
Updated documentation about ISO-639 language codes and address issue #753 (#800)
* Updated references to ISO 639 standard to clarify that the ISO 639-1 alpha-2 standard is used.

* Added `market` parameter to `album` and `albums`

* fix formatting change
2022-06-18 23:18:59 +01:00
Mohammad Momeni
72a6cd9190
Fix text attribute for Response object (#811)
* Fix text attribute for Response object

* Add a changelog for the AttributeError PR
2022-06-18 23:17:58 +01:00
ENT8R
9a627e88f4
Simplify check for existing token (#765)
* Simplify check for existing token in RedisCacheHandler

* Update CHANGELOG.md
2022-01-03 19:33:13 +01:00
ENT8R
08411b9031
Allow to set custom key in RedisCacheHandler (#761)
* Allow to set custom key in RedisCacheHandler

* Update CHANGELOG.md

* Check for the existence of the key
2021-12-22 15:44:38 +01:00
Felix Cusson
0464f4f483
Remove query parameters from URI (#758)
* made _get_id take account of ? in URI

* corrected typo

* changes to _get_id explained
2021-12-17 22:20:47 +00:00
Takehisa Oyama
7d23fc3277
Add RedisCacheHandler (#747)
* add RedisCacheHandler

* add the explanation for customized chache handlers

* update the dependency and chengelog
2021-11-22 19:31:58 +00:00
Yash
a81aa595ba
Fixed some playlist functions docstrings (#732)
playlist_items(), playlist_cover_image() functions can take ID, URI or URL. Current docstring only mentions ID. This can also be verified and tested out. Example in examples folder also uses URI with playlist_items().
2021-09-30 22:01:12 +01:00
dvirOsher
1a6df54111
update current_user_saved_albums function message (#697)
max limit spotipy can handler without getting any HTTP 401 error is 50.
2021-06-26 20:20:45 +01:00
Peter Schorn
06551cd055
Fallback on decoding error responses into string if decoding into JSON fails (#689)
* Fixed a bug in the initializers for the auth managers that produced a spurious warning message if you provide a cache handler and you set a value for the "SPOTIPY_CLIENT_USERNAME" environment variable.

* fixed a bug in _get_auth_response_local_server which occurs if you provide a state parameter and click cancel in the authorization dialog

* Fallback on decoding the error response body into text if decoding into JSON fails.

* Fall back on decoding oauth errors into text if decoding into JSON fails.

* Fixed unused `http_error` name in exeception clause.

* Updated CHANGELOG

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2021-06-19 15:59:02 +02:00
Varun Patil
d0fc4425f7
Added DjangoSessionCacheHandler (#691)
* Added DjangoSessionCacheHandler

Added `DjangoSessionCacheHandler`, a cache handler that stores the token in the session framework provided by Django. Web apps using spotipy with Django can directly use this for cache handling.

* removed whitespaces
2021-06-19 15:57:36 +02:00
Peter Schorn
c4f6a3fa4b
Fixed a bug in the initializers for the auth managers that produced a spurious warning message if you provide a cache handler and you set a value for the "SPOTIPY_CLIENT_USERNAME" environment variable. (#674) 2021-04-19 20:17:54 +01:00
Peter Schorn
07915e21e5
Added MemoryCacheHandler (#670)
* Added `MemoryCacheHandler`, a cache handler that simply stores the token info in memory as an instance attribute of this class.

* Fixed a bug in `CacheFileHandler.__init__`: The documentation says that the username will be retrieved from the environment, but it wasn't.
2021-04-14 16:59:37 +01:00
Peter Schorn
25f9df2dd5
Added new endpoints (#666)
* Added an exception clause that catches `FileNotFoundError` and logs a debug message in `SpotifyOAuth.get_cached_token`, `SpotifyPKCE.get_cached_token` and `SpotifyImplicitGrant.get_cached_token`.

* Changed docs for `auth` parameter of `Spotify.init` to `access token` instead of `authorization token`. In issue #599, a user confused the access token with the authorization code.

* Updated CHANGELOG.md

* Removed `FileNotFoundError` because it does not exist in python 2.7 (*sigh*) and replaced it with a call to `os.path.exists`.

* Replaced ` os.path.exists` with `error.errno == errno.ENOENT` to supress errors when the cache file does not exist.

* Changed docs for `search` to mention that you can provide multiple multiple types to search for. The query parameters of requests are now logged. Added log messages for when the access token and refresh tokens are retrieved and when they are refreshed. Other small grammar fixes.

* Removed duplicate word "multiple" from CHANGELOG

* * Fixed the bugs in `SpotifyOAuth.refresh_access_token` and `SpotifyPKCE.refresh_access_token` which raised the incorrect exception upon receiving an error response from the server. This addresses #645.
* Fixed a bug in `RequestHandler.do_GET` in which the non-existent `state` attribute of  `SpotifyOauthError` is accessed. This bug occurs when the user clicks "cancel" in the permissions dialog that opens in the browser.
* Cleaned up the documentation for `SpotifyClientCredentials.__init__`, `SpotifyOAuth.__init__`, and `SpotifyPKCE.__init__`.

* Removed unneeded import

* Added the following endpoints:
 `Spotify.current_user_saved_episodes` `Spotify.current_user_saved_episodes_add` `Spotify.current_user_saved_episodes_delete` `Spotify.current_user_saved_episodes_contains` `Spotify.available_markets`
 Added tests for the above endpoints.

* updated CHANGELOG

* Fixed flake8 issue

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2021-04-10 14:53:03 +01:00
Peter Schorn
dc89a00113
Added cache handler to SpotifyClientCredentials and fixed a bug in refresh tokens methods that raised the wrong exception (#655)
* Added an exception clause that catches `FileNotFoundError` and logs a debug message in `SpotifyOAuth.get_cached_token`, `SpotifyPKCE.get_cached_token` and `SpotifyImplicitGrant.get_cached_token`.

* Changed docs for `auth` parameter of `Spotify.init` to `access token` instead of `authorization token`. In issue #599, a user confused the access token with the authorization code.

* Updated CHANGELOG.md

* Removed `FileNotFoundError` because it does not exist in python 2.7 (*sigh*) and replaced it with a call to `os.path.exists`.

* Replaced ` os.path.exists` with `error.errno == errno.ENOENT` to supress errors when the cache file does not exist.

* Changed docs for `search` to mention that you can provide multiple multiple types to search for. The query parameters of requests are now logged. Added log messages for when the access token and refresh tokens are retrieved and when they are refreshed. Other small grammar fixes.

* Removed duplicate word "multiple" from CHANGELOG

* * Fixed the bugs in `SpotifyOAuth.refresh_access_token` and `SpotifyPKCE.refresh_access_token` which raised the incorrect exception upon receiving an error response from the server. This addresses #645.
* Fixed a bug in `RequestHandler.do_GET` in which the non-existent `state` attribute of  `SpotifyOauthError` is accessed. This bug occurs when the user clicks "cancel" in the permissions dialog that opens in the browser.
* Cleaned up the documentation for `SpotifyClientCredentials.__init__`, `SpotifyOAuth.__init__`, and `SpotifyPKCE.__init__`.

* Removed unneeded import

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2021-03-13 14:34:52 +01:00
Omer Korner
e07dd64925
Allow the scope to be either a list or comma separated string (#650)
* Allow the scope to be either a list or comma separated string

* Move normalize scope to util file and make it a base method

Also adjust documentation to reflect the new scope parameter supporting a list

* Add change to CHANGELOG.md
2021-03-04 18:56:39 +01:00
Rob Sanek
d001326cc3
Allow both id types in playlist_change_details (#649) 2021-03-02 19:41:14 +01:00
Rene Nulsch
4e1e74bddc
Replace Urllib3 method_whitelist with allowed_methods (#638)
* Replace method_whitelist with allowed_methods

* Add ChangeLog Entry

* update requests to 2.25 and six to 1.15
2021-02-27 16:43:56 +01:00
kiselz
2cb2cc2c09
Update urls to a search query in client.py (#646)
https://developer.spotify.com/documentation/web-api/reference/search/search - This url does not seem to be valid.
I guess https://developer.spotify.com/documentation/web-api/reference/search/ is right link.
2021-02-26 16:03:11 +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
Tim Gates
44970c3348
docs: fix simple typo, retrival -> retrieval (#629)
There is a small typo in spotipy/oauth2.py.

Should read `retrieval` rather than `retrival`.
2020-12-26 08:47:11 +01:00
Peter DeVita
3ae3d8cab1
Fix Spotify.user_playlist_reorder_items parameter order (#628)
* Fix Spotify.user_playlist_reorder_items

* Update CHANGELOG.md
2020-12-26 08:46:58 +01:00
Tony Jackson
9550c8fd86
Create CacheHandler to abstract caching tokens (#625)
* 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
2020-12-21 11:31:21 +01:00
Peter Schorn
94e164385e
Added more logging and fixed docs for search endpoint (#609)
* Added an exception clause that catches `FileNotFoundError` and logs a debug message in `SpotifyOAuth.get_cached_token`, `SpotifyPKCE.get_cached_token` and `SpotifyImplicitGrant.get_cached_token`.

* Changed docs for `auth` parameter of `Spotify.init` to `access token` instead of `authorization token`. In issue #599, a user confused the access token with the authorization code.

* Updated CHANGELOG.md

* Removed `FileNotFoundError` because it does not exist in python 2.7 (*sigh*) and replaced it with a call to `os.path.exists`.

* Replaced ` os.path.exists` with `error.errno == errno.ENOENT` to supress errors when the cache file does not exist.

* Changed docs for `search` to mention that you can provide multiple multiple types to search for. The query parameters of requests are now logged. Added log messages for when the access token and refresh tokens are retrieved and when they are refreshed. Other small grammar fixes.

* Removed duplicate word "multiple" from CHANGELOG

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2020-11-15 22:22:41 +00:00
Rob Sanek
7531d141c0
Add market argument to track info (#610) 2020-11-15 22:20:11 +00:00