create function updateTags()
* move code from atom to updateTags() * toys/missingtags: update tags
This commit is contained in:
parent
7b34e0eb11
commit
7c8617d713
110
atom
110
atom
@ -161,115 +161,7 @@ do
|
||||
done
|
||||
echo "Suppressed $deleted files, $removed removed from database"
|
||||
|
||||
# get files
|
||||
for reader in "${tagreaders[@]}"
|
||||
do
|
||||
tagreaderclause+="${tagreaderclause:+ AND }NOT tags.tagreader = \"$reader\""
|
||||
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 '
|
||||
SELECT DISTINCT
|
||||
source_files.id,
|
||||
source_files.last_change,
|
||||
mime_type_actions.mime_text,
|
||||
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;
|
||||
|
||||
SELECT "AtOM:NoMoreFiles";' >&3
|
||||
read -u4 line
|
||||
while ! [[ $line = AtOM:NoMoreFiles ]]
|
||||
do
|
||||
tagfiles+=("$line")
|
||||
read -u4 line
|
||||
done
|
||||
echo 'BEGIN TRANSACTION;' >&3
|
||||
for line in "${tagfiles[@]}"
|
||||
do
|
||||
sourcefileid=${line%%::AtOM:SQL:Sep::*}
|
||||
rest=${line#*::AtOM:SQL:Sep::}
|
||||
lastchange=${rest%%::AtOM:SQL:Sep::*}
|
||||
rest=${rest#*::AtOM:SQL:Sep::}
|
||||
mimetype=${rest%%::AtOM:SQL:Sep::*}
|
||||
filename=${rest#*::AtOM:SQL:Sep::}
|
||||
echo -en "\rTags: $((++count*100/filecount))%"
|
||||
if (( count % 1000 == 0 ))
|
||||
then
|
||||
echo 'COMMIT;BEGIN TRANSACTION;' >&3
|
||||
(( debug )) \
|
||||
&& echo -n " $count files read, committing..."
|
||||
fi
|
||||
if getTags
|
||||
then
|
||||
Update tags \
|
||||
album "${album:-NULL}" \
|
||||
albumartist "${albumartist:-NULL}" \
|
||||
artist "${artist:-NULL}" \
|
||||
composer "${composer:-NULL}" \
|
||||
disc "${disc:-NULL}" \
|
||||
genre "${genre:-NULL}" \
|
||||
performer "${performer:-NULL}" \
|
||||
title "${title:-NULL}" \
|
||||
track "${tracknum:-NULL}" \
|
||||
year "${year:-NULL}" \
|
||||
last_change "$lastchange" \
|
||||
rate "${rate:-NULL}" \
|
||||
channels "${channels:-NULL}" \
|
||||
bitrate "${bitrate:-NULL}" \
|
||||
tagreader "$tagreader" \
|
||||
>/dev/null <<<"source_file = $sourcefileid"
|
||||
unset genre \
|
||||
albumartist \
|
||||
year \
|
||||
album \
|
||||
disc \
|
||||
artist \
|
||||
tracknum \
|
||||
title \
|
||||
composer \
|
||||
performer \
|
||||
rate \
|
||||
bitrate \
|
||||
channels
|
||||
fi
|
||||
done
|
||||
echo 'COMMIT;' >&3
|
||||
echo -e "\rRead tags from ${count:-0} files.\033[K"
|
||||
unset count tagfiles
|
||||
updateTags
|
||||
|
||||
echo '
|
||||
CREATE TEMPORARY TABLE tasks(
|
||||
|
||||
111
lib/tags/updateTags
Normal file
111
lib/tags/updateTags
Normal file
@ -0,0 +1,111 @@
|
||||
#!/bin/bash
|
||||
updateTags() {
|
||||
for reader in "${tagreaders[@]}"
|
||||
do
|
||||
tagreaderclause+="${tagreaderclause:+ AND }NOT tags.tagreader = \"$reader\""
|
||||
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 '
|
||||
SELECT DISTINCT
|
||||
source_files.id,
|
||||
source_files.last_change,
|
||||
mime_type_actions.mime_text,
|
||||
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;
|
||||
|
||||
SELECT "AtOM:NoMoreFiles";' >&3
|
||||
read -u4 line
|
||||
while ! [[ $line = AtOM:NoMoreFiles ]]
|
||||
do
|
||||
tagfiles+=("$line")
|
||||
read -u4 line
|
||||
done
|
||||
echo 'BEGIN TRANSACTION;' >&3
|
||||
for line in "${tagfiles[@]}"
|
||||
do
|
||||
sourcefileid=${line%%::AtOM:SQL:Sep::*}
|
||||
rest=${line#*::AtOM:SQL:Sep::}
|
||||
lastchange=${rest%%::AtOM:SQL:Sep::*}
|
||||
rest=${rest#*::AtOM:SQL:Sep::}
|
||||
mimetype=${rest%%::AtOM:SQL:Sep::*}
|
||||
filename=${rest#*::AtOM:SQL:Sep::}
|
||||
echo -en "\rTags: $((++count*100/filecount))%"
|
||||
if (( count % 1000 == 0 ))
|
||||
then
|
||||
echo 'COMMIT;BEGIN TRANSACTION;' >&3
|
||||
(( debug )) \
|
||||
&& echo -n " $count files read, committing..."
|
||||
fi
|
||||
if getTags
|
||||
then
|
||||
Update tags \
|
||||
album "${album:-NULL}" \
|
||||
albumartist "${albumartist:-NULL}" \
|
||||
artist "${artist:-NULL}" \
|
||||
composer "${composer:-NULL}" \
|
||||
disc "${disc:-NULL}" \
|
||||
genre "${genre:-NULL}" \
|
||||
performer "${performer:-NULL}" \
|
||||
title "${title:-NULL}" \
|
||||
track "${tracknum:-NULL}" \
|
||||
year "${year:-NULL}" \
|
||||
last_change "$lastchange" \
|
||||
rate "${rate:-NULL}" \
|
||||
channels "${channels:-NULL}" \
|
||||
bitrate "${bitrate:-NULL}" \
|
||||
tagreader "$tagreader" \
|
||||
>/dev/null <<<"source_file = $sourcefileid"
|
||||
unset genre \
|
||||
albumartist \
|
||||
year \
|
||||
album \
|
||||
disc \
|
||||
artist \
|
||||
tracknum \
|
||||
title \
|
||||
composer \
|
||||
performer \
|
||||
rate \
|
||||
bitrate \
|
||||
channels
|
||||
fi
|
||||
done
|
||||
echo 'COMMIT;' >&3
|
||||
echo -e "\rRead tags from ${count:-0} files.\033[K"
|
||||
unset count tagfiles
|
||||
}
|
||||
@ -93,6 +93,7 @@ if (( update ))
|
||||
then
|
||||
getFiles
|
||||
updateMimes
|
||||
updateTags
|
||||
fi
|
||||
|
||||
for check in ${!checks[@]}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user