Skip to content

Instantly share code, notes, and snippets.

@jfeilbach
Last active May 1, 2019 17:49
Show Gist options
  • Select an option

  • Save jfeilbach/d4a8feb991c1174b4941e746683d82b1 to your computer and use it in GitHub Desktop.

Select an option

Save jfeilbach/d4a8feb991c1174b4941e746683d82b1 to your computer and use it in GitHub Desktop.
add album cover art to flac audio files
#!/bin/bash
# add cover art image to flac audio files, requires metaflac
# run from working directory
SECONDS=0
COVER=${1}
COUNT=$(ls *.flac | wc -l)
COUNTER='1'
CMD='metaflac'
NC='\e[0m'
WHITE='\e[1;37m'
YELLOW='\e[1;33m'
LIGHT_BLUE='\e[1;34m'
CYAN='\e[0;36m'
RED='\e[0;31m'
displaytime () {
local T=$SECONDS
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
[[ $D > 0 ]] && printf '%d days ' $D
[[ $H > 0 ]] && printf '%d hours ' $H
[[ $M > 0 ]] && printf '%d minutes ' $M
[[ $D > 0 || $H > 0 || $M > 0 ]] && printf 'and '
printf '%d seconds\n' $S
}
if [ "$1" == "" ]; then
echo -e "Please enter the path to the cover art. Exiting.\n"
exit 1
fi
if [[ -e "${COVER}" ]]; then
echo ""
echo -e "Cover art file ${WHITE}${COVER}${NC} found. Proceeding...\n"
else
echo -e "Cover art file ${WHITE}${COVER}${NC} not found. Exiting.\n"
exit 2
fi
if ! [ -x "$(command -v ${CMD})" ]; then
echo -e "${RED}Error: ${CMD} is not installed. Exiting.${NC}\n" >&2
exit 3
else
echo -e "${CMD} found at $(command -v ${CMD}). Proceeding...\n"
fi
if [ "$COUNT" == "0" ]; then
echo -e "${RED}Error: No .flac files found. Exiting.${NC}\n"
exit 4
fi
echo -e "Adding ${WHITE}${COVER}${NC} to ${WHITE}${COUNT}${NC} .flac audio files...\n"
for i in *.flac ; do
echo -ne "${COUNTER}/${COUNT} - Updating file \"${WHITE}${i}${NC}\" ... "
${CMD} --import-picture-from="${COVER}" "${i}"
echo "Done."
(( COUNTER++ ))
done
TIME=$(displaytime)
echo ""
echo -e "Completed in ${YELLOW}${TIME}${NC}.\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment