create decoding tasks for Musepack files

This commit is contained in:
Vincent Riquer 2013-03-12 01:45:21 +01:00
parent 4bb88bc3f9
commit 30d6ba9dc2

148
atom
View File

@ -893,6 +893,38 @@ getTags() {
fi fi
} }
decodeSox() {
if (( ${destinationnormalize["$destination"]} ))
then
soxoptions_in+=" --norm"
fi
if [ -n "${destinationfrequency["$destination"]}" ] \
&& (( ${rate:-0} != ${destinationfrequency["$destination"]} ))
then
soxoptions_out+=" -r ${destinationfrequency["$destination"]}"
fi
if [ -n "${destinationchannels["$destination"]}" ] \
&& (( ${channels:-0} != ${destinationchannels["$destination"]} ))
then
soxoptions_out+=" -c ${destinationchannels["$destination"]}"
fi
tmpfile="$fileid${soxoptions_in// /}${soxoptions_out// /}"
soxoptions_in+=' --single-threaded'
soxoptions_out+=" --temp \"$tempdir\""
if [ -n "$1" ]
then
origin="$1"
else
origin="$sourcepath/$filename"
fi
commandline="sox $soxoptions_in \"$origin\" $soxoptions_out \"$tempdir/$tmpfile.wav\""
}
decodeMpcdec() {
tmpfile="${fileid}mpcdec"
commandline="mpcdec \"$sourcepath/$filename\" \"$tempdir/$tmpfile.wav\""
}
encodeFile::MP3() { encodeFile::MP3() {
#lame #lame
: :
@ -1131,37 +1163,44 @@ echo '
CREATE INDEX tasks_by_key ON tasks ( key );' >&3 CREATE INDEX tasks_by_key ON tasks ( key );' >&3
echo ' echo '
SELECT COUNT(DISTINCT source_files.id) SELECT COUNT(source_files.id)
FROM source_files, FROM source_files
destinations, INNER JOIN destination_files
destination_files, ON source_files.id
mime_type_actions = destination_files.source_file_id
WHERE destination_files.last_change < source_files.last_change INNER JOIN destinations
AND destinations.id = destination_files.destination_id ON destination_files.destination_id=destinations.id
INNER JOIN mime_type_actions
ON mime_type_actions.id = source_files.mime_type
INNER JOIN tags
ON source_files.id = tags.source_file
WHERE CAST(destination_files.last_change AS TEXT)
<> CAST(source_files.last_change AS TEXT)
AND mime_type_actions.destination_id = destinations.id AND mime_type_actions.destination_id = destinations.id
AND mime_type_actions.id = source_files.mime_type
AND source_files.id = destination_files.source_file_id
AND mime_type_actions.action = 1;' >&3 AND mime_type_actions.action = 1;' >&3
read -u4 filecount read -u4 filecount
echo ' echo '
SELECT SELECT
source_files.id, source_files.id,
source_files.filename, source_files.filename,
mime_type_actions.mime_text,
destinations.name, destinations.name,
destination_files.id, destination_files.id,
tags.rate, tags.rate,
tags.channels tags.channels
FROM source_files, FROM source_files
destinations, INNER JOIN destination_files
destination_files, ON source_files.id
tags, = destination_files.source_file_id
mime_type_actions INNER JOIN destinations
WHERE destination_files.last_change < source_files.last_change ON destination_files.destination_id=destinations.id
AND destinations.id = destination_files.destination_id INNER JOIN mime_type_actions
ON mime_type_actions.id = source_files.mime_type
INNER JOIN tags
ON source_files.id = tags.source_file
WHERE CAST(destination_files.last_change AS TEXT)
<> CAST(source_files.last_change AS TEXT)
AND mime_type_actions.destination_id = destinations.id AND mime_type_actions.destination_id = destinations.id
AND mime_type_actions.id = source_files.mime_type
AND source_files.id = destination_files.source_file_id
AND tags.source_file = source_files.id
AND mime_type_actions.action = 1; AND mime_type_actions.action = 1;
SELECT "AtOM:NoMoreFiles";' >&3 SELECT "AtOM:NoMoreFiles";' >&3
@ -1172,6 +1211,7 @@ do
read -u4 line read -u4 line
done done
echo -n 'Creating tasks... ' echo -n 'Creating tasks... '
echo 'BEGIN TRANSACTION;' >&3 echo 'BEGIN TRANSACTION;' >&3
for line in "${decodefiles[@]}" for line in "${decodefiles[@]}"
do do
@ -1179,6 +1219,8 @@ do
rest=${line#*|} rest=${line#*|}
filename=${rest%%|*} filename=${rest%%|*}
rest=${rest#*|} rest=${rest#*|}
mimetype=${rest%%|*}
rest=${rest#*|}
destination=${rest%%|*} destination=${rest%%|*}
rest=${rest#*|} rest=${rest#*|}
destfileid=${rest%%|*} destfileid=${rest%%|*}
@ -1186,32 +1228,38 @@ do
rate=${rest%%|*} rate=${rest%%|*}
rest=${rest#*|} rest=${rest#*|}
channels=${rest%%|*} channels=${rest%%|*}
unset garbage unset rest
if (( ${destinationnormalize["$destination"]} )) case "$mime_text" in
then 'audio/mpeg')
soxoptions_in+=" --norm" decodeSox
fi ;;
if [ -n "${destinationfrequency["$destination"]}" ] \ 'application/ogg')
&& (( ${rate:-0} != ${destinationfrequency["$destination"]} )) decodeSox
then ;;
soxoptions_out+=" -r ${destinationfrequency["$destination"]}" 'audio/x-flac')
fi decodeSox
if [ -n "${destinationchannels["$destination"]}" ] \ ;;
&& (( ${channels:-0} != ${destinationchannels["$destination"]} )) *)
then extendedtype=$(file -b "$sourcepath/$filename")
soxoptions_out+=" -c ${destinationchannels["$destination"]}" case "$extendedtype" in
fi *'Musepack '*)
tmpfile="$fileid${soxoptions_in// /}${soxoptions_out// /}" decodeMpcdec
sox_needed=1
;;
*)
decodeSox
;;
esac
;;
esac
if ! decodetaskid=$( if ! decodetaskid=$(
Select tasks id <<<"key = $tmpfile" Select tasks id <<<"key = $tmpfile"
) )
then then
soxoptions_in+=' --single-threaded'
soxoptions_out+=" --temp \"$tempdir\""
decodetaskid=$( decodetaskid=$(
Insert tasks <<-EOInsert Insert tasks <<-EOInsert
key $tmpfile key $tmpfile
command_line sox $soxoptions_in "$sourcepath/$filename" $soxoptions_out "$tempdir/$tmpfile.wav" command_line $commandline
status 0 status 0
EOInsert EOInsert
) )
@ -1223,6 +1271,30 @@ do
*) ;; *) ;;
esac esac
fi fi
if (( sox_needed ))
then
decodeSox "$tempdir/$tmpfile.wav"
if ! soxtaskid=$(
Select tasks id <<<"key = $tmpfile"
)
then
soxtaskid=$(
Insert tasks <<-EOInsert
key $tmpfile
command_line $commandline
requires $decodetaskid
status 0
EOInsert
)
case $(( ++count % 40 )) in
0) echo -ne '\b|' ;;
10) echo -ne '\b/' ;;
20) echo -en '\b-' ;;
30) echo -ne '\b\\' ;;
*) ;;
esac
fi
fi
unset \ unset \
channels \ channels \
decodetaskid \ decodetaskid \