parse & dump config
(features exposed there may or may not be implemented)
This commit is contained in:
parent
2911ee43d4
commit
c2be5814fa
219
atom
Normal file → Executable file
219
atom
Normal file → Executable file
@ -1,7 +1,196 @@
|
|||||||
#!/bin/bash
|
#!/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 arguments
|
||||||
#parse config
|
#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
|
#check sanity
|
||||||
|
|
||||||
getFiles() {
|
getFiles() {
|
||||||
@ -89,5 +278,33 @@ transcodeLauncher() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#UI
|
#UI
|
||||||
|
getConfig
|
||||||
|
{
|
||||||
|
cat <<EOF
|
||||||
|
General|Load|$maxload
|
||||||
|
|Load Interval|$loadinterval
|
||||||
|
|Temp Dir|$tempdir
|
||||||
|
|Database|$database
|
||||||
|
|Debug|$debug
|
||||||
|
Source|Path|$sourcepath
|
||||||
|
|ID3 Charset|$sourceid3charset
|
||||||
|
EOF
|
||||||
|
for destination in ${!destinationpath[@]}
|
||||||
|
do
|
||||||
|
cat <<EOF
|
||||||
|
$destination|Path|${destinationpath[$destination]}
|
||||||
|
|Format|${destinationformat[$destination]}
|
||||||
|
|Quality|${destinationquality[$destination]}
|
||||||
|
|Channels|${destinationchannels[$destination]}
|
||||||
|
|Frequency|${destinationfrequency[$destination]}
|
||||||
|
|Path Change|${destinationrenamepath[$destination]}
|
||||||
|
|File Rename|${destinationrename[$destination]}
|
||||||
|
EOF
|
||||||
|
echo "|Skipped mime-type|${destinationskipmime[$destination]//\|/
|
||||||
|
|Skipped mime-type|}"
|
||||||
|
echo "|Copied mime-type|${destinationcopymime[$destination]//\|/
|
||||||
|
|Copied mime-type|}"
|
||||||
|
done
|
||||||
|
}|column -t -s'|' -n
|
||||||
|
|
||||||
# vim:set ts=8,sw=8:
|
# vim:set ts=8 sw=8:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user