Fix rename_pattern, permit optional fields with []

This commit is contained in:
Vincent Riquer 2013-10-09 17:20:36 +02:00
parent eba2adf2c2
commit f9143525d0
2 changed files with 80 additions and 65 deletions

View File

@ -4,49 +4,57 @@ getDestDir() {
if [ -n "${destinationrenamepath[$destination]}" ] \ if [ -n "${destinationrenamepath[$destination]}" ] \
&& ( && (
( (
! [[ ${destinationrenamepath[$destination]} =~ %\{album\} ]] \ [[ ${destinationrenamepath[$destination]} == \
|| [ -n "$album" ] *?([^[])%\{album\}?([^\]])* ]] \
) && ( && [ -n "$album" ]
! [[ ${destinationrenamepath[$destination]} =~ %\{albumartist\} ]] \ ) || (
|| [ -n "$albumartist" ] [[ ${destinationrenamepath[$destination]} == \
) && ( *?([^[])%\{albumartist\}?([^\]])* ]] \
! [[ ${destinationrenamepath[$destination]} =~ %\{artist\} ]] \ && [ -n "$albumartist" ]
|| [ -n "$artist" ] ) || (
) && ( [[ ${destinationrenamepath[$destination]} == \
! [[ ${destinationrenamepath[$destination]} =~ %\{genre\} ]] \ *?([^[])%\{artist\}?([^\]])* ]] \
|| [ -n "$genre" ] && [ -n "$artist" ]
) && ( ) || (
! [[ ${destinationrenamepath[$destination]} =~ %\{title\} ]] \ [[ ${destinationrenamepath[$destination]} == \
|| [ -n "$title" ] *?([^[])%\{genre\}?([^\]])* ]] \
) && ( && [ -n "$genre" ]
! [[ ${destinationrenamepath[$destination]} =~ %\{track\} ]] \ ) || (
|| [ -n "$track" ] [[ ${destinationrenamepath[$destination]} == \
) && ( *?([^[])%\{title\}?([^\]])* ]] \
! [[ ${destinationrenamepath[$destination]} =~ %\{year\} ]] \ && [ -n "$title" ]
|| [ -n "$year" ] ) || (
) && ( [[ ${destinationrenamepath[$destination]} == \
! [[ ${destinationrenamepath[$destination]} =~ %\{disc\} ]] \ *?([^[])%\{track\}?([^\]])* ]] \
|| [ -n "$disc" ] && [ -n "$track" ]
) || (
[[ ${destinationrenamepath[$destination]} == \
*?([^[])%\{year\}?([^\]])* ]] \
&& [ -n "$year" ]
) || (
[[ ${destinationrenamepath[$destination]} == \
*?([^[])%\{disc\}?([^\]])* ]] \
&& [ -n "$disc" ]
) )
) )
then then
replace=$(sanitizeFile "$album" dir) replace=$(sanitizeFile "$album" dir)
destdir+="${destinationrenamepath[$destination]//%\{album\}/$replace}" destdir+="${destinationrenamepath[$destination]//?(\[)%\{album\}?(\])/$replace}"
replace=$(sanitizeFile "$albumartist" dir) replace=$(sanitizeFile "$albumartist" dir)
destdir="${destdir//%\{albumartist\}/$replace}" destdir="${destdir//?(\[)%\{albumartist\}?(\])/$replace}"
replace=$(sanitizeFile "$artist" dir) replace=$(sanitizeFile "$artist" dir)
destdir="${destdir//%\{artist\}/$replace}" destdir="${destdir//?(\[)%\{artist\}?(\])/$replace}"
replace=$(sanitizeFile "$genre" dir) replace=$(sanitizeFile "$genre" dir)
destdir="${destdir//%\{genre\}/$replace}" destdir="${destdir//?(\[)%\{genre\}?(\])/$replace}"
replace=$(sanitizeFile "$title" dir) replace=$(sanitizeFile "$title" dir)
destdir="${destdir//%\{title\}/$replace}" destdir="${destdir//?(\[)%\{title\}?(\])/$replace}"
tracknumber="${track%/*}" tracknumber="${track%/*}"
replace=$(sanitizeFile "$tracknumber" dir) replace=$(sanitizeFile "$tracknumber" dir)
destdir="${destdir//%\{track\}/$replace}" destdir="${destdir//?(\[)%\{track\}?(\])/$replace}"
replace=$(sanitizeFile "$year" dir) replace=$(sanitizeFile "$year" dir)
destdir="${destdir//%\{year\}/$replace}" destdir="${destdir//?(\[)%\{year\}?(\])/$replace}"
replace=$(sanitizeFile "$disc" dir) replace=$(sanitizeFile "$disc" dir)
destdir="${destdir//%\{disc\}/$replace}" destdir="${destdir//?(\[)%\{disc\}?(\])/$replace}"
else else
destdir+=$(sanitizeFile "${filename%%/*}" dir) destdir+=$(sanitizeFile "${filename%%/*}" dir)
part=${filename#*/} part=${filename#*/}

View File

@ -3,41 +3,48 @@ getDestFile() {
if [ -n "${destinationrename[$destination]}" ] \ if [ -n "${destinationrename[$destination]}" ] \
&& ( && (
( (
! [[ ${destinationrename[$destination]} =~ %\{album\} ]] \ [[ ${destinationrename[$destination]} == \
|| [ -n "$album" ] *?([^[])%\{album\}?([^\]])* ]] \
) && ( && [ -n "$album" ]
! [[ ${destinationrename[$destination]} =~ %\{albumartist\} ]] \ ) || (
|| [ -n "$albumartist" ] [[ ${destinationrename[$destination]} == \
) && ( *?([^[])%\{albumartist\}?([^\]])* ]] \
! [[ ${destinationrename[$destination]} =~ %\{artist\} ]] \ && [ -n "$albumartist" ]
|| [ -n "$artist" ] ) || (
) && ( [[ ${destinationrename[$destination]} == \
! [[ ${destinationrename[$destination]} =~ %\{genre\} ]] \ *?([^[])%\{artist\}?([^\]])* ]] \
|| [ -n "$genre" ] && [ -n "$artist" ]
) && ( ) || (
! [[ ${destinationrename[$destination]} =~ %\{title\} ]] \ [[ ${destinationrename[$destination]} == \
|| [ -n "$title" ] *?([^[])%\{genre\}?([^\]])* ]] \
) && ( && [ -n "$genre" ]
! [[ ${destinationrename[$destination]} =~ %\{track\} ]] \ ) || (
|| [ -n "$track" ] [[ ${destinationrename[$destination]} == \
) && ( *?([^[])%\{title\}?([^\]])* ]] \
! [[ ${destinationrename[$destination]} =~ %\{year\} ]] \ && [ -n "$title" ]
|| [ -n "$year" ] ) || (
) && ( [[ ${destinationrename[$destination]} == \
! [[ ${destinationrename[$destination]} =~ %\{disc\} ]] \ *?([^[])%\{track\}?([^\]])* ]] \
|| [ -n "$disc" ] && [ -n "$track" ]
) || (
[[ ${destinationrename[$destination]} == \
*?([^[])%\{year\}?([^\]])* ]] \
&& [ -n "$year" ]
) || (
[[ ${destinationrename[$destination]} == \
*?([^[])%\{disc\}?([^\]])* ]] \
&& [ -n "$disc" ]
) )
) )
then destfile="${destinationrename[$destination]//?(\[)%\{album\}?(\])/$album}"
destfile="${destinationrename[$destination]//%\{album\}/$album}" destfile="${destfile//?(\[)%\{albumartist\}?(\])/$albumartist}"
destfile="${destfile//%\{albumartist\}/$albumartist}" destfile="${destfile//?(\[)%\{artist\}?(\])/$artist}"
destfile="${destfile//%\{artist\}/$artist}" destfile="${destfile//?(\[)%\{genre\}?(\])/$genre}"
destfile="${destfile//%\{genre\}/$genre}" destfile="${destfile//?(\[)%\{title\}?(\])/$title}"
destfile="${destfile//%\{title\}/$title}"
tracknumber="${track%/*}" tracknumber="${track%/*}"
destfile="${destfile//%\{track\}/$tracknumber}" destfile="${destfile//?(\[)%\{track\}?(\])/$tracknumber}"
destfile="${destfile//%\{year\}/$year}" destfile="${destfile//?(\[)%\{year\}?(\])/$year}"
destfile="${destfile//%\{disc\}/$disc}" destfile="${destfile//?(\[)%\{disc\}?(\])/$disc}"
else else
destfile="${filename##*/}" destfile="${filename##*/}"
destfile="${destfile%.*}" destfile="${destfile%.*}"