Skip to content

About

A Python command-line interface (CLI) tool for fetching, listing, and exporting Spotify playlists, Liked Songs, and Daily Mixes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Spotify Playlist Exporter

A versatile Python command-line interface (CLI) tool for fetching, listing, and exporting Spotify playlists, Liked Songs, and Daily Mixes. Designed for seamless integration with downstream tools, it supports multiple output formats including plain text lists, raw JSON metadata, and native spotDL-compatible JSON schemas.

Developed by Gonçalo Miranda (@dnigamer on GitHub) - 2026.

Features

  • Secure PKCE Authentication: Authenticates with Spotify via OAuth 2.0 Proof Key for Code Exchange (PKCE).
  • Specialized Daily Mix Support: Includes built-in fallback authentication using the Exportify Client ID, enabling users to export algorithmically generated Daily Mix playlists by providing an Exportify refresh token.
  • Multiple Output Formats:
    • json: Complete API metadata for archival and developers.
    • txt: Clean, human-readable track lists (Artist(s) - Track Name).
    • spotdl: Native structured JSON tailored for spotDL, including release dates, album covers, and ISRC codes.
  • Flexible Inputs: Target playlists using raw IDs, standard HTTP URLs, or Spotify URIs (spotify:playlist:...). Support for batch processing via comma-separated inputs.
  • Headless & Override Support: Designed to run cleanly in standard desktops, servers, or headless terminal environments with custom token override options.
  • Standalone URL Extractor: Includes an auxiliary script (export_urls.py) to scrape and deduplicate direct Spotify track URLs from local .json or .spotdl metadata files.

Requirements and Installation

Prerequisites

  • Python 3.10+ (Required for modern typing syntax and features)
  • A Spotify account and registered Developer Application (for standard playlist exporting)

Installation

  1. Clone or Download the Repository:

    git clone <repository-url>
    cd export-spotify
  2. Set Up a Virtual Environment (Optional but recommended):

    python -m venv .venv
    # On Windows:
    .venv\Scripts\activate
    # On macOS/Linux:
    source .venv/bin/activate
  3. Install Dependencies:

    pip install -r requirements.txt

Configuration (Standard Playlists & Liked Songs)

Before querying standard public or private playlists from the Spotify API, configure your Spotify Developer Client ID:

  1. Go to the Spotify Developer Dashboard and create a new application.
  2. In your app settings, add the following as a Redirect URI: http://127.0.0.1:8888/callback
  3. Copy the Client ID from your application page (a Client Secret is NOT required due to PKCE authentication).
  4. Rename .env.example to .env in the root directory (or create a new .env file):
# Spotify API Configuration
SPOTIFY_CLIENT_ID=your_spotify_client_id_here
SPOTIFY_REDIRECT_URI=http://127.0.0.1:8888/callback
SPOTIFY_SCOPES=playlist-read-private playlist-read-collaborative user-library-read
SPOTIFY_TOKEN_FILE=spotify_tokens.json

# Optional: Override authentication with direct tokens
SPOTIFY_ACCESS_TOKEN=
SPOTIFY_REFRESH_TOKEN=

Special Setup: Exporting Daily Mixes

Due to Spotify API restrictions on algorithmic playlists, exporting personalized "Daily Mix" playlists requires utilizing an established Client ID authorization flow. This utility includes built-in fallback authentication for Exportify.

To export your Daily Mixes, follow these required steps to obtain an Exportify refresh token:

  1. Open your web browser and navigate to exportify.net.
  2. Click Get Started and authorize the application with your Spotify account.
  3. Once logged in and viewing your playlists on the Exportify website, open your browser's Developer Tools (press F12, or right-click and select Inspect).
  4. Switch to the Network tab in Developer Tools.
  5. Filter by Fetch/XHR or interact with the page (e.g., reloading or initiating a playlist export) to inspect incoming network API requests made by the website.
  6. Locate the request containing token details (such as requests to Spotify API or token endpoints) and copy your refresh_token from the request payload, headers, or response data.
  7. Provide this refresh token directly to the CLI via the --refresh-token (-rt) option, or set it as SPOTIFY_REFRESH_TOKEN in your .env file.

