From f9143525d028958f677bada7f0b6084dbae9dd55 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Wed, 9 Oct 2013 17:20:36 +0200 Subject: [PATCH] Fix rename_pattern, permit optional fields with [] --- lib/files/getDestDir | 72 +++++++++++++++++++++++------------------- lib/files/getDestFile | 73 ++++++++++++++++++++++++------------------- 2 files changed, 80 insertions(+), 65 deletions(-) diff --git a/lib/files/getDestDir b/lib/files/getDestDir index ff4f26b..f28fb49 100644 --- a/lib/files/getDestDir +++ b/lib/files/getDestDir @@ -1,52 +1,60 @@ #!/bin/bash getDestDir() { destdir="${destinationpath[$destination]}/" - if [ -n "${destinationrenamepath[$destination]}" ] \ + 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#*/} diff --git a/lib/files/getDestFile b/lib/files/getDestFile index 1ec9087..41c2003 100644 --- a/lib/files/getDestFile +++ b/lib/files/getDestFile @@ -1,43 +1,50 @@ #!/bin/bash getDestFile() { - if [ -n "${destinationrename[$destination]}" ] \ + 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%.*}"