AtOM/lib/setup/setupDestination
2013-06-19 02:33:21 +02:00

355 lines
8.2 KiB
Bash

#!/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 <bitrate>. 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}\
-p 'Loss: ' \
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 <bitrate>.
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
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
<original file's rate>, 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
case ${destinationnormalize["$destination"]} in
0) initialvalue=n ;;
1) initialvalue=y ;;
*) unset initialvalue ;;
esac
comeagain() {
read \
-e \
${initialvalue+-i $initialvalue}\
-p'Normalize (y/N): ' \
value
case $value in
[yY])
destinationnormalize["$destination"]=1
;;
''|[nN])
destinationnormalize["$destination"]=0
;;
*)
comeagain
;;
esac
}
comeagain
cat <<-EODesc
Rename (string):
Destination files will be named according to <string>, after
expansion of special strings:
%{album},
%{albumartist},
%{artist},
%{disc},
%{genre},
%{title},
%{track},
%{year}.
Untagged files or files in unrecognized formats will not be changed.
Leave blank if you don't want file renaming.
EODesc
initialvalue="${destinationrenamepath["$destination"]}"
initialvalue+="${initialvalue+/}"
initialvalue+="${destinationrename["$destination"]}"
read \
-e \
${initialvalue+-i"$initialvalue"} \
-p'Rename pattern: ' \
value
case "$value" in
*/*)
destinationrenamepath["$destination"]="${value%/*}"
;;
esac
destinationrename["$destination"]="${value##*/}"
cat <<-EODesc
FAT32 Compatibility (boolean):
Rename files for compatibility with FAT32 filesystems.
EODesc
case ${destinationfat32compat["$destination"]} in
0) initialvalue=n ;;
1) initialvalue=y ;;
*) unset initialvalue ;;
esac
comeagain() {
read \
-e \
${initialvalue+-i $initialvalue}\
-p'FAT32 Compatibility (y/N): ' \
value
case $value in
[yY])
destinationfat32compat["$destination"]=1
;;
''|[nN])
destinationfat32compat["$destination"]=0
;;
*)
comeagain
;;
esac
}
comeagain
cat <<-EODesc
Skip mime-type (mime-type, string):
Files with mime-type <mime-type> will not be included in that
destination. The '*' character is a wildcard.
This prompt will loop until an empty string is encountered.
EODesc
destinationskipmime["$destination"]="${destinationskipmime["$destination"]}|"
while [[ ${destinationskipmime["$destination"]} =~ / ]]
do
skippedmimes+=("${destinationskipmime["$destination"]%%|*}")
destinationskipmime["$destination"]="${destinationskipmime["$destination"]#*|}"
done
count=${#skippedmimes[@]}
unset destinationskipmime["$destination"]
for (( i=0 ; 1 ; i++ ))
do
read \
-e \
${skippedmimes[i]+-i"${skippedmimes[i]}"} \
-p 'Skip mime-type: ' \
value
if [ -n "$value" ]
then
destinationskipmime[$destination]="${destinationskipmime[$destination]:+${destinationskipmime[$destination]}|}$value"
elif (( i < count ))
then
continue
else
break
fi
done
unset skippedmimes
cat <<-EODesc
Copy mime-type (mime-type, string):
Files with mime-type <mime-type> will be copied as-is to the
destination. E.g. image/* will copy covers and other images to the
destination. The '*' character is a wildcard.
This prompt will loop until an empty string is encountered.
EODesc
destinationcopymime["$destination"]="${destinationcopymime["$destination"]}|"
while [[ ${destinationcopymime["$destination"]} =~ / ]]
do
copiedmimes+=("${destinationcopymime["$destination"]%%|*}")
destinationcopymime["$destination"]="${destinationcopymime["$destination"]#*|}"
done
count=${#copiedmimes[@]}
unset destinationcopymime["$destination"]
for (( i=0 ; 1 ; i++ ))
do
read \
-e \
${copiedmimes[i]+-i"${copiedmimes[i]}"} \
-p 'Copy mime-type: ' \
value
if [ -n "$value" ]
then
destinationcopymime[$destination]="${destinationcopymime[$destination]:+${destinationcopymime[$destination]}|}$value"
elif (( i < count ))
then
continue
else
break
fi
done
unset copiedmimes
cat <<-EODesc
EODesc
comeagain() {
:
}
comeagain
cat <<-EODesc
EODesc
comeagain() {
:
}
comeagain
cat <<-EODesc
EODesc
comeagain() {
:
}
comeagain
}