Add Spotify Web API (OAuth PKCE) support: auth, token caching, resilient client, playlist/liked-songs downloads#4
Merged
Ssenseii merged 7 commits intoSsenseii:mainfrom Dec 18, 2025
Conversation
- remove config.json file - the configuration is now handled by environment variables
- add spotify_client_id, spotify_redirect_uri, spotify_scopes, spotify_cache_tokens, spotify_auto_refresh to config - add spotify web api (oauth pkce) section to config schema - validate list element types in config feat(gitignore): add config.json to gitignore - ignore config files to prevent credential leakage feat(downloads_menu): integrate spotify web api (oauth pkce) - add spotify web api menu with authentication, playlist download, and liked songs download options - add spotify authentication using oauth pkce flow - add playlist download from spotify web api - add liked songs download from spotify web api - add spotify api credential setup help - add spotify token status display - add spotify logout (clear cached token) option docs(readme): update readme with spotify web api instructions - add spotify web api feature description - add spotify web api setup and authentication instructions - add spotify web api authentication instructions - add spotify web api playlist and liked songs download instructions - update project structure with spotify api directory - update prerequisites with spotify web api requirements feat(spotify_api): create spotify web api package - create spotify web api package with auth, client, data loader, and token manager modules - add spotify authentication using oauth pkce flow - add spotify client for making api requests - add spotify data loader for loading playlists and liked songs - add spotify token manager for caching and refreshing tokens test(spotify_api): add basic tests for spotify api - add tests for spotify auth helpers - add tests for spotify token manager - add tests for spotify data loader normalization test(spotify_api): add tests for data loader limits - add tests for spotify data loader limits
- create config.json.example with default settings - include spotify api and sync configurations
- update spotify redirect uri to 127.0.0.1 for local development - create spotify_tokens.json to store access tokens - add httpx dependency for making http requests - update authentication flow with pkce - provide user-friendly instructions for spotify app setup - add token management to handle token refresh and storage - improve error handling and logging for authentication failures - update start script to check missing dependencies and install them if needed
- add minimal local callback server for auto-capture of redirect url - improve ux and instructions for spotify oauth (pkce) flow - update readme and comments to reflect changes - fix docker setup instructions - update musicbrainz user agent - rename trav-dj to harmoni
- add diagnostics for common auth issues (401/403) - improve error message handling to display server-provided details - update spotify_tokens.json with new access and refresh tokens refactor(spotify): remove audio features - remove audio features from spotify downloads - remove audio features option and related code - remove audio features from tests docs(readme): remove audio features - remove audio features from readme
- remove spotify_tokens.json from tracked files (I CHANGED THEM, NO LEAKY LEAKY!!!) - add spotify_tokens.json to .gitignore
Owner
|
I'm encountering a problem when I try to authenticate. You mind explaining how to setup the Spotify API integration so I can add it to the docs? @TheRealAlexV |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a complete Spotify Web API integration (Authorization Code + PKCE) so HARMONI can load tracks directly from a user’s Spotify account (Playlists + Liked Songs) and reuse the existing per-playlist selection + download pipeline.
Key deliverables:
spotify_api/package (PKCE auth, token cache, API client with retries/paging, data normalization)Motivation
File-based workflows (Exportify CSV / Spotify export JSON) remain supported, but direct Web API access is the most reliable and user-friendly source of up-to-date playlist + liked-song data.
What’s Included
1) OAuth PKCE implementation (no client secret)
SpotifyPKCEAuthSpotifyPKCEAuth.generate_pkce_pair()andcode_challenge_from_verifier()extract_code_from_redirect_url()SpotifyPKCEAuth.exchange_code_for_token()andSpotifyPKCEAuth.refresh_access_token()Dependency note:
httpx(import guarded with a clear runtime error when missing) inspotify_api/auth.pyhttpxis included inrequirements.txt2) Token caching + expiry
TokenManagerDEFAULT_TOKEN_CACHE_PATH(data/spotify_tokens.json)TokenManager.is_expired()Config controls:
spotify_cache_tokens: enable/disable disk cache (checked inTokenManager.should_cache())spotify_auto_refresh: enable/disable refresh-token flow (enforced inSpotifyClient.get_token())3) Resilient Spotify Web API client (stdlib networking)
SpotifyClientSpotifyClient.request_json()Retry-AfterSpotifyClient.get_user_playlists()SpotifyClient.get_playlist_tracks()SpotifyClient.get_liked_songs()Tunable retry keys (optional):
spotify_max_retries,spotify_backoff_base,spotify_retry_jitter(read inSpotifyClient.request_json()andSpotifyClient._sleep_with_jitter())4) High-level data loader + normalization compatible with existing workflows
SpotifyDataLoaderSpotifyDataLoader.list_all_playlists()SpotifyDataLoader.load_playlist_tracks()SpotifyDataLoader.load_liked_songs()artist+track):SpotifyDataLoader._normalize_track()5) CLI menu integration (auth + download UI)
downloads_menu()_spotify_api_menu()OAuth UX improvements:
_spotify_authenticate()0.0.0.0inside container when redirect is127.0.0.1):_spotify_authenticate()Download workflow integration:
_spotify_download_from_playlists()_spotify_download_liked_songs()select_songs_for_playlist()download_playlist()6) Configuration + docs
DEFAULT_CONFIGandCONFIG_SCHEMAspotify_client_id,spotify_redirect_uri,spotify_scopes,spotify_cache_tokens,spotify_auto_refreshreadme.mdClient ID behavior:
spotify_client_idis not set, falls back to Exportify’s public client id viaget_effective_spotify_client_id()(with warnings + guidance fromcheck_spotify_credentials())Testing
test_spotify_api_basic.pytest_spotify_data_loader_limits.pySecurity / Privacy notes
spotify_cache_tokensis enabled (seeTokenManager.should_cache()).SpotifyClient.request_json()).User-facing workflow
readme.md_spotify_authenticate()select_songs_for_playlist()