diff --git a/toys/README b/toys/README index 9b7785b..d3d7af9 100644 --- a/toys/README +++ b/toys/README @@ -14,3 +14,24 @@ AtOM). Options: -r: remove unwanted files. + +missingtags +=========== +Checks for files which don't have the specified tags set. + +Options: + -A: Album artist + -l: Album + -a: Artist + -c: Composer + -d: Disc + -g: Genre + -p: Performer + -t: Title + -n: Track number + -N: Track total + -y: Year + + -u: Update database first + -D: Debug + diff --git a/toys/missingtags b/toys/missingtags new file mode 100755 index 0000000..4c6c6de --- /dev/null +++ b/toys/missingtags @@ -0,0 +1,186 @@ +#!/bin/bash + +# config structures +declare -A \ + destinationchannels \ + destinationfat32compat \ + destinationcopymime \ + destinationformat \ + destinationfrequency \ + destinationid \ + destinationloss \ + destinationmaxbps \ + destinationnormalize \ + destinationpath \ + destinationquality \ + destinationrename \ + destinationnoresample \ + destinationrenamepath \ + destinationskipmime \ + checks \ +|| { + 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 'AlacdgptnNyuD' opt +do + case $opt in + A) checks[albumartist]=1 ;; + l) checks[album]=1 ;; + a) checks[artist]=1 ;; + c) checks[composer]=1 ;; + d) checks[disc]=1 ;; + g) checks[genre]=1 ;; + p) checks[performer]=1 ;; + t) checks[title]=1 ;; + n) checks[track]=1 ;; + N) checks[tracktotal]=1 ;; + y) checks[year]=1 ;; + + u) update=1 ;; + D) (( debug++ )) ;; + esac +done + +(( ${#checks[@]} )) || { + cat >&2 <<-EOHelp + No check specified! + -A Album artist + -l Album + -a Artist + -c Composer + -d Disc + -g Genre + -p Performer + -t Title + -n Track number + -N Track total + -y Year + + Other options: + -u Update database first + -D Debug + EOHelp + exit 1 +} + +getConfig + +openDatabase + +if (( update )) +then + getFiles + updateMimes +fi + +for check in ${!checks[@]} +do + case $check in + albumartist) + cat >&2 <<-EONotice + Album artist is not supported for ID3. Files in this format will be ignored by + this check (other checks still apply). + EONotice + mimemp3=$( + Select mime_types id <<<"mime_text = audio/mpeg" + ) + whereclause+="${whereclause+ OR }(" + whereclause+='tags.albumartist IS NULL ' + whereclause+="AND NOT tags.tagreader LIKE \"ID3-%\"" + whereclause+=')' + ;; + tracktotal) + whereclause+="${whereclause+ OR }NOT tags.track LIKE \"%/%\"" + ;; + *) + whereclause+="${whereclause+ OR }tags.$check IS NULL" + ;; + esac + whereclause+=' +' +done + +cat >&3 <<-EOSelect + SELECT source_files.filename, + tags.genre, + tags.albumartist, + tags.year, + tags.album, + tags.disc, + tags.artist, + tags.track, + tags.title, + tags.composer, + tags.performer + FROM tags + INNER JOIN source_files + ON tags.source_file=source_files.id + WHERE $whereclause + AND NOT tags.tagreader LIKE "unknown-%"; + + SELECT "AtOM:NoMoreFiles"; +EOSelect + +read -u4 line +until [[ $line == AtOM:NoMoreFiles ]] +do + lines+=( "$line" ) + read -u4 line +done + +for line in "${lines[@]}" +do + missing=() + filename=${line%%|*} + rest="${line#*|}|" + (( ${checks[genre]} )) && [ -z "${rest%%|*}" ] && missing+=( "Genre" ) + rest=${rest#*|} + (( ${checks[albumartist]} )) && [ -z "${rest%%|*}" ] && missing+=( "AlbumArtist" ) + rest=${rest#*|} + (( ${checks[year]} )) && [ -z "${rest%%|*}" ] && missing+=( "Year" ) + rest=${rest#*|} + (( ${checks[album]} )) && [ -z "${rest%%|*}" ] && missing+=( "Album" ) + rest=${rest#*|} + (( ${checks[disc]} )) && [ -z "${rest%%|*}" ] && missing+=( "Disc" ) + rest=${rest#*|} + (( ${checks[artist]} )) && [ -z "${rest%%|*}" ] && missing+=( "Artist" ) + rest=${rest#*|} + track=${rest%%|*} + (( ${checks[track]} )) && [ -z "$track" ] && missing+=( "Track" ) + if (( ${checks[tracktotal]} )) && ! [[ $track =~ / ]] + then + missing+=( TrackTotal ) + fi + rest=${rest#*|} + (( ${checks[title]} )) && [ -z "${rest%%|*}" ] && missing+=( "Title" ) + rest=${rest#*|} + (( ${checks[composer]} )) && [ -z "${rest%%|*}" ] && missing+=( "Composer" ) + rest=${rest#*|} + (( ${checks[performer]} )) && [ -z "${rest%%|*}" ] && missing+=( "Performer" ) + rest=${rest#*|} + echo "$filename: ${missing[@]}" +done + +closeDatabase