handle rename pattern change

This commit is contained in:
Vincent Riquer 2013-03-28 13:49:02 +01:00
parent 722a3896b4
commit 49031cde33
2 changed files with 111 additions and 5 deletions

115
atom
View File

@ -1059,7 +1059,14 @@ copyFile() {
" SELECT last_change" \
" FROM source_files" \
" WHERE id=$fileid" \
" )" \
" )," \
" old_filename=(" \
" SELECT filename" \
" FROM destination_files" \
" WHERE id=$destfileid" \
" )," \
" rename_pattern=" \
"\"${destinationrenamepath[$destination]}/${destinationrename[$destination]}\""\
"WHERE id=$destfileid;" \
>&3
(( ++copies ))
@ -1194,6 +1201,7 @@ encodeFile::mp3() {
cleanup $tempdir/$tmpfile.wav
source_file $fileid
status 0
rename_pattern "${destinationrenamepath[$destination]}/${destinationrename[$destination]}"
EOInsert
)
progressSpin
@ -1228,6 +1236,7 @@ encodeFile::vorbis() {
cleanup $tempdir/$tmpfile.wav
source_file $fileid
status 0
rename_pattern "${destinationrenamepath[$destination]}/${destinationrename[$destination]}"
EOInsert
)
progressSpin
@ -1502,6 +1511,11 @@ master() {
" SELECT filename" \
" FROM destination_files" \
" WHERE id=$destfileid" \
" )," \
" rename_pattern=(" \
" SELECT rename_pattern" \
" FROM tasks" \
" WHERE id=$taskid" \
" )" \
"WHERE id=$destfileid;" \
>&3
@ -1767,6 +1781,7 @@ echo '
CREATE TEMPORARY TABLE tasks(
id INTEGER PRIMARY KEY,
key TEXT UNIQUE,
rename_pattern TEXT,
source_file INTEGER,
fileid INTEGER,
filename TEXT,
@ -2096,22 +2111,22 @@ endtime=$(date +%s)
(( elapsedseconds = endtime - starttime ))
(( days =
secsremaining
elapsedseconds
/
( 24*60*60 )
)) || true
(( hours =
( secsremaining - ( days*24*60*60 ) )
( elapsedseconds - ( days*24*60*60 ) )
/
( 60*60 )
)) || true
(( minutes =
( secsremaining - ( ( days*24 + hours ) *60*60 ) )
( elapsedseconds - ( ( days*24 + hours ) *60*60 ) )
/
60
)) || true
(( seconds =
secsremaining
elapsedseconds
-
( ( ( ( days*24 + hours ) *60 ) + minutes ) *60 )
)) || true
@ -2119,6 +2134,96 @@ endtime=$(date +%s)
echo -e "\rRan $taskcount tasks, $failed of which failed, in $days" \
"days, $hours hours, $minutes minutes and $seconds seconds."
if [ -n "$quit" ]
then
closeDatabase
exit
fi
#set -x
for destination in "${!destinationpath[@]}"
do
echo '
SELECT
destination_files.filename,
tags.album,
tags.albumartist,
tags.artist,
tags.composer,
tags.disc,
tags.genre,
tags.performer,
tags.title,
tags.track,
tags.year
FROM destination_files
INNER JOIN destinations
ON destination_files.destination_id
=destinations.id
INNER JOIN tags
ON destination_files.source_file_id
=tags.source_file
WHERE destinations.name="'"$destination"'"
AND (destination_files.rename_pattern
!=
"'"${destinationrenamepath[$destination]}/${destinationrename[$destination]}"'"
OR destination_files.rename_pattern is NULL)
;
SELECT "AtOM:NoMoreFiles";
' >&3
read -u4 line
if [[ $line != AtOM:NoMoreFiles ]]
then
case "${destinationformat[$destination]}" in
'mp3') extension=mp3 ;;
'vorbis') extension=ogg ;;
esac
echo -n "$destination: rename pattern changed, renaming files... "
while [[ $line != AtOM:NoMoreFiles ]]
do
oldfilename=${line%%|*}
rest=${line#*|}'|'
album=${rest%%|*}
rest=${rest#*|}
albumartist=${rest%%|*}
rest=${rest#*|}
artist=${rest%%|*}
rest=${rest#*|}
composer=${rest%%|*}
rest=${rest#*|}
disc=${rest%%|*}
rest=${rest#*|}
genre=${rest%%|*}
rest=${rest#*|}
performer=${rest%%|*}
rest=${rest#*|}
title=${rest%%|*}
rest=${rest#*|}
track=${rest%%|*}
rest=${rest#*|}
year=${rest%%|*}
rest=${rest#*|}
if [ -n "$oldfilename" -a -f "$oldfilename" ]
then
getDestDir
getDestFile
destfilename="$destdir/$destfile.$extension"
mv "$oldfilename" "$destfilename"
echo "UPDATE destination_files" \
"SET filename=\"${destfilename//\"/\"\"}\"," \
" rename_pattern=" \
"\"${destinationrenamepath[$destination]}/${destinationrename[$destination]}\"" \
"WHERE id=$destfileid;" \
>&3
progressSpin
fi
done
fi
unset count
done
echo '
SELECT id,
old_filename

View File

@ -18,6 +18,7 @@ CREATE TABLE destination_files (
id INTEGER PRIMARY KEY,
filename TEXT,
old_filename TEXT,
rename_pattern TEXT,
last_change FLOAT NOT NULL DEFAULT 0,
source_file_id INTEGER,
destination_id INTEGER,