Files
music_tools/bin/album_retitle

49 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
function fix_file_name
{
input="$1"
# echo ${input} | sed -e 's/ /_/g' -e "s/'/_/g" -e 's/_(/-/g' -e 's/)//g' -e 's/_-_/-/g' -e 's/\//_/g' | tr '[:upper:]' '[:lower:]'
echo ${input} | sed -e 's/\(^[0-9]*\)./\1-/' -e 's/[ ,!/?]/_/g' -e 's/\[/-/g' -e 's/\]//g' -e "s/'/_/g" -e 's/(/-/g' -e 's/)//g' -e 's/__/_/g' -e 's/_\././' -e 's/_-/-/g' -e 's/--/-/g' -e 's/-_/-/g' -e 's/é/e/g' -e 's/è/e/g' -e 's/ê/e/g' -e 's/ë/e/g' -e 's/à/a/g' -e 's/[+&]/and/' -e 's/^-//' -e 's/"/_inch/' | tr '[:upper:]' '[:lower:]'
}
shopt -s extglob
if [[ "$1" == "-h" ]]
then
echo "album_retitle [-h] | <source_dir> <target_dir> <title_file>"
exit
fi
source_dir="$1"
target_dir="$2"
title_file="$3"
i=1
while read title
do
file=(${source_dir}/$(printf %02d $i)-*.@(flac|mp3))
suffix=${file##*.}
target_file="${target_dir}/$( fix_file_name $( fix_file_name $( fix_file_name $(printf "%02d" $i)-"${title}.${file##*.}")))"
echo "${target_file}: '"${title}"'"
cp "${file}" "${target_file}"
case "${suffix}"
in
flac)
metaflac --remove-tag=TRACKNUMBER --set-tag=TRACKNUMBER=$i --remove-tag=TITLE --set-tag=TITLE="${title}" "${target_file}"
;;
mp3)
mid3v2 -T $i -t "${title}" "${target_file}"
;;
esac
i=$(($i + 1))
done < ${title_file}