Add script to set flac tags from filename

This commit is contained in:
2026-07-23 14:38:22 +00:00
parent 1d6f6a1598
commit 4bd492b716

View File

@@ -0,0 +1,30 @@
#!/bin/bash
# sets the tags for songs (FLAC files) according to their name
# the name should be in the format: <TRACK NR>. <ARTIST> - <TITLE>.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