diff --git a/atom b/atom index 3658747..c42d154 100755 --- a/atom +++ b/atom @@ -232,6 +232,16 @@ getConfigDestination() { 'copy_mime-type') destinationcopymime[$destination]="${destinationcopymime[$destination]:+${destinationcopymime[$destination]}|}$value" ;; + 'higher-than') + expr='^[0-9]*$' + if ! [[ $value =~ $expr ]] + then + echo "Invalid higher-than bitrate value: $value" >&2 + exit $EMAXBPS + fi + unset expr + destinationmaxbps[$destination]="$value" + ;; esac } getConfig() { @@ -913,6 +923,25 @@ getTags() { fi } +checkCopy() { + ( + [ -z "${destinationfrequency[$destination]}" ] \ + || (( ${rate:-0} == ${destinationfrequency[$destination]} )) + ) && ( + [ -z "${destinationchannels[$destination]}" ] \ + || (( ${channels:-0} == ${destinationchannels[$destination]} )) + ) && ( + (( ${bitrate:-1000} == ${destinationquality[$destination]} )) \ + || ( + [ -n "${destinationmaxbps[$destination]}" ] \ + || (( + ${bitrate:-1000} + <= ${destinationmaxbps[$destination]:-0} + )) + ) + ) +} + decodeSox() { if (( ${destinationnormalize["$destination"]} )) then @@ -950,6 +979,24 @@ encodeFile::MP3() { : } +copyFile() { + tmpfile="${fileid}copy$destination" + extension="${filename##*.}" + commandline="cp -al \"$sourcepath/$filename\" \"$destdir/$destfile.$extension\"" + commandline+=" 2>/dev/null" + commandline+=' || ' + commandline+="cp -a \"$sourcepath/$filename\" \"$destdir/$destfile\"" + copytaskid=$( + Insert tasks <<-EOInsert + key ${fileid}copy$destination + source_file $fileid + command_line $commandline + status 0 + EOInsert + ) + progressSpin +} + encodeFile::Ogg() { #oggenc : @@ -1286,10 +1333,22 @@ do unset rest case "$mimetype" in 'audio/mpeg') - decodeSox + if [[ ${destinationformat[$destination]} = mp3 ]] \ + && checkCopy + then + copied=1 + else + decodeSox + fi ;; 'application/ogg') - decodeSox + if [[ ${destinationformat[$destination]} = vorbis ]] \ + && checkCopy + then + copied=1 + else + decodeSox + fi ;; 'audio/x-flac') decodeSox diff --git a/doc/config b/doc/config index 5e535f0..0e650b7 100644 --- a/doc/config +++ b/doc/config @@ -77,6 +77,12 @@ Sections: * frequency : Files will be resampled as needed to Hz sampling-rate. Shoutcast/Icecast streams require a constant sampling-rate. Telephony systems often require a sample rate of 8000Hz. + * higher-than : Integer. Only reencode files with bitrates higher + then kbps. This only applies if sample-rate, channel count and of + course format are equal. If unset, only files with bitrates equal to that + of the target will be copied (actually, hardlinking will be attempted + first). As Ogg Vorbis target quality is not defined by its bitrate, Ogg + Vorbis files will always be reencoded if unset. Ogg parameters: * quality : The quality parameter of oggenc. See man oggenc for diff --git a/doc/example.cfg b/doc/example.cfg index 7f7ebce..0958034 100644 --- a/doc/example.cfg +++ b/doc/example.cfg @@ -29,6 +29,7 @@ path /mnt/Musique-mp3.test format mp3 bitrate 96 normalize yes +higher-than 128 # rename file, path unchanged rename %{track}--%{artist}-%{title} @@ -39,6 +40,7 @@ skip_mime-type text/* [asterisk] path /mnt/Musique-asterisk +quality 0 format vorbis normalize yes channels 1