Skip to content

Instantly share code, notes, and snippets.

@sillage
Last active December 23, 2023 18:44
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sillage/7c15c2701e00e0a85017 to your computer and use it in GitHub Desktop.
Save sillage/7c15c2701e00e0a85017 to your computer and use it in GitHub Desktop.
flac tags with metaflac
#!/bin/bash
# file format: ARTIST/ALBUM/01-TITLE.flac
read -p "YEAR? " -n 4 YEAR
ALBUM="${PWD##*/}" # ALBUM=$(basename "${PWD}")
ARTIST=$(echo $(cd .. && echo "${PWD##*/}"))
# delete all
metaflac --preserve-modtime --remove-all-tags *.flac
# artist, album, year and cover
metaflac --preserve-modtime --set-tag=ARTIST="${ARTIST}" --set-tag=ALBUM="${ALBUM}" --set-tag=DATE=${YEAR} --import-picture-from=Folder.jpg *.flac
# using input redirection and process substitution (!) to manage punctuation and spaces
# TRACKNUMBER
while read file;
do
# only keep tracknumber before `-'
metaflac --preserve-modtime --set-tag=TRACKNUMBER=${file%%-*} "${file}";
done < <(ls *.flac)
# TITLE
while read file;
do
TITLE="${file#*-}"; # remove tracknumber
TITLE="${TITLE%.flac}"; # remove extension
metaflac --preserve-modtime --set-tag=TITLE="${TITLE}" "${file}";
done < <(ls *.flac)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment