想要批量重命名mp3文件到以下方案
my-artist_my-title.mp3
理想情况下,我更喜欢有一个
bash script
,我会用它来触发:
$ rename-mp3 directory-with-subdirectories-with-mp3-files
搜索类似的解决方案,我发现了this功能。我修改了它并且它有效,部分!标有
#?
的正则表达式修改不起作用。
function rename-mp3() { # input is an mp3 file: i.e. find -name 's3 24)3ü6 Dț67 .mp3' -exec bash -c 'rename-mp3 "$@"' bash {} \;
# extract metadata from file
artist=`ffprobe -loglevel error -show_entries format_tags=artist -of default=noprint_wrappers=1:nokey=1 "$1"`
title=`ffprobe -loglevel error -show_entries format_tags=title -of default=noprint_wrappers=1:nokey=1 "$1"`
artist="${artist/\&/}" #? delete all non-numeral, non-latin, and non-space characters (&, %, !, ', ä, ö, ü, ă, ț, etc.)
title="${title/\&/}" #? delete all non-numeral, non-latin, and non-space characters (&, %, !, ', ä, ö, ü, ă, ț, etc.)
artist="${artist// +/\-}" #? replace all spaces with "-", if more then one in sequence substitute only one "-"
title="${artist// +/\-}" #? replace all spaces with "-", if more then one in sequence substitute only one "-"
filename="$artist_$title.mp3" # paste artist and title together
filename="${name,,}" # lowercase everything
echo "$filename" # display new filename
cp "$1" "renamed/$name" # copy renamed file to the renamed folder
}