rekordbox_set_list_manager.services.spotify_service#

Spotify integration service — authentication and playlist import.

Exceptions#

SpotifyServiceError

Raised when a Spotify API operation fails.

Classes#

SpotifyService

Wraps spotipy for playlist import.

Module Contents#

exception rekordbox_set_list_manager.services.spotify_service.SpotifyServiceError[source]#

Bases: Exception

Raised when a Spotify API operation fails.

class rekordbox_set_list_manager.services.spotify_service.SpotifyService[source]#

Bases: rekordbox_set_list_manager.services.streaming_base.StreamingService

Wraps spotipy for playlist import.

Call authenticate() once before any other method. The instance keeps the authenticated client alive for the session.

SCOPES = 'playlist-read-private playlist-read-collaborative playlist-modify-public playlist-modify-private'[source]#
REDIRECT_URI = 'http://127.0.0.1:8888/callback'[source]#
authenticate(link_callback=None)[source]#

Open browser for PKCE auth (skipped if cached token is valid).

link_callback is accepted for interface compatibility but ignored — Spotify uses a browser redirect flow, not a device-code link.

Parameters:

link_callback (Callable[[str], None] | None) – Accepted for interface compatibility but ignored by Spotify’s browser-redirect flow. Defaults to None.

Returns:

The authenticated user’s display name.

Return type:

str

Raises:

SpotifyServiceError – If spotify_client_id is not configured or authentication fails.

is_authenticated()[source]#

Return True if a Spotify session is active.

Returns:

True when an authenticated spotipy.Spotify client exists.

Return type:

bool

get_playlists()[source]#

Return metadata for all of the authenticated user’s playlists.

Returns:

Each entry contains "id" (str) and "name" (str) keys.

Return type:

list[dict]

Raises:

SpotifyServiceError – If not authenticated or the API call fails.

get_playlist_tracks(playlist_id)[source]#

Fetch all tracks from playlist_id and return as Track objects.

Parameters:

playlist_id (str) – The Spotify playlist ID to fetch tracks from.

Returns:

(tracks, skipped) where skipped is the count of items that could not be imported (local files without a Spotify ID, null entries, etc.). Each track has source=SPOTIFY, spotify_id, isrc (if available), and match_status=UNMATCHED.

Return type:

tuple[list[Track], int]

Raises:

SpotifyServiceError – If not authenticated or the API call fails.

replace_playlist_tracks(playlist_id, spotify_uris)[source]#

Replace all tracks in playlist_id with spotify_uris in order.

Parameters:
  • playlist_id (str) – The Spotify playlist ID to update.

  • spotify_uris (list[str]) – Ordered list of Spotify track URIs to set as the playlist contents.

Returns:

The snapshot_id returned by the Spotify API.

Return type:

str

Raises:

SpotifyServiceError – If not authenticated or the API call fails.

try_silent_authenticate()[source]#

Authenticate using a cached token without opening the browser.

Returns:

The display name on success, or None if no valid cached token exists or authentication fails.

Return type:

str | None