From 2d345047f75475f4d29a62fe0f1cb5dec20eef46 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 28 May 2013 13:38:00 +0200 Subject: [PATCH 1/2] toys/lowquality Get file names by format and quality constraints --- toys/lowquality | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100755 toys/lowquality diff --git a/toys/lowquality b/toys/lowquality new file mode 100755 index 0000000..0e73163 --- /dev/null +++ b/toys/lowquality @@ -0,0 +1,130 @@ +#!/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" + +cffile="$HOME/.atom/atom.cfg" +LC_ALL=C + +shopt -s extglob + +for function in "$LIBDIR"/*/* +do + source "$function" +done + +while getopts 'fm:o:p:*:uD' opt +do + case $opt in + f) mimetypes+=("audio/x-flac") + bitrates+=("") + ;; + m) mimetypes+=("audio/mpeg") + bitrates+=("$OPTARG") + ;; + o) mimetypes+=("application/ogg vorbis") + bitrates+=("$OPTARG") + ;; + p) mimetypes+=("application/ogg opus") + bitrates+=("$OPTARG") + ;; + \*) mimetypes+=("*") + bitrates+=("$OPTARG") + ;; + + u) update=1 ;; + D) (( debug++ )) ;; + esac +done + +getConfig + +openDatabase + +if (( update )) +then + getFiles + updateMimes + updateTags +fi + +echo ' + SELECT + mime_type_actions.mime_text, + tags.bitrate, + source_files.filename + FROM source_files + INNER JOIN tags + ON source_files.id=tags.source_file + INNER JOIN mime_type_actions + ON mime_type_actions.id=source_files.mime_type + WHERE mime_type_actions.action=1 + AND ( +' >&3 + +for indice in ${!mimetypes[@]} +do + (( notfirst )) && echo OR >&3 + case ${mimetypes[indice]} in + 'audio/x-flac') + echo 'mime_type_actions.mime_text="audio/x-flac"'>&3 + ;; + '*') + echo '( ( + NOT mime_type_actions.mime_text="audio/x-flac" + AND NOT mime_type_actions.mime_text="audio/mpeg" + AND NOT + mime_type_actions.mime_text="application/ogg vorbis" + AND NOT + mime_type_actions.mime_text="application/ogg opus" + ) AND tags.bitrate < '${bitrates[indice]}' )' >&3 + ;; + *) + echo '( + mime_type_actions.mime_text="'"${mimetypes[indice]}"'" + AND tags.bitrate < '${bitrates[indice]}' )' >&3 + ;; + esac + notfirst=1 +done +echo ') ORDER BY bitrate;' >&3 + +echo 'SELECT "AtOM:NoMoreFiles";' >&3 + +read -u4 line +until [[ $line == AtOM:NoMoreFiles ]] +do + echo "${line//::AtOM:SQL:Sep::/$'\t'}" + read -u4 line +done + +closeDatabase From d3fdf154c1a98f150ce0e398b1e257f1a8621fd1 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 28 May 2013 13:49:52 +0200 Subject: [PATCH 2/2] DISTINCT --- toys/lowquality | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toys/lowquality b/toys/lowquality index 0e73163..0e3395b 100755 --- a/toys/lowquality +++ b/toys/lowquality @@ -78,7 +78,7 @@ then fi echo ' - SELECT + SELECT DISTINCT mime_type_actions.mime_text, tags.bitrate, source_files.filename