Skip to content

feat: Spotify playlist import — match tracks to local library or auto-download #44

@gitcoder89431

Description

@gitcoder89431

Feature

Import a Spotify playlist into tuitube by matching tracks against the local library (by artist + title) and optionally auto-downloading unmatched tracks via yt-dlp YouTube search.

Why

The single biggest onramp friction for new tuitube users is: "I already have years of curated playlists on Spotify — why would I rebuild them from scratch?" Spotify import closes that gap. Competing terminal players like Aurras already offer this. It turns tuitube from a YouTube-native tool into a serious personal music system.

UX

# Import by Spotify playlist URL (uses Spotify public API, no auth for public playlists)
tuitube import spotify https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M

# Or by playlist ID
tuitube import spotify 37i9dQZF1DXcBWIGoYBM5M --playlist-name "Lofi Focus"

Output:

Fetching playlist: Lofi Hip-Hop Beats (52 tracks)
Matched in library:  31 tracks
Searching YouTube:   21 tracks
Downloaded:          18 tracks
Failed:               3 tracks (printed with reason)
Created playlist: "Lofi Focus" with 49 tracks

Implementation sketch

Step 1: Fetch Spotify playlist

Spotify's /playlists/{id}/tracks endpoint is public for public playlists with a client-credentials token (no user login). Store client_id/client_secret in config (see #38) or accept --client-id/--client-secret flags.

Step 2: Match against library

// Fuzzy match: normalize artist + title, compare against db.ListTracks()
func matchTrack(spotifyArtist, spotifyTitle string, library []db.Track) *db.Track

Use strings.ToLower + strip punctuation. Levenshtein distance for near-matches.

Step 3: Search + download unmatched

For unmatched tracks, construct a yt-dlp search query:

ytSearch = fmt.Sprintf("ytsearch1:%s %s", artist, title)

Reuse the existing downloadCmd infrastructure from internal/app/update.go.

Step 4: Create playlist

Reuse db.CreatePlaylist + db.AddToPlaylistBatch (from #36).

Files likely affected

  • New cmd/import.go subcommand
  • New internal/spotify/spotify.go for API client
  • internal/db/ — expose fuzzy track matching helper
  • internal/app/update.go — reuse download infrastructure

Notes

  • Only public playlists work without user OAuth — document this clearly
  • The MCP search_tracks + create_playlist + add_to_playlist tools could expose this as an agent workflow too once implemented

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions