60 lines
1.9 KiB
Bash
60 lines
1.9 KiB
Bash
splitartist() {
|
|
local flac_file="$1"
|
|
local sep="${2:-,}" # Default separator is ','
|
|
|
|
if [[ ! -f "$flac_file" ]]; then
|
|
echo "File not found: $flac_file"
|
|
return 1
|
|
fi
|
|
|
|
if ! command -v metaflac >/dev/null 2>&1; then
|
|
echo "Error: metaflac not found"
|
|
return 1
|
|
fi
|
|
|
|
echo "Reading tags from: $flac_file"
|
|
|
|
local artist_tag albumartist_tag
|
|
artist_tag=$(metaflac --show-tag=ARTIST "$flac_file" | sed 's/^ARTIST=//')
|
|
albumartist_tag=$(metaflac --show-tag=ALBUMARTIST "$flac_file" | sed 's/^ALBUMARTIST=//')
|
|
|
|
IFS="$sep" read -ra artist_array <<< "$artist_tag"
|
|
IFS="$sep" read -ra albumartist_array <<< "$albumartist_tag"
|
|
|
|
echo -e "\nCurrent ARTIST tag: $artist_tag"
|
|
echo "Split ARTIST into:"
|
|
for a in "${artist_array[@]}"; do echo " - ${a#" "}"; done
|
|
|
|
echo -e "\nCurrent ALBUMARTIST tag: $albumartist_tag"
|
|
echo "Split ALBUMARTIST into:"
|
|
for a in "${albumartist_array[@]}"; do echo " - ${a#" "}"; done
|
|
|
|
echo -e "\nThe following actions will be performed on: $flac_file"
|
|
echo "1. Remove all ARTIST and ALBUMARTIST tags"
|
|
echo "2. Add split ARTIST tags:"
|
|
for a in "${artist_array[@]}"; do echo " --set-tag=ARTIST='${a#" "}"; done
|
|
echo "3. Add split ALBUMARTIST tags:"
|
|
for a in "${albumartist_array[@]}"; do echo " --set-tag=ALBUMARTIST='${a#" "}"; done
|
|
|
|
read -p $'\nProceed with these changes? [y/N]: ' confirm
|
|
if [[ "$confirm" != [yY] ]]; then
|
|
echo "Aborted."
|
|
return 0
|
|
fi
|
|
|
|
# Clear old tags
|
|
metaflac --remove-tag=ARTIST --remove-tag=ALBUMARTIST "$flac_file"
|
|
|
|
# Add split artist tags
|
|
for a in "${artist_array[@]}"; do
|
|
metaflac --set-tag="ARTIST=${a#" "}" "$flac_file"
|
|
done
|
|
|
|
# Add split albumartist tags
|
|
for a in "${albumartist_array[@]}"; do
|
|
metaflac --set-tag="ALBUMARTIST=${a#" "}" "$flac_file"
|
|
done
|
|
|
|
echo "Tags updated successfully."
|
|
}
|
|
|