From 0176483217ad8ab18232f31dfd51d19d28d801d2 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Mon, 17 Jun 2013 13:41:25 +0200 Subject: [PATCH] [destination] setup (mandatory parameters) --- lib/setup/setupDestination | 227 ++++++++++++++++++++++++++++++++++++ lib/setup/setupDestinations | 80 +++++++++++++ 2 files changed, 307 insertions(+) create mode 100644 lib/setup/setupDestination create mode 100644 lib/setup/setupDestinations diff --git a/lib/setup/setupDestination b/lib/setup/setupDestination new file mode 100644 index 0000000..8c6b994 --- /dev/null +++ b/lib/setup/setupDestination @@ -0,0 +1,227 @@ +#!/bin/bash + +setupDestination() { + cat <<-EODesc + + Format: + vorbis, opus or mp3. Other formats may appear in the future. + EODesc + comeagain() { + read \ + -e \ + ${destinationformat["$destination"]+-i"${destinationformat["$destination"]}"}\ + -p 'Format: ' \ + value + case "$value" in + 'mp3') + destinationformat["$destination"]=mp3 + lameneeded=1 + ;; + 'opus') + destinationformat["$destination"]=opus + opusencneeded=1 + ;; + 'vorbis'|'ogg') + destinationformat["$destination"]=vorbis + oggencneeded=1 + ;; + *) + echo "Unsupported destination format: $value" >&2 + comeagain + ;; + esac + } + comeagain + cat <<-EODesc + + Path (path): + Where to store transcoded files (will be created if it does not + exist). + EODesc + read \ + -e \ + -p'Path: ' \ + ${destinationpath["$destination"]+-i"${destinationpath["$destination"]}"}\ + destinationpath["$destination"] + case ${destinationformat["$destination"]} in + vorbis) + cat <<-EODesc + + Quality (integer): + The quality parameter of oggenc. See man oggenc for more info. + EODesc + expr='^[0-9]*$' + comeagain() { + read \ + -p'Quality: ' \ + -e \ + -i \ + ${destinationquality["$destination"]:-3}\ + value + if ! [[ $value =~ $expr ]] + then + echo "Invalid quality value: $value" >&2 + comeagain + fi + } + comeagain + destinationquality["$destination"]=$value + ;; + opus) + cat <<-EODesc + + Bitrate (kbps, integer): + 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. + EODesc + expr='^[0-9]*$' + comeagain() { + read \ + -e \ + -i \ + ${destinationquality["$destination"]:-128}\ + -p 'Bitrate: ' + value + if ! [[ $value =~ $expr ]] + then + echo "Invalid bitrate value: $value" >&2 + comeagain + fi + } + comeagain + destinationquality["$destination"]=$value + cat <<-EODesc + + Loss (percent, integer): + 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. + EODesc + comeagain() { + read \ + -e \ + -i \ + ${destinationloss["$destination"]:-0}\ + value + if ! [[ $value =~ $expr ]] + then + echo "Invalid loss value: $value" >&2 + comeagain + fi + } + comeagain + destinationloss["$destination"]=$value + ;; + mp3) + cat <<-EODesc + + Bitrate (kbps, integer): + Set (ABR) bitrate to . + EODesc + expr='^[0-9]*$' + comeagain() { + read \ + -e \ + -i \ + ${destinationquality["$destination"]:-128}\ + value + if ! [[ $value =~ $expr ]] + then + echo "Invalid bitrate value: $value" >&2 + comeagain + fi + } + comeagain + destinationquality["$destination"]=$value + cat <<-EODesc + + Prevent resampling (boolean): + 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. + EODesc + case ${destinationnoresample["$destination"]} in + 0) initialvalue=n ;; + 1) initialvalue=y ;; + *) unset initialvalue ;; + esac + comeagain() { + read \ + -e \ + ${initialvalue+-i $initialvalue}\ + -p'Prevent resampling (y/N): ' \ + value + case $value in + [yY]) + destinationnoresample["$destination"]=1 + ;; + ''|[nN]) + destinationnoresample["$destination"]=0 + ;; + *) + comeagain + ;; + esac + } + comeagain + ;; + esac + cat <<-EODesc + + [Optional parameters] + Now you will have the opportunity to configure "advanced" parameters + for $destination. You may leave any of these fields blank. + EODesc + cat <<-EODesc + + Normalize (boolean): + Normalize output files. + EODesc + comeagain() { + : + } + comeagain + cat <<-EODesc + EODesc + comeagain() { + : + } + comeagain + cat <<-EODesc + EODesc + comeagain() { + : + } + comeagain + cat <<-EODesc + EODesc + comeagain() { + : + } + comeagain + cat <<-EODesc + EODesc + comeagain() { + : + } + comeagain + cat <<-EODesc + EODesc + comeagain() { + : + } + comeagain + cat <<-EODesc + EODesc + comeagain() { + : + } + comeagain + cat <<-EODesc + EODesc + comeagain() { + : + } + comeagain +} diff --git a/lib/setup/setupDestinations b/lib/setup/setupDestinations new file mode 100644 index 0000000..305852b --- /dev/null +++ b/lib/setup/setupDestinations @@ -0,0 +1,80 @@ +#!/bin/bash + +setupDestinations() { + cat <<-EODesc + + +[Destinations] + Finally, we'll setup your destination(s). + EODesc + if (( ${#destinations[@]} )) + then + cat <<-EODesc + + [Existing destinations] + We will review your currently configured destinations. Clear the 'Name' + field to remove one. + EODesc + for destination in "${destinations[@]}" + do + cat <<-EODesc + + Name (string): + A simple name for this destination. Clear to remove this destination. + EODesc + expr='^[A-z0-9]*$' + comeagain() { + read -p'Name: ' -e -i"$destination" value + if [ -z "$value" ] + then + read \ + -p"Really remove destination $destination? [y/N]" + if [[ $REPLY == y ]] + then + removeDestination "$destination" + continue + else + value="$destination" + fi + elif ! [[ $value =~ $expr ]] + then + echo "Invalid name $value." \ + 'Please use only' \ + 'alphanumeric characters.' >&2 + comeagain + fi + } + comeagain + destination="$value" + setupDestination + done + fi + cat <<-EODesc + + [New destinations] + This section will loop until you enter an empty 'Name'. + EODesc + for (( i=0 ; 1 ; i++ )) + do + cat <<-EODesc + + Name (string): + A simple name for this destination. Empty string to end this + configuration loop. + EODesc + expr='^[A-z0-9]*$' + comeagain() { + read -p'Name: ' value + [ -z "$value" ] && break + if ! [[ $value =~ $expr ]] + then + echo "Invalid name $value. Please use" \ + 'only alphanumeric characters.' >&2 + comeagain + fi + } + comeagain + destination="$value" + setupDestination + done +}