I decided to leave Spotify and hit an immediate problem: years of carefully curated playlists, liked songs, and listening history, locked behind an API with no built-in export function. Lose all of it, or spend days manually recreating it elsewhere. Neither was acceptable, so I built ByeByeSpotify: a Python command-line tool that exports your entire library to portable JSON and CSV in one run.
I built it in a weekend to solve my own problem. It exported my full library (playlists, liked songs, albums, listening stats) in under 10 minutes. What would have been days of manual recreation became a single command.
Key Features
- Comprehensive Export: Downloads liked songs, playlists, albums, followed artists, top tracks, listening statistics, podcasts, and audiobooks
- Dual Format Output: Generates both JSON (complete metadata) and CSV (spreadsheet-friendly) files for maximum compatibility
- OAuth Security: Uses modern PKCE authentication flow (no client secret needed)
- Organized Output: Creates timestamped exports in structured directories with individual playlist CSV files
- API Management: Handles rate limiting and pagination automatically
- Platform Migration: CSV format designed for easy importing to Apple Music, YouTube Music, or other services
Technical Implementation
Authentication Architecture
Implemented secure OAuth 2.0 PKCE (Proof Key for Code Exchange) flow, eliminating the need for client secret storage:
# PKCE flow configuration
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(
client_id=SPOTIFY_CLIENT_ID,
redirect_uri="http://127.0.0.1:8888",
scope=SCOPES,
open_browser=True
))
This approach is more secure than traditional OAuth flows and better suited for client-side applications.
Data Export Strategy
The tool exports data in two complementary formats:
JSON Format: Complete metadata preservation
- Full track information including artist details, album data, popularity metrics
- Nested structures for complex data like playlists and albums
- Ideal for programmatic processing or custom analysis
CSV Format: Human-readable and migration-friendly
- Flattened structures for spreadsheet compatibility
- Individual CSV files per playlist for targeted imports
- Designed for importing to competing platforms
API Pagination & Rate Limiting
Spotify’s API returns results in batches (typically 50 items). The tool automatically handles pagination to retrieve complete datasets:
# Automatic pagination for large datasets
results = sp.current_user_saved_tracks(limit=50)
while results['next']:
results = sp.next(results)
all_tracks.extend(results['items'])
Rate limiting is managed by the Spotipy library, which implements exponential backoff for 429 (Too Many Requests) responses.
Use Cases
Platform Migration
Export your Spotify library before switching to Apple Music, YouTube Music, Tidal, or self-hosted solutions like Plex or Jellyfin. CSV files map cleanly to most music platform import formats.
Data Ownership
Maintain an independent backup of your music library metadata. Streaming services can remove tracks, change catalogs, or alter recommendations. Your export remains unchanged.
Listening Analytics
Analyze your music preferences over time with JSON exports. Build custom visualizations, track genre trends, or create recommendation algorithms using your historical data.
Playlist Archival
Preserve collaborative playlists before members leave or playlists get deleted. Export creates a permanent record of the playlist state at export time.
Output Structure
spotify_export_YYYY-MM-DD_HHMM/
├── SUMMARY.txt # Human-readable overview
├── liked_songs.json # Full liked songs metadata
├── liked_songs.csv # Spreadsheet-friendly format
├── playlists.json # All playlists with tracks
├── playlists/
│ ├── playlist_name_1.csv
│ ├── playlist_name_2.csv
│ └── ...
├── albums.json
├── albums.csv
├── artists.json
├── artists.csv
├── top_tracks_short_term.json
├── top_tracks_medium_term.json
├── top_tracks_long_term.json
├── podcast_shows.json
└── audiobooks.json
Limitations & Considerations
Recently Played Limitation: Spotify’s API only provides approximately 50 recently played tracks, not full listening history. This is a platform limitation, not a tool limitation.
Redirect URI Requirement: OAuth redirect URI must be exactly http://127.0.0.1:8888. Changing this breaks authentication.
Rate Limits: Large libraries (10,000+ tracks) may take several minutes to export due to API pagination and rate limiting.
Technology Stack
- Python 3.7+: Core language
- Spotipy: Official Spotify Web API wrapper
- OAuth 2.0 PKCE: Secure authentication without client secrets
- CSV & JSON: Universal export formats
Since open-sourcing it, others in the same spot have used it to migrate to Apple Music, YouTube Music, self-hosted servers, or just to keep an independent backup. Streaming platforms build walled gardens. Your music library shouldn’t be held hostage by platform lock-in.
Future Enhancements
Potential improvements include:
- Direct import adapters for major platforms (Apple Music, YouTube Music)
- Incremental export mode (only export new changes since last run)
- Playlist comparison tool (identify changes between exports)
- Conversion to M3U playlist format for local media players
- Integration with music recognition APIs to match tracks across platforms
Discussion
Loading comments...
Leave a comment
Your email is required but will never be displayed publicly.