From 4bd492b716fd86f9ebf2bf21cb71177666871b50 Mon Sep 17 00:00:00 2001 From: ymir Date: Thu, 23 Jul 2026 14:38:22 +0000 Subject: [PATCH] Add script to set flac tags from filename --- flac_set_tags_from_filename.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 flac_set_tags_from_filename.sh 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