Merge branch 'toys'
This commit is contained in:
commit
249cf7a2ff
8
toys/README
Normal file
8
toys/README
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
checkextensions
|
||||||
|
===============
|
||||||
|
Reports files whose extension does not match the (detected) mime-type.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-u: update source directory
|
||||||
|
-r: rename files
|
||||||
|
-n: (with -r): show what would be done.
|
||||||
212
toys/checkextensions
Executable file
212
toys/checkextensions
Executable file
@ -0,0 +1,212 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# config structures
|
||||||
|
declare -A \
|
||||||
|
destinationchannels \
|
||||||
|
destinationfat32compat \
|
||||||
|
destinationcopymime \
|
||||||
|
destinationformat \
|
||||||
|
destinationfrequency \
|
||||||
|
destinationid \
|
||||||
|
destinationloss \
|
||||||
|
destinationmaxbps \
|
||||||
|
destinationnormalize \
|
||||||
|
destinationpath \
|
||||||
|
destinationquality \
|
||||||
|
destinationrename \
|
||||||
|
destinationnoresample \
|
||||||
|
destinationrenamepath \
|
||||||
|
destinationskipmime \
|
||||||
|
|| {
|
||||||
|
echo "Check your Bash version. You need >= 4.0" >&2
|
||||||
|
exit $EBASHVERS
|
||||||
|
}
|
||||||
|
|
||||||
|
declare -r \
|
||||||
|
DOCDIR=./doc \
|
||||||
|
LIBDIR=./lib \
|
||||||
|
SHAREDIR=./share
|
||||||
|
declare -r \
|
||||||
|
exampleconf=$DOCDIR/example.cfg \
|
||||||
|
schema=$SHAREDIR/schema.sql \
|
||||||
|
\
|
||||||
|
oldIFS="$IFS"
|
||||||
|
|
||||||
|
LC_ALL=C
|
||||||
|
|
||||||
|
shopt -s extglob
|
||||||
|
|
||||||
|
for function in "$LIBDIR"/*/*
|
||||||
|
do
|
||||||
|
source "$function"
|
||||||
|
done
|
||||||
|
|
||||||
|
while getopts 'urnD' opt
|
||||||
|
do
|
||||||
|
case $opt in
|
||||||
|
u) update=1 ;;
|
||||||
|
r) rename=1 ;;
|
||||||
|
n) pretend=1 ;;
|
||||||
|
D) (( debug++ )) ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
getConfig
|
||||||
|
|
||||||
|
openDatabase
|
||||||
|
|
||||||
|
(( update )) && getFiles
|
||||||
|
|
||||||
|
echo '
|
||||||
|
SELECT
|
||||||
|
source_files.id,
|
||||||
|
source_files.filename,
|
||||||
|
mime_types.mime_text
|
||||||
|
FROM
|
||||||
|
source_files
|
||||||
|
INNER JOIN mime_types
|
||||||
|
ON source_files.mime_type = mime_types.id
|
||||||
|
;
|
||||||
|
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 " -> ${filename%.*}$extension"
|
||||||
|
if ! (( pretend ))
|
||||||
|
then
|
||||||
|
if [[ $dest == '' ]]
|
||||||
|
then
|
||||||
|
table=destination_files
|
||||||
|
else
|
||||||
|
table=source_files
|
||||||
|
fi
|
||||||
|
mv \
|
||||||
|
"${dest:+$dest/}$filename" \
|
||||||
|
"${dest:+$dest/}${filename%.*}$extension" \
|
||||||
|
&& Update $table filename "${filename%.*}$extension"<<-EOW
|
||||||
|
id = $fileid
|
||||||
|
EOW
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
while read -u4 line
|
||||||
|
do
|
||||||
|
if [[ $line == AtOM:NoMoreFiles ]]
|
||||||
|
then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
lines+=("$line")
|
||||||
|
done
|
||||||
|
for line in "${lines[@]}"
|
||||||
|
do
|
||||||
|
fileid=${line%%|*}
|
||||||
|
rest="${line#*|}|"
|
||||||
|
filename=${rest%%|*}
|
||||||
|
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 =~ Musepack ]] || continue
|
||||||
|
if [[ ${filename##*.} != flac ]]
|
||||||
|
then
|
||||||
|
format=mpc
|
||||||
|
extension=.mpc
|
||||||
|
echo "$filename: Musepack ($extension)"
|
||||||
|
(( rename )) && renameFile
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
closeDatabase
|
||||||
Loading…
x
Reference in New Issue
Block a user