Use this program to get audio for Spotify songs, albums, playlists, and artists. It finds each song on YouTube Music, prefers the label's official audio and the same clean or explicit edit, and tags the file with Spotify and Deezer metadata and lyrics.
A YouTube Music track with the song's ISRC is taken when it has the song's title and length (within 3 s), whatever its artists and album: YouTube Music credits 2Pac's live album to "Tupac" and files Tyler Ward's "The Scientist" under a "tribute" album. The ISRC is Deezer's (Spotify's web player gives none), so url and save --preload look it up as a download does, and save --preload keeps it in the save file. Other results need the song's artists, but YouTube Music may leave out the first one that Spotify lists (a BBC presenter, a band member): a result as long as the song (within 3 s) is accepted when its first artist is another of the song's artists, or when it has the song's title on the song's album. A title with a note ("Lower 5E - Live At The BBC For ...") must match without the note, so a shared note does not make another song match. Numbered titles must have the same numbers: a result for "Side 2, Pt. 2: Skins" must not number another side, part, take, volume or "No." ("Side 4, Pt. 3: Surfacing"), and it may leave out a prefix of only such markers ("Skins").
The program needs yt-dlp and FFmpeg in PATH (or set --yt-dlp and --ffmpeg). For reliable YouTube downloads, also have Deno, Node.js, or Bun in PATH.
spotdl <Spotify URL>
spotdl save <Spotify URL> --save-file songs.spotdl
spotdl sync songs.spotdl
spotdl url "Daft Punk - Get Lucky"
spotdl meta ~/MusicUse download, save, sync, url, or meta before a query to select an action. A query is a Spotify URL or URI, a .spotdl file, a YouTube, YouTube Music or SoundCloud URL, or search text (album:, playlist: and artist: pick the result type). Use youtube-url|spotify-url to pin the video for a song; a pinned video wins over the search, also when the song appears in another query. An artist link gets every release on the artist page. Albums and EPs are downloaded whole, also songs that another album or EP has; singles and compilations add only songs that no album or EP has. Titles are compared without punctuation, so a compilation's "Nowhere Man - First Version - Take 2" is the album's "Nowhere Man (First Version - Take 2)"; another take is another song. A bigger edition of an album (deluxe, super deluxe) that has at least 90% of a smaller edition's songs replaces the smaller edition and is downloaded whole; an explicit edition replaces a clean edition that shares most of its songs (Spotify titles the clean songs "Song - Album Version (Edited)" and censors some titles), and a clean edition never replaces an explicit one. Remix editions are editions too: "Animals (2018 Remix)" with its "Dogs - 2018 Remix" has Animals' songs, and of two editions with the same songs the one titled only with the album's title is downloaded. An edition's title is the album's title or starts with it ("OK Computer OKNOTOK 1997 2017").
In --output, {disc-track-number} is the track number (07), with the disc in front on albums that have more than one disc (2-07). Only the parts of --output that have a {field} are made path-safe (and changed by --restrict); folders written without a field, such as ../Music or My Music: 50% Off, are used as written. A filled part that starts with one . (.5: The Gray Chapter) gets a _ in front, so its folder or file is not hidden and music servers such as Navidrome scan it; ...And Justice for All stays as it is.
Songs are saved as Opus by default (--format also takes m4a, mp3, flac, ogg and wav); YouTube's audio is copied without converting when it is in that format. --bitrate sets how converted songs are encoded, as in Python spotDL: disable (the default) uses the encoder's default, auto the source's bitrate (128k when yt-dlp does not know it; none for FLAC and WAV), digits a VBR quality (--bitrate 0 is LAME's V0 for MP3; Opus has none), and anything else a bitrate (256k). A value other than disable and auto converts every song, also one already in the format.
Use --config file.json to load a config file. Use --generate-config to write the default file to ~/.spotdl/config.json. Use --key=value when a value starts with --, for example --yt-dlp-args="--js-runtimes node".
Use --max-retries 3 to set the number of retries after a failed request. A retry waits as long as the server's Retry-After asks (at most 60 s), else 2, 4, 8, 16, then 32 s; when Spotify's API answers 429, all threads wait together. What is read of the replies from Spotify, Deezer and YouTube Music (songs, albums, search hits) is cached in ~/.spotdl/cache for 7 days; each run deletes the older ones. Use --use-cache-file to keep track data between runs (in ~/.spotdl/cache/keep, which is not cleaned). Use --no-cache to turn off local caches.
Use --meta-threads N to set the number of metadata workers; save uses them for searches and lyrics. Lyrics are fetched while the audio downloads.
On albums with more than one disc, a song's track total (TRACKTOTAL, ID3's TRCK "n/total") is the number of tracks on its disc, as its track number is: disc 2 of good kid, m.A.A.d city (Deluxe) is "1 of 5", not "1 of 17". DISCTOTAL is the number of discs. Files tagged before this have the album's total until spotdl meta --force-update-metadata writes their tags again.
Songs are tagged with Spotify's explicit flag as ITUNESADVISORY (rtng in M4A files), which music servers such as Navidrome read. COMPILATION=1 marks only Spotify compilations by Various Artists: an artist's own anthologies and best-ofs, which Spotify also calls compilations, are not flagged (players file flagged albums under Various Artists), and their RELEASETYPE is still compilation. RELEASETYPE (Spotify's album, single or compilation) is written as the MusicBrainz Album Type atom in M4A files, which keep only atom names; TagLib, and so Navidrome, reads it as RELEASETYPE. A song's ReplayGain track gain comes from Deezer's loudness value when Deezer has the song, taken against -18.4 LUFS as deemix does: Deezer's value reads about 0.4 dB below the loudness FFmpeg measures. --replaygain measures it instead: FFmpeg's EBU R128 loudness gives each song a ReplayGain 2.0 track gain and peak (at -18 LUFS), and each album folder an album gain and peak from its songs' loudness, averaged as energy over their lengths. Spotify dates some albums by year or month only: their songs are dated 1994 or 1994-03, not 1 January, or with Deezer's day when Deezer's copy of the album is from that year or month. ORIGINALDATE is the earlier of Spotify's and Deezer's dates (Deezer's album can be a reissue); Deezer's 1900-01-01 placeholder for an album it has no date for is not a date. Deezer's copy of the album is the one with the same title, then the same record type (single, EP or album), track count and explicit flag, looked for in the artist's discography too when no search hit fits in all of these (Deezer's search finds only GNX's clean edition). When fewer than half of its positions hold a song as long (within 3 s) as the Spotify album's, it is another release (a single's album, a remix single's original, another recording): only its genres are used, not its barcode, label, date or ISRCs. A song's ISRC is that of Deezer's track at the same disc and position when it is as long (within 3 s) and has the same explicit flag. When Deezer numbers the album otherwise (M83's two-disc "Hurry Up, We're Dreaming" is one disc there, a deluxe edition puts its bonus songs in between), it is that of the one track with the song's full title, version note included, the same length and the same explicit flag; an instrumental or remix as long as the song is not taken for it, and with two such tracks the song gets none. The LABEL tag is Spotify's label of the downloaded release; Deezer's label is used only when Spotify has none. When Deezer fails (a timeout, a server error, a "service busy" reply after retries), the song is tagged with Spotify's metadata alone and a WARNING says so; nothing is cached, so a later song of the album and a later run ask again, and spotdl meta keeps the genres, ISRC, barcode, BPM and Deezer's day of the date that the file already has. Files tagged before this have 1 January dates until spotdl meta --force-update-metadata writes their tags again.
--folder-art writes cover.jpg (the album cover) next to the songs and artist.jpg (the album artist's Spotify picture) in the folder above, when that folder is named after the album artist, as with {album-artist}/{album} ({year})/... output paths. Music servers show these images for albums and artists. Album covers, the embedded one and cover.jpg, are taken in the size they were uploaded to Spotify (often 1500 or 2000 px) rather than the 640 px size that Spotify lists, when Spotify has that size; meta does not replace an existing cover.jpg. An album that has no cover on Spotify gets no cover.jpg.
spotdl meta FILES... fills in what files are missing: tags (and the explicit flag of Spotify songs tagged before it was written into Opus files), lyrics, .lrc files with --generate-lrc, measured ReplayGain with --replaygain, and folder images with --folder-art. Tags written again keep the file's other data: its lyrics, the URL its audio came from, the keys spotdl does not write (MusicBrainz IDs, composers, sort names, album gains), the values Spotify does not have, and a measured ReplayGain track gain and peak unless --replaygain measures them again. A song that is missing only lyrics gets only its lyrics written. An instrumental has no lyrics: when the song's own Genius page (with its title, dated to the release's year or listed on its album) has no words, only "[Instrumental]" or "This song is an instrumental", or when every LRCLIB version as long as the song is marked instrumental and Genius has no words for it, the lyrics providers after it (azlyrics and musixmatch, which go by the title alone and gave "Interstellar Overdrive" the words of "See-Saw") are not asked. When Genius (the genius or synced provider) answers that it has no lyrics for a song (an instrumental), the song is tagged SPOTDL_NOLYRICS=1 (----:spotdl:NOLYRICS in M4A) and later meta runs do not look for its lyrics again; --force-update-metadata or --overwrite metadata looks again. A failed Genius request does not count as an answer.
Use --generate-lrc to write a synced .lrc file next to each song. Synced lyrics come from LRCLIB, a crowd's uploads: same titles and lengths do not make the same song, and LRCLIB has, for example, the words of "KING" from VULTURES 1 under BULLY's "KING". So synced lyrics are used only when they were timed to a recording as long as the file and their words are the song's Genius lyrics. LRCLIB also files lyrics timed to a longer version (the album cut, another concert) under a shorter edit's length, so synced lyrics with a line long after the end of the song (more than 15 seconds after; lyrics a little off are kept) are not used as synced: LRCLIB's give the song their words as plain lyrics, synced lyrics in the tags lose their times, and with --overwrite metadata or force such an old .lrc file is removed. Words must also be the song's Genius lyrics (at least 30% of the word pairs are the same; LRCLIB and Genius share about 80% for one song and at most 8% for two). Genius has a page for each song, with its artists and release date: of two songs of an artist with one title, the one of the release's year is taken. A page is the artist's only when the artist's whole name is among the page's artists ("¥$" is in "¥$, Kanye West & Ty Dolla $ign" but not in "Genius Ukrainian Translations"), and pages of Genius's own accounts (translations and romanizations of other artists' songs) are never used. Without synced lyrics that agree, the song has its Genius lyrics in the tags and no .lrc file. A song that Genius has no lyrics for can get LRCLIB's synced lyrics, timed to a recording as long as the song, but not its plain lyrics, which anyone can file under any title (all LRCLIB versions of Lee Fields's "Funky Screw" have a Japanese comic song's words). --overwrite metadata or force checks the lyrics of files again: lyrics in the tags and .lrc files that are another song's are replaced or removed. Only a Genius page with the song's own title, dated to the release's year or listed on the release's album, can replace or remove lyrics, and only lyrics of 20 word pairs or more are compared; when that page has no words (an instrumental), lyrics of 20 word pairs or more and the .lrc file are removed and the song is tagged as having none. A song whose title has a note after " - " that Genius has no page for ("Robbery - Live from the Sydney Opera House") takes the page of the title before it. An instrumental, a song whose title notes say Instrumental, Karaoke or Backing Track ("Big Poppa - Instrumental; 2014 Remaster", "Girl (Take 2 - Instrumental Backing Track)"), takes lyrics only from a Genius page of an instrumental version (the studio talk on a Beatles take), never the sung song's words; without such a page, or when that page has no words, it has no lyrics, and its old lyrics and .lrc file are removed with --overwrite metadata. The "You might also like" that earlier scrapes of Genius pages glued into lyrics is removed. With genius_token set (spotDL's config has one), Genius's API is asked first and its website's search when the API cannot answer (a token out of requests is not asked again in that run); when Genius says too many requests, all threads wait 15, 30, 60 and then 120 seconds, a warning says so each time, and then the request gives up (a banned run fails each song within four minutes instead of waiting silently). So do they when LRCLIB says too many requests; when it is busy (503) they wait a few seconds; a song whose LRCLIB requests still fail gets a warning. When Genius cannot be asked (its website answers 403, a block that is not asked again in that run), LRCLIB's lyrics cannot be checked: they are not used, no .lrc file is written or removed, and the run ends with the number of such songs. Their lyrics stay empty, so a later meta run adds them. azlyrics and musixmatch are asked at most once every 1.5 seconds by all threads together. When azlyrics answers with its "request for access" page (a bot check), a warning says so and azlyrics is not asked again in that run.
Python spotDL's synced provider asks Musixmatch first; Musixmatch now gives programs without an account made-up lyrics, so spotdl-rs does not use its API. Its synced provider takes LRCLIB's synced lyrics that agree with Genius before plain ones, even when a plain version is filed under the song's album.
meta works on --threads files at a time. With meta, a song without a Spotify URL takes the tags of a Spotify song only when that song has the same title, artist, and length, and, when the file has them, the same album title and track number: the track search finds a song on its most popular release (often a compilation), so the file's album is searched too. Otherwise the song keeps its tags, and only its lyrics change.
Use --scan-for-songs to find songs in the output folder. Use --fetch-albums to add all songs from each album. Use --ytm-data to use the title and artist from a YouTube Music page.
Use --playlist-numbering to use the playlist name as the album name and the playlist owner as the album artist. Use --playlist-retain-track-cover to keep each track's album cover. Either way, Deezer's genres, UPC and ISRC still come from each track's own album. Use --m3u to write one playlist file per list; it includes every song of the list, also those that another query already downloaded.
A song gets its file name only after its tags, cover and ReplayGain are written, so a file at the output path is a finished song: a run that is stopped or fails while tagging leaves a <name>.<id>.converted.<format> file (<id> is the Spotify or YouTube id, or a 16-digit hash of the URL for a song without one or with a longer one, so the name fits the 255-byte limit), which is not taken for a song and is deleted when the song is downloaded again.
Use --print-errors to print all errors at the end. Use --save-errors errors.txt to save them, with the Spotify URL of each song. Set --log-level and --log-format to change log output.
You can use --redownload with meta to save the local songs again in the selected format: each song replaces its own file (same name, with the format's extension), and the old file goes once the new one is saved. With --fetch-albums, the songs of the files' albums that have no file are saved at the --output path. Each song is downloaded once, after all files are done, also when several files share an album. sync moves the files of songs whose output path changed and deletes the files of songs that are no longer listed; a file that a listed song writes is kept, also when the song's Spotify URL changed (a re-released album gives its songs new IDs). A moved song keeps its lyrics and .lrc file, and its tags are written again for its new title, album or year; a folder left with nothing but cover.jpg or artist.jpg is removed. Use --sync-remove-lrc to also remove the lyric files of songs that are no longer listed. Use --add-unavailable to add songs without a download to the archive and playlists.
The Spotify URL is stored in the WOAS tag (----:spotdl:WOAS in M4A), as Python spotDL does, so either program can scan the other's files.
Run cargo test for the unit, fuzz and end-to-end tests; the end-to-end tests use the live services. The fuzz tests (src/fuzz) feed hostile text, replies of any shape and damaged audio files to the parsers and check that nothing panics; FUZZ_ITERS=2000000 cargo test --release fuzz runs them for minutes, and a failure names the FUZZ_SEED that reproduces it. Set SPOTDL_E2E_DOWNLOAD=1 to also test downloads, and SPOTDL_E2E_YT_DLP to select yt-dlp.
The code is one module per job: main (command line, playlists, .m3u8), settings (the typed Settings and their parsing), http (requests, retries, and Service, a website that is asked politely), spotify, deezer and search (what the song is and where its audio is), download (fetching and tagging), meta (the meta command), tags, replaygain and files (what is written to files), and lyrics, genius, lrclib and html (which words are a song's own). Each module has its tests, and src/fuzz the fuzz tests of the modules that parse.