diff --git a/flac_set_tags_from_filename.sh b/flac_set_tags_from_filename.sh new file mode 100644 index 0000000..a27755d --- /dev/null +++ b/flac_set_tags_from_filename.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# sets the tags for songs (FLAC files) according to their name +# the name should be in the format: . - .flac. +# so for example: 01. Artist - Title.flac + +for file in *.flac; do + name="${file%.flac}" + + if [[ "$name" =~ ^([0-9]+)\.\ (.+)\ -\ (.+)$ ]]; then + track="${BASH_REMATCH[1]}" + artist="${BASH_REMATCH[2]}" + title="${BASH_REMATCH[3]}" + + echo "Tagging: $file" + echo " TRACKNUMBER=$track" + echo " ARTIST=$artist" + echo " TITLE=$title" + + metaflac --remove-tag=TRACKNUMBER \ + --remove-tag=ARTIST \ + --remove-tag=TITLE \ + --set-tag="TRACKNUMBER=$track" \ + --set-tag="ARTIST=$artist" \ + --set-tag="TITLE=$title" \ + "$file" + else + echo "Skipping (unexpected format): $file" + fi +done