Skip to content

update API endpoints for Feb 2026 Dev Mode changes and more#9

Open
soyware wants to merge 2 commits into
debfx:masterfrom
soyware:update-spotify-api-feb-2026-and-add-podcasts-albums-and-artists
Open

update API endpoints for Feb 2026 Dev Mode changes and more#9
soyware wants to merge 2 commits into
debfx:masterfrom
soyware:update-spotify-api-feb-2026-and-add-podcasts-albums-and-artists

Conversation

@soyware
Copy link
Copy Markdown

@soyware soyware commented Jun 5, 2026

Overview

This Pull Request updates spotify-playlists.py to adapt to the Spotify Developer Access and Platform Security changes announced in February 2026. Legacy/deprecated routes that have been removed are replaced with their modern counterparts, response field parsing is aligned with renamed structures, and robustness is improved to prevent crashes during batch operations.

In addition, this PR expands the utility of the script by adding full export and import support for Saved Albums, Followed Artists, and Podcasts (Shows & Saved Episodes).

The code was enhanced using Google® Gemini® service, quickly glanced over and tested with followed podcasts, saved podcast episodes, own playlist and liked tracks.


Detailed Changes

1. Compatibility with February 2026 Web API Changes

  • Deprecated Endpoints & Methods:
    • Replaced sp.user_playlist_create with the recommended sp.current_user_playlist_create (uses POST /me/playlists under the hood, as POST /users/{user_id}/playlists was completely removed).
    • Removed the redundant/deprecated sp.user_playlist_change_details in favor of setting collaborative directly during playlist creation.
    • Replaced sp.user_playlist_add_tracks with sp.playlist_add_items (uses the updated POST /playlists/{id}/items route instead of the removed /tracks endpoint).
  • Playlist Field Renaming:
    • Refactored process_tracks to parse both "item" (new Web API rules) and "track" (legacy/saved tracks fallback) keys: track = item.get("item") or item.get("track").
    • Updated the query filter inside sp.playlist_items from items(track(...)) to items(item(...)) to match the renamed playlist response fields.
  • Access Safeguards:
    • Under updated Dev Mode rules, playlist tracks can only be fetched for playlists that the current user owns or collaborates on. Added verification checks (is_owner or is_collaborative) before calling sp.playlist_items.
    • Wrapped tracks fetching inside a robust try...except spotipy.SpotifyException block. If there's an issue fetching a specific playlist, the script logs a warning and proceeds with the rest of the export rather than crashing.

2. Saved Albums, Followed Artists, and Podcasts Support (Export/Import)

  • New Scopes: Added "user-library-modify", "user-follow-read", and "user-follow-modify" to authorization scopes.
  • Export Expansion:
    • Saved Albums: Fetched via sp.current_user_saved_albums() and written to Saved albums.xspf (type: "saved_albums").
    • Followed Artists: Fetched via cursor-paginated sp.current_user_followed_artists() and written to Followed artists.xspf (type: "followed_artists").
    • Followed Podcasts (Shows): Fetched via sp.current_user_saved_shows() and written to Followed podcasts.xspf (type: "followed_podcasts").
    • Liked Podcasts (Saved Episodes): Fetched via sp.current_user_saved_episodes() and written to Liked podcasts.xspf (type: "liked_podcasts").
  • Import Expansion:
    • Added parsing of the <type> element from the XML <extension> tag.
    • Added direct routing back into the user's library in batch-sized chunks of 40 (to stay within API limits):
      • "saved_tracks" -> sp.current_user_saved_tracks_add()
      • "saved_albums" -> sp.current_user_saved_albums_add()
      • "followed_artists" -> sp.user_follow_artists()
      • "followed_podcasts" -> sp.current_user_saved_shows_add()
      • "liked_podcasts" -> sp.current_user_saved_episodes_add()

3. Platform Encoding Fixes

  • Added encoding="utf-8" explicitly in write_playlist() to prevent UnicodeEncodeError when dealing with tracks containing UTF-8 characters on Windows platforms.

References

Update on Developer Access and Platform Security
February 2026 Web API Dev Mode Changes - Migration Guide

soyware added 2 commits June 5, 2026 23:06
add Saved Albums, Followed Artists, and Podcast support;
update .gitignore;
retrieve canonical User ID;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant