scan destination_files
This commit is contained in:
parent
2c507a4181
commit
496c48d04d
@ -69,14 +69,70 @@ echo '
|
||||
;
|
||||
SELECT "AtOM:NoMoreFiles";
|
||||
' >&3
|
||||
|
||||
getdstfiles() {
|
||||
local \
|
||||
line \
|
||||
lines
|
||||
unset dest
|
||||
for destination in "${!destinationformat[@]}"
|
||||
do
|
||||
if [[ ${destinationformat["$destination"]} != $format ]]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
echo '
|
||||
SELECT
|
||||
destination_files.id,
|
||||
destination_files.filename
|
||||
FROM destination_files
|
||||
INNER JOIN source_files
|
||||
ON
|
||||
destination_files.source_file_id=source_files.id
|
||||
INNER JOIN destinations
|
||||
ON
|
||||
destinations.id=destination_files.destination_id
|
||||
WHERE source_files.id='$fileid'
|
||||
AND destinations.name="'"$destination"'"
|
||||
AND destination_files.filename IS NOT NULL
|
||||
AND destination_files.filename NOT LIKE
|
||||
"%'$extension'"
|
||||
;
|
||||
SELECT "AtOM:NoMoreFiles";
|
||||
'>&3
|
||||
while read -u4 line
|
||||
do
|
||||
if [[ $line == AtOM:NoMoreFiles ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
lines+=("$line")
|
||||
done
|
||||
done
|
||||
for line in "${lines[@]}"
|
||||
do
|
||||
fileid=${line%|*}
|
||||
filename=${line#*|}
|
||||
echo $'\t'"$filename"
|
||||
(( rename )) && echo -n $'\t'
|
||||
(( rename )) && renameFile
|
||||
done
|
||||
}
|
||||
|
||||
renameFile() {
|
||||
echo $'\t'"${filename%.*}$extension"
|
||||
echo " -> ${filename%.*}$extension"
|
||||
if ! (( pretend ))
|
||||
then
|
||||
mv \
|
||||
"$sourcepath/$filename" \
|
||||
"$sourcepath/${filename%.*}$extension" \
|
||||
&& Update source_files filename "${filename%.*}$extension"<<-EOW
|
||||
"${dest:+$dest/}$filename" \
|
||||
"${dest:+$dest/}${filename%.*}$extension" \
|
||||
if [[ $dest == '' ]]
|
||||
then
|
||||
table=destination_files
|
||||
else
|
||||
table=source_files
|
||||
fi
|
||||
&& Update $table filename "${filename%.*}$extension"<<-EOW
|
||||
id = $fileid
|
||||
EOW
|
||||
fi
|
||||
@ -98,39 +154,58 @@ do
|
||||
rest=${rest#*|}
|
||||
mimetype=${rest%%|*}
|
||||
rest=${rest#*|}
|
||||
dest=$sourcepath
|
||||
case "$mimetype" in
|
||||
'audio/mpeg')
|
||||
if [[ ${filename##*.} != mp3 ]]
|
||||
then
|
||||
format=mp3
|
||||
extension=.mp3
|
||||
echo "$filename: MP3 ($extension)"
|
||||
(( rename )) && renameFile
|
||||
getdstfiles
|
||||
fi
|
||||
;;
|
||||
'application/ogg vorbis')
|
||||
if [[ ${filename##*.} != ogg ]]
|
||||
then
|
||||
format=vorbis
|
||||
extension=.ogg
|
||||
echo "$filename: Ogg Vorbis ($extension)"
|
||||
(( rename )) && renameFile
|
||||
getdstfiles
|
||||
fi
|
||||
;;
|
||||
'application/ogg opus')
|
||||
if [[ ${filename##*.} != opus ]]
|
||||
then
|
||||
format=opus
|
||||
extension=.opus
|
||||
echo "$filename: Opus ($extension)"
|
||||
(( rename )) && renameFile
|
||||
getdstfiles
|
||||
fi
|
||||
;;
|
||||
'audio/x-flac')
|
||||
if [[ ${filename##*.} != flac ]]
|
||||
then
|
||||
format=flac
|
||||
extension=.flac
|
||||
echo "$filename: FLAC ($extension)"
|
||||
(( rename )) && renameFile
|
||||
fi
|
||||
;;
|
||||
'application/data')
|
||||
extendedtype=$(file -b "$sourcepath/$filename")
|
||||
[[ $extendedtype =~ Mmeusepack ]] || continue
|
||||
if [[ ${filename##*.} != flac ]]
|
||||
then
|
||||
format=mpc
|
||||
extension=.mpc
|
||||
echo "$filename: Musepack ($extension)"
|
||||
(( rename )) && renameFile
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user