The application automatically recognizes the token and leverages the fallback Exportify Client ID (d99b082b01d74d61a100c9a0e056380b) to authorize and fetch your Daily Mix tracks.

Example Daily Mix Export Command

python main.py --export-daily-mix-tracks --refresh-token "YOUR_EXPORTIFY_REFRESH_TOKEN" --format spotdl --output-dir exports/

Usage: Main Exporter (main.py)

Command-Line Arguments

Argument Short Description
--format -f Export format: json (default), txt, or spotdl.
--output-dir -o Target directory for generated output files.
--headless -hl Run without automatically launching a web browser for auth.
--token -t Manually specify a Spotify access token to bypass login.
--refresh-token -rt Manually provide a Spotify or Exportify refresh token.
--fetch-playlists-only -fpo Query all user playlists and save metadata to playlists.json.
--export-playlist -elp Export tracks for one or more playlists (ID, URL, or URI).
--export-liked-songs -els Export all Liked Songs from your user library.
--export-daily-mix-tracks -edm Export all generated playlists starting with "Daily Mix". Requires Exportify refresh token.
--convert-spotdl -csd Convert .spotdl files to .txt tracklist files.
--list-playlists -lp Print summary details of all playlists to the terminal.
--list-liked-songs -lls Print Liked Songs directly to the terminal.
--list-playlist -lpt Print tracks of specified playlists directly to the terminal.

Common Examples

  1. Export Daily Mix tracks using an Exportify refresh token:

    python main.py --export-daily-mix-tracks -rt "your_refresh_token_here" --format spotdl
  2. Export Liked Songs to spotDL format:

    python main.py --export-liked-songs --format spotdl --output-dir exports/
  3. Export specific playlists (by URL or URI) to text files:

    python main.py --export-playlist "https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M, spotify:playlist:37i9dQZF1DX0XUsuxWHRQd" --format txt
  4. Fetch playlist metadata without downloading tracks:

    python main.py --fetch-playlists-only
  5. Convert existing spotDL JSON files to plain text lists:

    python main.py --convert-spotdl path/to/spotdl_files/ --output-dir converted_txt/
  6. Run in a headless environment:

    python main.py --export-liked-songs --headless

Usage: URL Extractor (export_urls.py)

The standalone export_urls.py script parses local metadata files (.spotdl or .json) to extract and deduplicate Spotify track URLs into .txt files. This is useful for passing clean URL lists to external downloaders.

Examples

  • Scan the current directory for all .json and .spotdl files:

    python export_urls.py
  • Scan a specific directory:

    python export_urls.py --dir ./exports
  • Process specific files directly:

    python export_urls.py my_playlist.spotdl liked_songs.json

Export Formats Overview

  • json The standard raw array of track dictionaries returned by the Spotify API, containing audio features, popularity metrics, markets, and album structures.

  • txt A flat text document featuring one song per line, organized as Artist(s) - Track Name. Suitable for importing into standard text-based media players and music migration tools.

  • spotdl A specialized JSON format tailored specifically for the spotDL application. Includes exact track titles, lead artist info, duration in seconds, release dates, covers, and International Standard Recording Codes (ISRC) for pinpoint audio matching.

Running Tests

Unit tests are located in the tests/ directory. To run the test suite using Python's built-in unittest framework:

python -m unittest discover -s tests

Alternatively, if you have pytest installed:

pytest tests/

License & Attribution

Copyright (c) 2026 Gonçalo Miranda (@dnigamer on GitHub). All rights reserved.

About

A Python command-line interface (CLI) tool for fetching, listing, and exporting Spotify playlists, Liked Songs, and Daily Mixes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages