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]}" ] \
&& (
(
! [[ ${destinationrenamepath[$destination]} =~ %\{album\} ]] \
|| [ -n "$album" ]
) && (
! [[ ${destinationrenamepath[$destination]} =~ %\{albumartist\} ]] \
|| [ -n "$albumartist" ]
) && (
! [[ ${destinationrenamepath[$destination]} =~ %\{artist\} ]] \
|| [ -n "$artist" ]
) && (
! [[ ${destinationrenamepath[$destination]} =~ %\{genre\} ]] \
|| [ -n "$genre" ]
) && (
! [[ ${destinationrenamepath[$destination]} =~ %\{title\} ]] \
|| [ -n "$title" ]
) && (
! [[ ${destinationrenamepath[$destination]} =~ %\{track\} ]] \
|| [ -n "$track" ]
) && (
! [[ ${destinationrenamepath[$destination]} =~ %\{year\} ]] \
|| [ -n "$year" ]
) && (
! [[ ${destinationrenamepath[$destination]} =~ %\{disc\} ]] \
|| [ -n "$disc" ]
[[ ${destinationrenamepath[$destination]} == \
*?([^[])%\{album\}?([^\]])* ]] \
&& [ -n "$album" ]
) || (
[[ ${destinationrenamepath[$destination]} == \
*?([^[])%\{albumartist\}?([^\]])* ]] \
&& [ -n "$albumartist" ]
) || (
[[ ${destinationrenamepath[$destination]} == \
*?([^[])%\{artist\}?([^\]])* ]] \
&& [ -n "$artist" ]
) || (
[[ ${destinationrenamepath[$destination]} == \
*?([^[])%\{genre\}?([^\]])* ]] \
&& [ -n "$genre" ]
) || (
[[ ${destinationrenamepath[$destination]} == \
*?([^[])%\{title\}?([^\]])* ]] \
&& [ -n "$title" ]
) || (
[[ ${destinationrenamepath[$destination]} == \
*?([^[])%\{track\}?([^\]])* ]] \
&& [ -n "$track" ]
) || (
[[ ${destinationrenamepath[$destination]} == \
*?([^[])%\{year\}?([^\]])* ]] \
&& [ -n "$year" ]
) || (
[[ ${destinationrenamepath[$destination]} == \
*?([^[])%\{disc\}?([^\]])* ]] \
&& [ -n "$disc" ]
)
)
then
replace=$(sanitizeFile "$album" dir)
destdir+="${destinationrenamepath[$destination]//%\{album\}/$replace}"
destdir+="${destinationrenamepath[$destination]//?(\[)%\{album\}?(\])/$replace}"
replace=$(sanitizeFile "$albumartist" dir)
destdir="${destdir//%\{albumartist\}/$replace}"
destdir="${destdir//?(\[)%\{albumartist\}?(\])/$replace}"
replace=$(sanitizeFile "$artist" dir)
destdir="${destdir//%\{artist\}/$replace}"
destdir="${destdir//?(\[)%\{artist\}?(\])/$replace}"
replace=$(sanitizeFile "$genre" dir)
destdir="${destdir//%\{genre\}/$replace}"
destdir="${destdir//?(\[)%\{genre\}?(\])/$replace}"
replace=$(sanitizeFile "$title" dir)
destdir="${destdir//%\{title\}/$replace}"
destdir="${destdir//?(\[)%\{title\}?(\])/$replace}"
tracknumber="${track%/*}"
replace=$(sanitizeFile "$tracknumber" dir)
destdir="${destdir//%\{track\}/$replace}"
destdir="${destdir//?(\[)%\{track\}?(\])/$replace}"
replace=$(sanitizeFile "$year" dir)
destdir="${destdir//%\{year\}/$replace}"
destdir="${destdir//?(\[)%\{year\}?(\])/$replace}"
replace=$(sanitizeFile "$disc" dir)
destdir="${destdir//%\{disc\}/$replace}"
destdir="${destdir//?(\[)%\{disc\}?(\])/$replace}"
else
destdir+=$(sanitizeFile "${filename%%/*}" dir)
part=${filename#*/}

View File

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