Skip to content

Commit 14ab13d

Browse files
authored
add deprecation warnings and FAQ to respond to Spotify's API changes (#1177)
* add deprecation warnings and FAQ to respond to Spotify's API changes * remove test cases associated with deprecated methods * added missing commas
1 parent db3fb9a commit 14ab13d

File tree

5 files changed

+46
-70
lines changed

5 files changed

+46
-70
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ Add your changes below.
1919
- Added `personalized_playlist.py`, `track_recommendations.py`, and `audio_features_analysis.py` to `/examples`.
2020
- Discord badge in README
2121
- Added `SpotifyBaseException` and moved all exceptions to `exceptions.py`
22+
- Marked the following methods as deprecated:
23+
- artist_related_artists
24+
- recommendations
25+
- audio_features
26+
- audio_analysis
27+
- featured_playlists
28+
- category_playlists
29+
- Added FAQ entry for inaccessible playlists
2230

2331
### Fixed
2432
- Audiobook integration tests

FAQ.md

+6
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,9 @@ sp = spotipy.Spotify(
7474
)
7575
```
7676
The error raised is a `spotipy.exceptions.SpotifyException`
77+
78+
### I get a 404 when trying to access a Spotify-owned playlist
79+
80+
Spotify has begun restricting access to algorithmic and Spotify-owned editorial playlists.
81+
Only applications with an existing extended mode will still have access to these playlists.
82+
Read more about this change here: [Introducing some changes to our Web API](https://developer.spotify.com/blog/2024-11-27-changes-to-the-web-api)

spotipy/client.py

+32
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ def artist_related_artists(self, artist_id):
458458
Parameters:
459459
- artist_id - the artist ID, URI or URL
460460
"""
461+
warnings.warn(
462+
"You're using `artist_related_artists(...)`, "
463+
"which is marked as deprecated by Spotify.",
464+
DeprecationWarning
465+
)
461466
trid = self._get_id("artist", artist_id)
462467
return self._get("artists/" + trid + "/related-artists")
463468

@@ -1587,6 +1592,11 @@ def featured_playlists(
15871592
(the first object). Use with limit to get the next set of
15881593
items.
15891594
"""
1595+
warnings.warn(
1596+
"You're using `featured_playlists(...)`, "
1597+
"which is marked as deprecated by Spotify.",
1598+
DeprecationWarning,
1599+
)
15901600
return self._get(
15911601
"browse/featured-playlists",
15921602
locale=locale,
@@ -1671,6 +1681,11 @@ def category_playlists(
16711681
(the first object). Use with limit to get the next set of
16721682
items.
16731683
"""
1684+
warnings.warn(
1685+
"You're using `category_playlists(...)`, "
1686+
"which is marked as deprecated by Spotify.",
1687+
DeprecationWarning,
1688+
)
16741689
return self._get(
16751690
"browse/categories/" + category_id + "/playlists",
16761691
country=country,
@@ -1708,6 +1723,12 @@ def recommendations(
17081723
attributes listed in the documentation, these values
17091724
provide filters and targeting on results.
17101725
"""
1726+
warnings.warn(
1727+
"You're using `recommendations(...)`, "
1728+
"which is marked as deprecated by Spotify.",
1729+
DeprecationWarning,
1730+
)
1731+
17111732
params = dict(limit=limit)
17121733
if seed_artists:
17131734
params["seed_artists"] = ",".join(
@@ -1754,6 +1775,11 @@ def audio_analysis(self, track_id):
17541775
Parameters:
17551776
- track_id - a track URI, URL or ID
17561777
"""
1778+
warnings.warn(
1779+
"You're using `audio_analysis(...)`, "
1780+
"which is marked as deprecated by Spotify.",
1781+
DeprecationWarning,
1782+
)
17571783
trid = self._get_id("track", track_id)
17581784
return self._get("audio-analysis/" + trid)
17591785

@@ -1762,6 +1788,12 @@ def audio_features(self, tracks=[]):
17621788
Parameters:
17631789
- tracks - a list of track URIs, URLs or IDs, maximum: 100 ids
17641790
"""
1791+
warnings.warn(
1792+
"You're using `audio_features(...)`, "
1793+
"which is marked as deprecated by Spotify.",
1794+
DeprecationWarning,
1795+
)
1796+
17651797
if isinstance(tracks, str):
17661798
trackid = self._get_id("track", tracks)
17671799
results = self._get("audio-features/?ids=" + trackid)

tests/integration/non_user_endpoints/test.py

-39
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,6 @@ def setUpClass(self):
7373
client_credentials_manager=SpotifyClientCredentials())
7474
self.spotify.trace = False
7575

76-
def test_audio_analysis(self):
77-
result = self.spotify.audio_analysis(self.four_tracks[0])
78-
assert ('beats' in result)
79-
80-
def test_audio_features(self):
81-
results = self.spotify.audio_features(self.four_tracks)
82-
self.assertTrue(len(results) == len(self.four_tracks))
83-
for track in results:
84-
assert ('speechiness' in track)
85-
86-
def test_audio_features_with_bad_track(self):
87-
bad_tracks = ['spotify:track:bad']
88-
input = self.four_tracks + bad_tracks
89-
results = self.spotify.audio_features(input)
90-
self.assertTrue(len(results) == len(input))
91-
for track in results[:-1]:
92-
if track is not None:
93-
assert ('speechiness' in track)
94-
self.assertTrue(results[-1] is None)
95-
96-
def test_recommendations(self):
97-
results = self.spotify.recommendations(
98-
seed_tracks=self.four_tracks,
99-
min_danceability=0,
100-
max_loudness=0,
101-
target_popularity=50)
102-
self.assertTrue(len(results['tracks']) == 20)
103-
10476
def test_artist_urn(self):
10577
artist = self.spotify.artist(self.radiohead_urn)
10678
self.assertTrue(artist['name'] == 'Radiohead')
@@ -179,17 +151,6 @@ def test_artist_top_tracks(self):
179151
self.assertTrue('tracks' in results)
180152
self.assertTrue(len(results['tracks']) == 10)
181153

182-
def test_artist_related_artists(self):
183-
results = self.spotify.artist_related_artists(self.weezer_urn)
184-
self.assertTrue('artists' in results)
185-
self.assertTrue(len(results['artists']) == 20)
186-
187-
found = False
188-
for artist in results['artists']:
189-
if artist['name'] == 'Jimmy Eat World':
190-
found = True
191-
self.assertTrue(found)
192-
193154
def test_artist_search(self):
194155
results = self.spotify.search(q='weezer', type='artist')
195156
self.assertTrue('artists' in results)

tests/integration/user_endpoints/test.py

-31
Original file line numberDiff line numberDiff line change
@@ -393,33 +393,6 @@ def test_categories_limit_high(self):
393393
response = self.spotify.categories(limit=50)
394394
self.assertLessEqual(len(response['categories']['items']), 50)
395395

396-
def test_category_playlists(self):
397-
response = self.spotify.categories()
398-
category = 'rock'
399-
for cat in response['categories']['items']:
400-
cat_id = cat['id']
401-
if cat_id == category:
402-
response = self.spotify.category_playlists(category_id=cat_id)
403-
self.assertGreater(len(response['playlists']["items"]), 0)
404-
405-
def test_category_playlists_limit_low(self):
406-
response = self.spotify.categories()
407-
category = 'rock'
408-
for cat in response['categories']['items']:
409-
cat_id = cat['id']
410-
if cat_id == category:
411-
response = self.spotify.category_playlists(category_id=cat_id, limit=1)
412-
self.assertEqual(len(response['categories']['items']), 1)
413-
414-
def test_category_playlists_limit_high(self):
415-
response = self.spotify.categories()
416-
category = 'rock'
417-
for cat in response['categories']['items']:
418-
cat_id = cat['id']
419-
if cat_id == category:
420-
response = self.spotify.category_playlists(category_id=cat_id, limit=50)
421-
self.assertLessEqual(len(response['categories']['items']), 50)
422-
423396
def test_new_releases(self):
424397
response = self.spotify.new_releases()
425398
self.assertGreater(len(response['albums']['items']), 0)
@@ -432,10 +405,6 @@ def test_new_releases_limit_high(self):
432405
response = self.spotify.new_releases(limit=50)
433406
self.assertLessEqual(len(response['albums']['items']), 50)
434407

435-
def test_featured_releases(self):
436-
response = self.spotify.featured_playlists()
437-
self.assertGreater(len(response['playlists']), 0)
438-
439408

440409
class SpotipyFollowApiTests(unittest.TestCase):
441410
@classmethod

0 commit comments

Comments
 (0)