Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adrianjagielak/36375a844fd020a9909ffac113844a69 to your computer and use it in GitHub Desktop.
Save adrianjagielak/36375a844fd020a9909ffac113844a69 to your computer and use it in GitHub Desktop.
This command downloads high-quality audio files from YouTube/YouTube Music in .m4a format and embeds cropped square album artwork and metadata. Perfect for importing music into Apple Music or other libraries. (Tested with yt-dlp version 2024.11.18, ffmpeg version 7.1_3 on macOS 15.2)
yt-dlp "song or playlist URL" \
-f "bestaudio[ext=m4a]" --extract-audio --audio-format m4a \
--embed-thumbnail --convert-thumbnail jpg --embed-metadata --add-metadata \
--write-info-json --write-thumbnail \
--exec-before-download "ffmpeg -i %(thumbnails.-1.filepath)q -vf crop=\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\" -frames:v 1 -update 1 cropped.jpg" \
--exec-before-download "mv cropped.jpg %(thumbnails.-1.filepath)q" \
--exec "rm \"%(artist)s - %(title)s.jpg\"" \
--exec "rm \"%(artist)s - %(title)s.info.json\"" \
--output "%(artist)s - %(title)s.%(ext)s"
#!/bin/bash
yt-dlp "$1" \
-f "bestaudio[ext=m4a]" --extract-audio --audio-format m4a \
--embed-thumbnail --convert-thumbnail jpg --embed-metadata --add-metadata \
--write-info-json --write-thumbnail \
--exec-before-download "echo \"Downloading: %(artist)s - %(title)s.%(ext)s\"" \
--exec-before-download "ffmpeg -loglevel quiet -i %(thumbnails.-1.filepath)q -vf crop=\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\" -frames:v 1 -update 1 cropped.jpg" \
--exec-before-download "mv cropped.jpg %(thumbnails.-1.filepath)q" \
--exec "rm \"%(artist)s - %(title)s.jpg\"" \
--exec "rm \"%(artist)s - %(title)s.info.json\"" \
--output "%(artist)s - %(title)s.%(ext)s" \
--quiet --progress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment