From daac6e00e560452f2d4ee3f3218e3d7b65478ea8 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Fri, 21 Jun 2013 02:32:39 +0200 Subject: [PATCH] writeConfig() --- lib/config/write | 237 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 lib/config/write diff --git a/lib/config/write b/lib/config/write new file mode 100644 index 0000000..f376731 --- /dev/null +++ b/lib/config/write @@ -0,0 +1,237 @@ +#!/bin/bash + +writeConfig() { + cat <<-EOCfg +[general] +# This section contains parameters of the program itself. + +# * max-load : Integer. Defines how parallel processing will behave. AtOM +# will try to keep the 1 minute load average between and +1 by +# adjusting concurrency. +# Initial concurrency will be set to half of that value. +max-load $maxload + +# * load-interval : Integer. How often should we check the load average +# and adjust concurrency. Set this too low, and concurrency may be increased +# too quickly. Set this too high, and AtOM will not adapt quickly enough to +# load increase. In both cases, your hard drive will suffer. In my +# experience, 30 seconds is a good value. +load-interval $loadinterval + +# * ionice [niceness]: IO-hungry processes will be run with ionice class +# and niceness [niceness] (if applicable). See man ionice for details. +ionice $class $niceness + +# * temporary-directory : String. Name speaks for itself: this is +# where FIFOs (for communicating with sqlite) and temporary WAVE files will +# be created. Note that debug logs (if enabled) will go there too. +temporary-directory $tempdir + +# * database : String. Where the SQLite database should be stored. +database $database + +# * debug : Integer. +#debug 1 + + +[source] +# This section defines where are the files you want transcoded. + +# * path : String. The root of your collection. +# Default: /var/lib/mpd/music +path $sourcepath + +# * skip : String. Files in will be ignored. Note that +# can be any expression accepted by find. + EOCfg + for dir in "${skippeddirectories[@]}" + do + echo $'skip\t\t\t'"$dir" + done + cat <<-EOCfg + + + EOCfg + for destination in "${!destinationpath[@]}" + do + cat <<-EOCfg +[$destination] +# Each section not named 'general' or 'source' will define a new destination. + +# Common parameters: +# Mandatory parameters: +# * path: Where files will be written +path ${destinationpath["$destination"]} + +# * format: ogg, opus or mp3. Other formats may appear in the future - feel +# free to implement your preferred format. +format ${destinationformat["$destination"]} + + EOCfg + case "${destinationformat[@]}" in + vorbis) + cat <<-EOCfg +# Ogg parameters: +# * quality : The quality parameter of oggenc. See man oggenc for +# more info. This is the only mode supported and planned. Still, if you want +# to be able to use bitrate settings, feel free to fork and file a pull +# request. +quality ${destinationquality["$destination"]} + + + EOCfg + ;; + opus) + cat <<-EOCfg +# Opus parameters: +# * bitrate : Set (VBR) bitrate to . Note that while Opus +# allows for decimal values, AtOM does not. The reason for this is simple: +# we do numeric comparisons, and Bash only manipulates integers. +bitrate ${destinationquality["$destination"]} + +# * loss : If you intend to stream the resulting files over an +# unreliable protocol, you may want to make use of Opus' Forward Error +# Correction algorythm. See the Opus-codec.org website for details. +# Default: 0 +loss ${destinationloss["$destination"]:-0} + + + EOCfg + ;; + mp3) + cat <<-EOCfg +# MP3 parameters: +# * bitrate : Set ABR to . Again, if you want CBR or any +# other mode supported by lame, please fork and file a pull request. +bitrate ${destinationquality["$destination"]} + +# * noresample /: LAME may decide to encode your file to a lower +# sampling-rate if you use a low bitrate. Setting this to yes will +# append --resample , preventing any resampling from +# happening. + EOCfg + if (( ${destinationnoresample["$destination"]} )) + then + echo $'noresample\t\tyes' + else + echo $'noresample\t\tno' + fi + cat <<-EOCfg + + + EOCfg + ;; + esac + cat <<-EOCfg +# Optional parameters: +# * normalize /: Normalize output files. + EOCfg + if (( ${destinationnormalize["$destination"]} )) + then + echo $'normalize\t\tyes' + else + echo $'normalize\t\tno' + fi + cat <<-EOCfg + +# * rename : Destination files will be named according to , +# after expansion of special strings: +# %{album}, +# %{albumartist}, +# %{artist}, +# %{disc}, +# %{genre}, +# %{title}, +# %{track}, +# %{year}. +# Untagged files or files in unrecognized formats will not be changed. + EOCfg + if [[ ${destinationrenamepath["$destination"]}/${destinationrename["$destination"]} == / ]] + then + echo $'#rename\t\t\t' + elif [[ ${destinationrenamepath["$destination"]}/${destinationrename["$destination"]} == /* ]] + then + echo $'rename\t\t\t'"${destinationrename["$destination"]}" + else + echo $'rename\t\t\t'"${destinationrenamepath["$destination"]}/${destinationrename["$destination"]}" + fi + cat <<-EOCfg + +# * fat32compat /: Rename files for compatibility with FAT32 +# filesystems. + EOCfg + if (( ${destinationfat32compat["$destination"]} )) + then + echo $'fat32compat\t\tyes' + else + echo $'fat32compat\t\tno' + fi + cat <<-EOCfg + +# * skip_mime-type : Files with mime-type will not +# be included in that destination. For more than one mime-type, use multiple +# times, as needed. The '*' character is a wildcard. + EOCfg + destinationskipmime["$destination"]="${destinationskipmime["$destination"]}|" + while [[ ${destinationskipmime["$destination"]} =~ \| ]] + do + echo $'skip_mime-type\t\t'"${destinationskipmime["$destination"]%%|*}" + destinationskipmime["$destination"]="${destinationskipmime["$destination"]#*|}" + done + cat <<-EOCfg + +# * copy_mime-type : Same as skip_mime-type, except that files +# matching will be copied as-is to the destination. E.g. image/* will copy +# covers and other images to the destination. In fact, AtOM will try to use +# hard links instead of copies. + EOCfg + destinationcopymime["$destination"]="${destinationcopymime["$destination"]}|" + while [[ ${destinationcopymime["$destination"]} =~ \| ]] + do + echo $'copy_mime-type\t\t'"${destinationcopymime["$destination"]%%|*}" + destinationcopymime["$destination"]="${destinationcopymime["$destination"]#*|}" + done + cat <<-EOCfg + +# * channels : Files with more than channels will be +# downmixed. Useful if you create files for telephony music-on-hold. + EOCfg + if (( ${destinationchannels["$destination"]} )) + then + echo $'channels\t\t'${destinationchannels["$destination"]} + else + echo $'#channels\t\t2' + fi + cat <<-EOCfg + +# * 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. + EOCfg + if (( ${destinationfrequency["$destination"]} )) + then + echo $'frequency\t\t'${destinationfrequency["$destination"]} + else + echo $'#frequency\t\t44100' + fi + cat <<-EOCfg + +# * 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. + EOCfg + if (( ${destinationmaxbps["$destination"]} )) + then + echo $'higher-than\t\t'${destinationmaxbps["$destination"]} + else + echo $'#higher-than\t\t128' + fi + cat <<-EOCfg + + + EOCfg + done +}