2021-03-01 04:31:39 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# ===Note for contributors========================================================================================================================
|
|
|
|
|
|
|
|
# This script interactively asks the user for the options to call AAXtoMP3 with. This first version does not include all options of AAXtoMP3
|
|
|
|
# since I tried to keep the dialog short, but I added an --advanced option, which is unused right now, but might be used in the future to add
|
|
|
|
# more options which only show up if explicitely wanted.
|
|
|
|
# If you want to add functionality please consider, whether the functionality you add might belong to the advanced options.
|
|
|
|
|
|
|
|
# ===Variables====================================================================================================================================
|
|
|
|
|
|
|
|
# Help mesaage
|
|
|
|
help=$'\nUsage: interactiveAAXtoMP3 [--advanced] [--help]\n
|
|
|
|
--advanced More options
|
|
|
|
--help Print this message\n'
|
2021-03-02 01:06:45 +01:00
|
|
|
summary="" # This will contain a summary of the options allready set.
|
2021-03-01 04:31:39 +01:00
|
|
|
call="./AAXtoMP3" # This will contain the call for AAXtoMP3.
|
2021-03-02 01:06:45 +01:00
|
|
|
advanced=0 # Toggles advanced options on or off.
|
2021-03-01 04:31:39 +01:00
|
|
|
|
|
|
|
# ===Options======================================================================================================================================
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
2021-03-02 01:06:45 +01:00
|
|
|
# Advanced options.
|
|
|
|
-a | --advanced ) advanced=1; shift ;;
|
|
|
|
# Command synopsis.
|
|
|
|
-h | --help ) echo -e "$help"; exit ;;
|
|
|
|
# Anything else stops command line processing.
|
|
|
|
* ) break ;;
|
2021-03-01 04:31:39 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-03-02 01:06:45 +01:00
|
|
|
# ===Cross platform compatible use grep and sed===================================================================================================
|
|
|
|
|
|
|
|
# ===Detect which annoying version of grep we have===
|
|
|
|
GREP=$(grep --version | grep -q GNU && echo "grep" || echo "ggrep")
|
|
|
|
if ! [[ $(type -P "$GREP") ]]; then
|
|
|
|
echo "$GREP (GNU grep) is not in your PATH"
|
|
|
|
echo "Without it, this script will break."
|
|
|
|
echo "On macOS, you may want to try: brew install grep"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ===Detect which annoying version of sed we have===
|
|
|
|
SED=$(sed --version 2>&1 | $GREP -q GNU && echo "sed" || echo "gsed")
|
|
|
|
if ! [[ $(type -P "$SED") ]]; then
|
|
|
|
echo "$SED (GNU sed) is not in your PATH"
|
|
|
|
echo "Without it, this script will break."
|
|
|
|
echo "On macOS, you may want to try: brew install gnu-sed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-03-01 04:31:39 +01:00
|
|
|
# ===Get options for AAXtoMP3=====================================================================================================================
|
|
|
|
|
|
|
|
# ===Codec===
|
|
|
|
while true; do
|
|
|
|
clear;
|
|
|
|
read -p "codec (mp3/m4a/m4b/flac/aac/opus): " codec
|
2021-03-02 01:06:45 +01:00
|
|
|
case "$codec" in
|
|
|
|
mp3 ) summary="$summary""codec: $codec"; call="$call -e:mp3"; break;;
|
|
|
|
m4a ) summary="$summary""codec: $codec"; call="$call -e:m4a"; break;;
|
|
|
|
m4b ) summary="$summary""codec: $codec"; call="$call -e:m4b"; break;;
|
|
|
|
flac ) summary="$summary""codec: $codec"; call="$call --flac"; break;;
|
|
|
|
aac ) summary="$summary""codec: $codec"; call="$call --aac"; break;;
|
|
|
|
opus ) summary="$summary""codec: $codec"; call="$call --opus"; break;;
|
|
|
|
esac
|
2021-03-01 04:31:39 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# ===Compression===
|
|
|
|
while true; do
|
2021-03-02 01:06:45 +01:00
|
|
|
clear; echo -e "$summary"
|
|
|
|
case "$codec" in
|
|
|
|
mp3 ) maxlevel=9;;
|
|
|
|
flac ) maxlevel=12;;
|
|
|
|
opus ) maxlevel=10;;
|
|
|
|
* ) break;;
|
|
|
|
esac
|
2021-03-01 04:31:39 +01:00
|
|
|
read -p "compression level (0-$maxlevel): " compression
|
2021-03-02 01:06:45 +01:00
|
|
|
if [[ $compression =~ ^[0-9]+$ ]] && [[ "$compression" -ge "0" ]] && [[ "$compression" -le "$maxlevel" ]]; then
|
|
|
|
summary="$summary""\ncompression level: $compression"
|
2021-03-01 04:31:39 +01:00
|
|
|
call="$call --level $compression"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# ===Chapters===
|
|
|
|
while true; do
|
2021-03-02 01:06:45 +01:00
|
|
|
clear; echo -e "$summary"
|
2021-03-01 04:31:39 +01:00
|
|
|
read -p "chapters (yes/no/chapternumber to continue with): " chapters
|
2021-03-02 01:06:45 +01:00
|
|
|
case "$chapters" in
|
|
|
|
^[0-9]+$ ) summary="$summary""\nchapters: $chapters"; call="$call -c --continue ${chapters}"; break;;
|
|
|
|
yes ) summary="$summary""\nchapters: $chapters"; call="$call -c"; break;;
|
|
|
|
no ) summary="$summary""\nchapters: $chapters"; call="$call -s"; break;;
|
|
|
|
esac
|
2021-03-01 04:31:39 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# ===Authcode===
|
|
|
|
if ! [ -r .authcode ] || [ -r ~/.authcode ]; then
|
2021-03-02 01:06:45 +01:00
|
|
|
clear; echo -e "$summary"
|
2021-03-01 04:31:39 +01:00
|
|
|
read -p "Authcode: " authcode
|
2021-03-02 01:06:45 +01:00
|
|
|
summary="$summary""\nauthcode: $authcode"
|
2021-03-01 04:31:39 +01:00
|
|
|
call="$call -A $authcode"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ===Loglevel===
|
|
|
|
while true; do
|
2021-03-02 01:06:45 +01:00
|
|
|
clear; echo -e "$summary"
|
2021-03-01 04:31:39 +01:00
|
|
|
read -p "loglevel (0/1/2/3): " loglevel
|
2021-03-02 01:06:45 +01:00
|
|
|
if [[ $loglevel =~ ^[0-9]+$ ]] && [[ "$loglevel" -ge "0" ]] && [[ "$loglevel" -le "3" ]]; then
|
|
|
|
summary="$summary""\nloglevel: $loglevel"
|
2021-03-01 04:31:39 +01:00
|
|
|
call="$call -l $loglevel"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# ===File===
|
2021-03-02 01:06:45 +01:00
|
|
|
clear; echo -e "$summary"
|
2021-03-01 04:31:39 +01:00
|
|
|
read -p "aax-file: " file
|
2021-03-02 01:06:45 +01:00
|
|
|
summary="$summary""\naax-file: $file"
|
|
|
|
call="$call $(echo $file | $SED "s;~;$HOME;")"
|
2021-03-01 04:31:39 +01:00
|
|
|
|
|
|
|
# ===Summerize chosen options and call AAXtoMP3===================================================================================================
|
|
|
|
|
2021-03-02 01:06:45 +01:00
|
|
|
# ===Summary===
|
|
|
|
clear; echo -e "$summary\n"
|
2021-03-01 04:31:39 +01:00
|
|
|
echo -e "$call\n"
|
|
|
|
|
|
|
|
# ===Call AAXtoMP3===
|
|
|
|
$call
|