rekordbox_set_list_manager.services.spotify_service#
Spotify integration service — authentication and playlist import.
Exceptions#
Raised when a Spotify API operation fails. |
Classes#
Wraps spotipy for playlist import. |
Module Contents#
- exception rekordbox_set_list_manager.services.spotify_service.SpotifyServiceError[source]#
Bases:
ExceptionRaised when a Spotify API operation fails.
- class rekordbox_set_list_manager.services.spotify_service.SpotifyService[source]#
Bases:
rekordbox_set_list_manager.services.streaming_base.StreamingServiceWraps 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]#
- 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_idis not configured or authentication fails.
- is_authenticated()[source]#
Return
Trueif a Spotify session is active.- Returns:
Truewhen an authenticatedspotipy.Spotifyclient 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
Trackobjects.- 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 hassource=SPOTIFY,spotify_id,isrc(if available), andmatch_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_idreturned by the Spotify API.- Return type:
str
- Raises:
SpotifyServiceError – If not authenticated or the API call fails.