From 30d6ba9dc284ad923b1cb67cdd3cf785620d6825 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 12 Mar 2013 01:45:21 +0100 Subject: [PATCH] create decoding tasks for Musepack files --- atom | 152 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 112 insertions(+), 40 deletions(-) diff --git a/atom b/atom index 2f0ad8e..9117ac0 100755 --- a/atom +++ b/atom @@ -874,7 +874,7 @@ getTags() { *' ID3 '*) type=MP3 ;; - *' Musepack '*) + *'Musepack '*) getRateChannelMPC tryAPE ;; @@ -893,6 +893,38 @@ getTags() { 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() { #lame : @@ -1131,37 +1163,44 @@ echo ' CREATE INDEX tasks_by_key ON tasks ( key );' >&3 echo ' - SELECT COUNT(DISTINCT source_files.id) - FROM source_files, - destinations, - destination_files, - mime_type_actions - WHERE destination_files.last_change < source_files.last_change - AND destinations.id = destination_files.destination_id + SELECT COUNT(source_files.id) + FROM source_files + INNER JOIN destination_files + ON source_files.id + = destination_files.source_file_id + INNER JOIN destinations + 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.id = source_files.mime_type - AND source_files.id = destination_files.source_file_id AND mime_type_actions.action = 1;' >&3 read -u4 filecount echo ' SELECT source_files.id, source_files.filename, + mime_type_actions.mime_text, destinations.name, destination_files.id, tags.rate, tags.channels - FROM source_files, - destinations, - destination_files, - tags, - mime_type_actions - WHERE destination_files.last_change < source_files.last_change - AND destinations.id = destination_files.destination_id + FROM source_files + INNER JOIN destination_files + ON source_files.id + = destination_files.source_file_id + INNER JOIN destinations + 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.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; SELECT "AtOM:NoMoreFiles";' >&3 @@ -1171,7 +1210,8 @@ do decodefiles+=("$line") read -u4 line done -echo -n 'Creating tasks... ' +echo -n 'Creating tasks... ' + echo 'BEGIN TRANSACTION;' >&3 for line in "${decodefiles[@]}" do @@ -1179,6 +1219,8 @@ do rest=${line#*|} filename=${rest%%|*} rest=${rest#*|} + mimetype=${rest%%|*} + rest=${rest#*|} destination=${rest%%|*} rest=${rest#*|} destfileid=${rest%%|*} @@ -1186,32 +1228,38 @@ do rate=${rest%%|*} rest=${rest#*|} channels=${rest%%|*} - unset garbage - 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// /}" + unset rest + case "$mime_text" in + 'audio/mpeg') + decodeSox + ;; + 'application/ogg') + decodeSox + ;; + 'audio/x-flac') + decodeSox + ;; + *) + extendedtype=$(file -b "$sourcepath/$filename") + case "$extendedtype" in + *'Musepack '*) + decodeMpcdec + sox_needed=1 + ;; + *) + decodeSox + ;; + esac + ;; + esac if ! decodetaskid=$( Select tasks id <<<"key = $tmpfile" ) then - soxoptions_in+=' --single-threaded' - soxoptions_out+=" --temp \"$tempdir\"" decodetaskid=$( Insert tasks <<-EOInsert key $tmpfile - command_line sox $soxoptions_in "$sourcepath/$filename" $soxoptions_out "$tempdir/$tmpfile.wav" + command_line $commandline status 0 EOInsert ) @@ -1223,6 +1271,30 @@ do *) ;; esac 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 \ channels \ decodetaskid \