Implement ascii-only

This commit is contained in:
Vincent Riquer 2013-10-09 17:24:08 +02:00
parent f9143525d0
commit 6f2a29f0d5
4 changed files with 49 additions and 26 deletions

24
atom
View File

@ -301,6 +301,7 @@ then
Renaming to ASCII-only disabled" >&2 Renaming to ASCII-only disabled" >&2
unset destinationascii unset destinationascii
destinationascii=0 destinationascii=0
textunidecodeneeded=0
(( sanitywarn++ )) (( sanitywarn++ ))
fi fi
if (( sanityfail )) if (( sanityfail ))
@ -503,6 +504,8 @@ do
done done
(( cron )) || echo -n 'Creating tasks... ' (( cron )) || echo -n 'Creating tasks... '
(( textunidecodeneeded )) && ascii
echo 'BEGIN TRANSACTION;' >&3 echo 'BEGIN TRANSACTION;' >&3
for line in "${decodefiles[@]}" for line in "${decodefiles[@]}"
do do
@ -591,6 +594,9 @@ echo 'COMMIT;' >&3
(( cron )) || echo -n $'\r' (( cron )) || echo -n $'\r'
echo "Created ${count:-0} tasks for $filecount files ${togo:+($togo left) }(${copies:-0} immediate copies)" echo "Created ${count:-0} tasks for $filecount files ${togo:+($togo left) }(${copies:-0} immediate copies)"
# remove perl unicode to ascii coprocess
(( textunidecodeneeded )) && eval exec "${toascii[1]}>&-"
concurrency=$(( maxload / 2 )) concurrency=$(( maxload / 2 ))
(( concurrency )) || concurrency=1 (( concurrency )) || concurrency=1
active=0 active=0
@ -764,7 +770,6 @@ then
exit exit
fi fi
#set -x
for destination in "${!destinationpath[@]}" for destination in "${!destinationpath[@]}"
do do
echo ' echo '
@ -792,14 +797,18 @@ do
INNER JOIN source_files INNER JOIN source_files
ON destination_files.source_file_id ON destination_files.source_file_id
=source_files.id =source_files.id
INNER JOIN mime_actions
ON source_files.mime_type
=mime_actions.mime_type
WHERE destinations.name="'"$destination"'" WHERE destinations.name="'"$destination"'"
AND (destination_files.rename_pattern AND (destination_files.rename_pattern
!= !=
"'"${destinationrenamepath[$destination]}/${destinationrename[$destination]}"'" "'"${destinationrenamepath[$destination]}/${destinationrename[$destination]}"'"
OR fat32compat != ${destinationfat32compat["$destination"]} OR fat32compat != '${destinationfat32compat["$destination"]}'
OR ascii != ${destinationascii["$destination"]} OR ascii != '${destinationascii["$destination"]}'
OR destination_files.rename_pattern is NULL) OR destination_files.rename_pattern is NULL)
AND destination_files.last_change > 0 AND destination_files.last_change > 0
AND mime_actions.action=1
; ;
SELECT "AtOM:NoMoreFiles"; SELECT "AtOM:NoMoreFiles";
@ -819,6 +828,7 @@ do
'vorbis') extension=ogg ;; 'vorbis') extension=ogg ;;
esac esac
(( cron )) || echo -n "$destination: rename pattern changed, renaming files... " (( cron )) || echo -n "$destination: rename pattern changed, renaming files... "
(( textunidecodeneeded )) && ascii
echo 'BEGIN TRANSACTION;' >&3 echo 'BEGIN TRANSACTION;' >&3
for line in "${renamefiles[@]}" for line in "${renamefiles[@]}"
do do
@ -863,9 +873,9 @@ do
echo "UPDATE destination_files" \ echo "UPDATE destination_files" \
"SET filename=\"${destfilename//\"/\"\"}\"," \ "SET filename=\"${destfilename//\"/\"\"}\"," \
" rename_pattern=" \ " rename_pattern=" \
"\"${destinationrenamepath[$destination]}/${destinationrename[$destination]}" \ "\"${destinationrenamepath[$destination]}/${destinationrename[$destination]}\","\
" fat32compat=" " fat32compat=" \
"${destinationfat32compat["$destination"]}\"" \ "${destinationfat32compat["$destination"]}," \
" ascii=" \ " ascii=" \
"${destinationascii["$destination"]}" \ "${destinationascii["$destination"]}" \
"WHERE id=$destfileid;" \ "WHERE id=$destfileid;" \
@ -877,6 +887,8 @@ do
fi fi
fi fi
done done
# remove perl unicode to ascii coprocess
(( textunidecodeneeded )) && eval exec "${toascii[1]}>&-"
echo 'COMMIT;' >&3 echo 'COMMIT;' >&3
(( cron )) || echo -n $'\r' (( cron )) || echo -n $'\r'
echo -n "$destination: Renamed ${changedcount:-0} files" echo -n "$destination: Renamed ${changedcount:-0} files"

View File

@ -22,11 +22,11 @@ copyFiles_matching() {
" FROM destination_files" \ " FROM destination_files" \
" WHERE id=$destfileid" \ " WHERE id=$destfileid" \
" )," \ " )," \
" rename_pattern" \ " rename_pattern=" \
"\"${destinationrenamepath[$destination]}/${destinationrename[$destination]}\""\ "\"${destinationrenamepath[$destination]}/${destinationrename[$destination]}\","\
" fat32compat" \ " fat32compat=" \
" ${destinationfat32compat["$destination"]}"\ "${destinationfat32compat["$destination"]}," \
" ascii ${destinationascii["$destination"]}"\ " ascii=${destinationascii["$destination"]}" \
"WHERE id=$destfileid;" \ "WHERE id=$destfileid;" \
>&3 >&3
(( ++copies )) (( ++copies ))

View File

@ -64,6 +64,11 @@ getDestDir() {
part=${part#*/} part=${part#*/}
done done
fi fi
if (( ${destinationascii["$destination"]} ))
then
echo "$destdir" >&${toascii[1]}
read -r -u${toascii[0]} destdir
fi
if ! [ -d "$destdir" ] if ! [ -d "$destdir" ]
then then
mkdir -p "$destdir" mkdir -p "$destdir"

View File

@ -36,6 +36,7 @@ getDestFile() {
&& [ -n "$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}"
@ -49,5 +50,10 @@ getDestFile() {
destfile="${filename##*/}" destfile="${filename##*/}"
destfile="${destfile%.*}" destfile="${destfile%.*}"
fi fi
if (( ${destinationascii["$destination"]} ))
then
echo "$destfile" >&${toascii[1]}
read -r -u${toascii[0]} destfile
fi
destfile=$(sanitizeFile "$destfile") destfile=$(sanitizeFile "$destfile")
} }