Merge branch 'master' into toys

This commit is contained in:
Vincent Riquer 2013-05-28 13:41:10 +02:00
commit d6569713b1
8 changed files with 173 additions and 76 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.ex
*.EX
trace.log

View File

@ -43,42 +43,37 @@ copyFiles_action() {
rest=${rest#*::AtOM:SQL:Sep::} rest=${rest#*::AtOM:SQL:Sep::}
destfileid=${rest%%::AtOM:SQL:Sep::*} destfileid=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::} rest=${rest#*::AtOM:SQL:Sep::}
echo 'SELECT IFNULL( (
SELECT destination_files.filename
FROM destination_files
INNER JOIN source_files
ON destination_files.source_file_id=source_files.id
INNER JOIN mime_type_actions
ON
mime_type_actions.id=source_files.mime_type
INNER JOIN destinations
ON destinations.id=destination_files.destination_id
WHERE destinations.id = '$destinationid'
AND source_files.filename LIKE
"'"${sourcedir//\"/\"\"}"'/%"
AND mime_type_actions.action = 1
LIMIT 1
),"AtOM:NotFound");
'>&3
read -u4 filename
if [[ $filename != AtOM:NotFound ]]
then
destdir=${filename%/*}
if cp -al "$sourcepath/$sourcefilename" "$destdir" 2>/dev/null\
|| cp -a "$sourcepath/$sourcefilename" "$destdir"
then
Update destination_files \
filename "$destdir/${sourcefilename##*/}"\
rename_pattern "${destinationrenamepath[$destination]}/${destinationrename[$destination]}:${destinationfat32compat["$destination"]}"\
last_change $lastchange \
<<-EOWhere
id = $destfileid
EOWhere
(( done++ ))
fi
fi
(( count++ )) (( count++ ))
printf '\b\b\b\b%3i%%' $(( (count * 100) / ${#copyfiles[@]} )) printf '\b\b\b\b%3i%%' $(( (count * 100) / ${#copyfiles[@]} ))
if [ -n "${renamepath["$destination"]}" ]
then
destdir="$(guessPath)" || continue
else
destdir="${destinationpath["$destination"]}/"
destdir+=$(sanitizeFile "${sourcefilename%%/*}" dir)
part=${sourcefilename#*/}
while [[ $part =~ / ]]
do
destdir+="/$(sanitizeFile "${part%%/*}" dir)"
part=${part#*/}
done
if ! [ -d "$destdir" ]
then
mkdir -p "$destdir"
fi
fi
if cp -al "$sourcepath/$sourcefilename" "$destdir" 2>/dev/null\
|| cp -a "$sourcepath/$sourcefilename" "$destdir"
then
Update destination_files \
filename "$destdir/${sourcefilename##*/}"\
rename_pattern "${destinationrenamepath[$destination]}/${destinationrename[$destination]}:${destinationfat32compat["$destination"]}"\
last_change $lastchange \
<<-EOWhere
id = $destfileid
EOWhere
(( done++ ))
fi
done done
echo 'COMMIT;' >&3 echo 'COMMIT;' >&3
echo -e "\rCopied ${done:-0} of $count files.\033[K" echo -e "\rCopied ${done:-0} of $count files.\033[K"

28
lib/copy/guessPath Normal file
View File

@ -0,0 +1,28 @@
#!/bin/bash
guessPath() {
echo 'SELECT IFNULL( (
SELECT destination_files.filename
FROM destination_files
INNER JOIN source_files
ON destination_files.source_file_id=source_files.id
INNER JOIN mime_type_actions
ON
mime_type_actions.id=source_files.mime_type
INNER JOIN destinations
ON destinations.id=destination_files.destination_id
WHERE destinations.id = '$destinationid'
AND source_files.filename LIKE
"'"${sourcedir//\"/\"\"}"'/%"
AND mime_type_actions.action = 1
LIMIT 1
),"AtOM:NotFound");
'>&3
read -u4 filename
if [[ $filename != AtOM:NotFound ]]
then
echo "${filename%/*}"
else
return 1
fi
}

View File

@ -15,6 +15,10 @@ Insert() {
insert_keys+='`'"$key"'`' insert_keys+='`'"$key"'`'
(( ${#insert_values} )) && insert_values+="," (( ${#insert_values} )) && insert_values+=","
case $value in case $value in
'::AtOM:FT::'*)
value="${value//::AtOM:FT::/}"
insert_values+='"'"${value//\"/\"\"}"'"'
;;
'NULL') 'NULL')
insert_values+="NULL" insert_values+="NULL"
;; ;;

View File

@ -25,7 +25,8 @@ InsertIfUnset() {
Select "$table" "$column" < <( Select "$table" "$column" < <(
for key in ${!keys[@]} for key in ${!keys[@]}
do do
echo "${keys[$key]}" = "${values[$key]}" echo "${keys[$key]}" = \
"${values[$key]//::AtOM:FT::}"
done done
) )
) )

View File

@ -26,6 +26,10 @@ Update() {
;; ;;
value) value)
case $argument in case $argument in
'::AtOM:FT::'*)
argument="${argument//::AtOM:FT::/}"
set_statement+=" = "'"'"${argument//\"/\"\"}"'"'
;;
'NULL') 'NULL')
set_statement+=" = NULL" set_statement+=" = NULL"
;; ;;

