I want to download all my favorite music to my local machine for completely offline listening. My goal is to have the same music library on both my iPhone (iOS) and MacBook (macOS).
<aside> ☝
This is for personal use only. I don't encourage illegal activities.
</aside>
<aside> ⚠️
Be careful: If you use --cookies-from-browser chrome to bypass the 403 error, you'll need to grant yt-dlp your OS user password. This gives the program access to your Chrome cookies and potentially stored passwords. Use at your own risk and make sure to download the official version from GitHub.
</aside>
yt-dlp --cookies-from-browser chrome \\
-x --audio-format mp3 \\
--embed-metadata --embed-thumbnail \\
--parse-metadata ".*:(?P<album>tinh_tao)" \\
--parse-metadata "uploader:(?P<artist>.*)" \\
--replace-in-metadata "title" " \\[.*?\\]" "" \\
-o "%(title)s.%(ext)s" \\
"PLAYLIST_URL"
Download all songs in .mp3 format from a YouTube playlist using yt-dlp
yt-dlp --cookies-from-browser chrome \\
-x --audio-format mp3 \\
--embed-metadata --embed-thumbnail \\
--parse-metadata ".*:(?P<album>tinh_tao)" \\
--parse-metadata "uploader:(?P<artist>.*)" \\
--replace-in-metadata "title" " \\[.*?\\]" "" -o "%(title)s.%(ext)s" \\
--download-archive downloaded.txt \\
--no-overwrite \\
"PLAYLIST_URL"
This command downloads and converts all songs from a YouTube playlist to .mp3 format. It saves the downloaded video IDs in downloaded.txt to prevent downloading the same song twice (using --no-overwrite). The command also captures all metadata (title, artist, album, cover) and removes [youtube_id] from the title.
The --cookies-from-browser option helps bypass the 403 (Forbidden) error.
Other options are available in the yt-dlp repository. Here are some useful ones:
--playlist-start 4--playlist-end 10If you only want to generate the downloaded.txt file without downloading anything:
yt-dlp --flat-playlist --no-overwrite \\
--get-id "PLAYLIST_URL" | sed 's/^/youtube /' > downloaded.txt
To play a notification sound when your download completes:
yt-dlp .... && afplay /System/Library/Sounds/Glass.aiff
You can create aliases (in zsh or bash) to efficiently download newly added songs from your playlists. For example, I have three playlists—"choices," "mood," and "rock"—with corresponding folders of the same names in ~/Download/musics/