Skip to content

Instantly share code, notes, and snippets.

@avrahamappel
Last active May 26, 2025 06:35
Show Gist options
  • Save avrahamappel/08dca995c61c17d049ffc6fa1c8cc627 to your computer and use it in GitHub Desktop.
Save avrahamappel/08dca995c61c17d049ffc6fa1c8cc627 to your computer and use it in GitHub Desktop.
yt-dlp configuration for downloading music with metadata and cover art
# Download in m4a format
--format="ba"
--extract-audio
--audio-format m4a
# Continue downloading if the download failed previously
--continue
--no-overwrites
# Set track number, album name, and artist name metadata tags
--add-metadata
--parse-metadata "%(playlist_index)s:%(track_number)s"
# Add cover art
--embed-thumbnail
--convert-thumbnails jpg
# Save file to ALBUM/TRACK NAME
-o "%(album)s/%(playlist_index)s %(title)s.%(ext)s"
#!/usr/bin/env nix-shell
#!nix-shell -p bash imagemagick exiftool -i bash
convert_album_art() {
file=$1
echo
echo "Processing file: $file"
# Extract the embedded album art
album_art=$(mktemp)
exiftool -b -CoverArt "$file" > "$album_art"
# Check if album art exists
if [ -n "$album_art" ]; then
echo "Album art found in $file, copied to $album_art"
# Determine the file extension of the album art
file_ext=$(exiftool -FileType "$album_art" | awk -F': ' '{print $2}' | tr '[:upper:]' '[:lower:]')
echo "album art file type is $file_ext"
# Convert the album art to JPEG format
convert_cmd="magick '$album_art' '${file%.m4a}.jpg'"
echo "> $convert_cmd"
eval "$convert_cmd"
echo "Album art converted to JPEG format: ${file%.m4a}.jpg"
# Update the embedded album art with the new JPEG image
exiftool -overwrite_original -CoverArt "${file%.m4a}.jpg" -all:image "$file"
echo "Album art updated in $file"
rm "${file%.m4a}.jpg"
else
echo "No album art found in $file"
fi
}
if [[ -f $1 ]]; then
# If the 1st arg is a file, convert it
convert_album_art "$1"
else
# Iterate through all M4A files in the current directory
for file in *.m4a; do
convert_album_art "$file"
done
fi
# Download in m4a format
--format="ba[ext=m4a]"
# Set track number, album name, and artist name metadata tags
--add-metadata
--embed-thumbnail
# Save file to TRACK NAME
-o "%(title)s.%(ext)s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment