diff --git a/atom b/atom old mode 100644 new mode 100755 index c84441f..554bb2f --- a/atom +++ b/atom @@ -1,7 +1,196 @@ #!/bin/bash +## Define exit codes +# General config errors [10-19] +ELOAD=10 +EINTERVAL=11 +# Source cofig errors [20-29] +# Destination config errors [30-49] +EFORMAT=30 +ECHANNEL=31 +EFMTINVPARM=49 + +# config structures +declare -A \ + destinationchannels \ + destinationcopymime \ + destinationformat \ + destinationfrequency \ + destinationpath \ + destinationquality \ + destinationrename \ + destinationrenamepath \ + destinationskipmime \ +|| { + echo "Check your Bash version. You need >= 4.0" >&2 + exit $EBASHVERS +} + #parse arguments #parse config +getConfigGeneral() { + case $key in + 'max-load') + expr='^[0-9]*$' + if [[ $value =~ $expr ]] + then + maxload="$value" + else + echo "Invalid max-load value: $value" >&2 + exit $ELOAD + fi + unset expr + ;; + 'load-interval') + expr='^[0-9]*$' + if [[ $value =~ $expr ]] + then + loadinterval="$value" + else + echo "Invalid load-interval value: $value" >&2 + exit $EINTERVAL + fi + unset expr + ;; + 'temporary-directory') + tempdir="$value" + ;; + debug) + #unimplemented + ;; + esac +} + +getConfigSource() { + case "$key" in + 'path') + sourcepath="$value" + ;; + 'id3charset') + sourceid3charset="$value" + ;; + esac +} + +getConfigDestination() { + case "$key" in + 'path') + destinationpath["$destination"]="$value" + ;; + 'format') + case "$value" in + 'mp3') + destinationformat["$destination"]=mp3 + ;; + 'vorbis') + destinationformat["$destination"]=vorbis + ;; + *) + echo "Unsupported destination format: $value" >2& + exit $EFORMAT + ;; + esac + ;; + 'quality') + expr='^[0-9]*$' + if ! [[ $value =~ $expr ]] + then + echo "Invalid quality value: $value" >&2 + exit $EQUALITY + fi + unset expr + case "${destinationformat["$destination"]}" in + 'vorbis') + destinationquality["$destination"]="$value" + ;; + *) + echo "$Invalid parameter \"$key\" for format \"${destinationformat["$destination"]}\"" >&2 + exit $EFMTINVPARM + ;; + esac + ;; + 'bitrate') + expr='^[0-9]*$' + if ! [[ $value =~ $expr ]] + then + echo "Invalid bitrate value: $value" >&2 + exit $EQUALITY + fi + unset expr + case "${destinationformat["$destination"]}" in + 'mp3') + destinationquality["$destination"]="$value" + ;; + *) + echo "$Invalid parameter \"$key\" for format \"${destinationformat["$destination"]}\"" >&2 + exit $EFMTINVPARM + ;; + esac + ;; + 'channels') + expr='^[0-9]*$' + if ! [[ $value =~ $expr ]] + then + echo "Invalid channel count: $value" >&2 + exit $ECHANNEL + fi + unset expr + destinationchannels["$destination"]=$value + ;; + 'frequency') + expr='^[0-9]*$' + if ! [[ $value =~ $expr ]] + then + echo "Invalid frequency value: $value" >&2 + exit $ECHANNEL + fi + unset expr + destinationfrequency["$destination"]=$value + ;; + 'rename') + case "$value" in + */*) + destinationrenamepath["$destination"]="${value%/*}" + ;; + esac + destinationrename["$destination"]="${value##*/}" + ;; + 'skip_mime-type') + destinationskipmime[$destination]="${destinationskipmime[$destination]:+${destinationskipmime[$destination]}|}$value" + ;; + 'copy_mime-type') + destinationcopymime[$destination]="${destinationcopymime[$destination]:+${destinationcopymime[$destination]}|}$value" + ;; + esac +} +getConfig() { + while read key value + do + case $key in + '#'*) + #comment + ;; + '') + #empty line + ;; + '[general]') + context=General + ;; + '[source]') + context=Source + ;; + \[*\]) + context=Destination + destination="${key#[}" + destination="${destination%]}" + ;; + *) + getConfig$context + ;; + esac + done < ~/.atom/atom.cfg +} + #check sanity getFiles() { @@ -89,5 +278,33 @@ transcodeLauncher() { } #UI +getConfig +{ +cat <