View File

@ -4,32 +4,25 @@ updateTags() {
do do
tagreaderclause+="${tagreaderclause:+ AND }NOT tags.tagreader = \"$reader\"" tagreaderclause+="${tagreaderclause:+ AND }NOT tags.tagreader = \"$reader\""
done done
echo '
SELECT COUNT(DISTINCT source_files.filename)
FROM source_files
INNER JOIN destination_files
ON destination_files.source_file_id=source_files.id
INNER JOIN destinations
ON destination_files.destination_id=destinations.id
INNER JOIN mime_type_actions
ON destinations.id=mime_type_actions.destination_id
INNER JOIN tags
ON source_files.id=tags.source_file
WHERE mime_type_actions.id = source_files.mime_type
AND (
CAST(tags.last_change AS TEXT)
<>
CAST(source_files.last_change AS TEXT)
OR ('"$tagreaderclause"')
)
AND mime_type_actions.action = 1;' >&3
read -u4 filecount
echo ' echo '
SELECT DISTINCT SELECT DISTINCT
source_files.id, source_files.id,
source_files.last_change, source_files.last_change,
mime_type_actions.mime_text, mime_type_actions.mime_text,
source_files.filename source_files.filename,
tags.album,
tags.albumartist,
tags.artist,
tags.composer,
tags.disc,
tags.genre,
tags.performer,
tags.title,
tags.track,
tags.year,
tags.rate,
tags.channels,
tags.bitrate
FROM source_files FROM source_files
INNER JOIN destination_files INNER JOIN destination_files
ON destination_files.source_file_id=source_files.id ON destination_files.source_file_id=source_files.id
@ -53,6 +46,7 @@ updateTags() {
while ! [[ $line = AtOM:NoMoreFiles ]] while ! [[ $line = AtOM:NoMoreFiles ]]
do do
tagfiles+=("$line") tagfiles+=("$line")
(( filecount++ ))
read -u4 line read -u4 line
done done
echo 'BEGIN TRANSACTION;' >&3 echo 'BEGIN TRANSACTION;' >&3
@ -63,7 +57,34 @@ updateTags() {
lastchange=${rest%%::AtOM:SQL:Sep::*} lastchange=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::} rest=${rest#*::AtOM:SQL:Sep::}
mimetype=${rest%%::AtOM:SQL:Sep::*} mimetype=${rest%%::AtOM:SQL:Sep::*}
filename=${rest#*::AtOM:SQL:Sep::} rest=${rest#*::AtOM:SQL:Sep::}
filename=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldalbum=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldalbumartist=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldartist=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldcomposer=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
olddisc=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldgenre=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldperformer=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldtitle=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldtrack=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldyear=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldrate=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldchannels=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
oldbitrate=${rest%%::AtOM:SQL:Sep::*}
echo -en "\rTags: $((++count*100/filecount))%" echo -en "\rTags: $((++count*100/filecount))%"
if (( count % 1000 == 0 )) if (( count % 1000 == 0 ))
then then
@ -73,22 +94,35 @@ updateTags() {
fi fi
if getTags if getTags
then then
Update tags \ [[ $oldalbum != "$album" ]]&& ual=1
album "${album:-NULL}" \ [[ $oldalbumartist != "$albumartist" ]]&&uaa=1
albumartist "${albumartist:-NULL}" \ [[ $oldartist != "$artist" ]]&& uar=1
artist "${artist:-NULL}" \ [[ $oldcomposer != "$composer" ]]&& uco=1
composer "${composer:-NULL}" \ [[ $olddisc != "$disc" ]]&& udi=1
disc "${disc:-NULL}" \ [[ $oldgenre != "$genre" ]]&& uge=1
genre "${genre:-NULL}" \ [[ $oldperformer != "$performer" ]]&& upe=1
performer "${performer:-NULL}" \ [[ $oldtitle != "$title" ]]&& uti=1
title "${title:-NULL}" \ [[ $oldtrack != "$tracknum" ]]&& utr=1
track "${tracknum:-NULL}" \ [[ $oldyear != "$year" ]]&& uye=1
year "${year:-NULL}" \ [[ $oldrate != "$rate" ]]&& ura=1
last_change "$lastchange" \ [[ $oldchannels != "$channels" ]]&& uch=1
rate "${rate:-NULL}" \ [[ $oldbitrate != "$bitrate" ]]&& ubi=1
channels "${channels:-NULL}" \ Update tags \
bitrate "${bitrate:-NULL}" \ ${ual:+album "::AtOM:FT::${album:-NULL}"}\
tagreader "$tagreader" \ ${uaa:+albumartist "::AtOM:FT::${albumartist:-NULL}"}\
${uar:+artist "::AtOM:FT::${artist:-NULL}"}\
${uco:+composer "::AtOM:FT::${composer:-NULL}"}\
${udi:+disc "${disc:-NULL}"} \
${uge:+genre "${genre:-NULL}"} \
${upe:+performer "::AtOM:FT::${performer:-NULL}"}\
${uti:+title "::AtOM:FT::${title:-NULL}"}\
${utr:+track "::AtOM:FT::${tracknum:-NULL}"}\
${uye:+year "${year:-NULL}"} \
last_change "$lastchange" \
${ura:+rate "${rate:-NULL}"} \
${uch:+channels "${channels:-NULL}"} \
${ubi:+bitrate "${bitrate:-NULL}"} \
tagreader "$tagreader" \
>/dev/null <<<"source_file = $sourcefileid" >/dev/null <<<"source_file = $sourcefileid"
unset genre \ unset genre \
albumartist \ albumartist \
@ -102,7 +136,20 @@ updateTags() {
performer \ performer \
rate \ rate \
bitrate \ bitrate \
channels channels \
ual \
uaa \
uar \
uco \
udi \
uge \
upe \
uti \
utr \
uye \
ura \
uch \
ubi
fi fi
done done
echo 'COMMIT;' >&3 echo 'COMMIT;' >&3

View File

@ -110,8 +110,23 @@ CREATE TRIGGER IF NOT EXISTS create_tags AFTER INSERT ON source_files
BEGIN BEGIN
INSERT INTO tags (source_file,last_change) VALUES (new.id,0); INSERT INTO tags (source_file,last_change) VALUES (new.id,0);
END; END;
CREATE TRIGGER IF NOT EXISTS force_destination_update_on_tag_update DROP TRIGGER IF EXISTS force_destination_update_on_tag_update;
AFTER UPDATE ON tags CREATE TRIGGER force_destination_update_on_tag_update
AFTER UPDATE OF
genre,
albumartist,
year,
album,
disc,
artist,
track,
title,
composer,
performer,
rate,
channels,
bitrate
ON tags
BEGIN BEGIN
UPDATE destination_files SET last_change=0 UPDATE destination_files SET last_change=0
WHERE source_file_id=old.source_file; WHERE source_file_id=old.source_file;