Some little improvements

This commit is contained in:
Nicko98 2021-03-02 01:06:45 +01:00 committed by GitHub
parent 4698f7728a
commit 7f2309248f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,56 +9,75 @@
# ===Variables==================================================================================================================================== # ===Variables====================================================================================================================================
# Usage synopsis
usage=$'\nUsage: interactiveAAXtoMP3 [--advanced] [--help]\n'
# Help mesaage # Help mesaage
help=$'\nUsage: interactiveAAXtoMP3 [--advanced] [--help]\n help=$'\nUsage: interactiveAAXtoMP3 [--advanced] [--help]\n
--advanced More options --advanced More options
--help Print this message\n' --help Print this message\n'
summery="" # This will contain a summery of the options allready set. summary="" # This will contain a summary of the options allready set.
call="./AAXtoMP3" # This will contain the call for AAXtoMP3. call="./AAXtoMP3" # This will contain the call for AAXtoMP3.
isnum='^[0-9]+$' # This is needed to check whether a variable is a number. advanced=0 # Toggles advanced options on or off.
advanced=0 # Toggles Advanced options on or off.
# ===Options====================================================================================================================================== # ===Options======================================================================================================================================
while true; do while true; do
case "$1" in case "$1" in
# Advanced options. # Advanced options.
-a | --advanced ) advanced=1; shift ;; -a | --advanced ) advanced=1; shift ;;
# Command synopsis. # Command synopsis.
-h | --help ) echo -e "$help"; exit ;; -h | --help ) echo -e "$help"; exit ;;
# Anything else stops command line processing. # Anything else stops command line processing.
* ) echo -e "$usage"; exit ;; * ) break ;;
esac esac
done done
# ===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
# ===Get options for AAXtoMP3===================================================================================================================== # ===Get options for AAXtoMP3=====================================================================================================================
# ===Codec=== # ===Codec===
while true; do while true; do
clear; clear;
read -p "codec (mp3/m4a/m4b/flac/aac/opus): " codec read -p "codec (mp3/m4a/m4b/flac/aac/opus): " codec
if [[ "$codec" = "mp3" ]]; then summery="$summery""codec: $codec"; call="$call -e:mp3"; break case "$codec" in
elif [[ "$codec" = "m4a" ]]; then summery="$summery""codec: $codec"; call="$call -e:m4a"; break mp3 ) summary="$summary""codec: $codec"; call="$call -e:mp3"; break;;
elif [[ "$codec" = "m4b" ]]; then summery="$summery""codec: $codec"; call="$call -e:m4b"; break m4a ) summary="$summary""codec: $codec"; call="$call -e:m4a"; break;;
elif [[ "$codec" = "flac" ]]; then summery="$summery""codec: $codec"; call="$call --flac"; break m4b ) summary="$summary""codec: $codec"; call="$call -e:m4b"; break;;
elif [[ "$codec" = "aac" ]]; then summery="$summery""codec: $codec"; call="$call --aac"; break flac ) summary="$summary""codec: $codec"; call="$call --flac"; break;;
elif [[ "$codec" = "opus" ]]; then summery="$summery""codec: $codec"; call="$call --opus"; break aac ) summary="$summary""codec: $codec"; call="$call --aac"; break;;
fi opus ) summary="$summary""codec: $codec"; call="$call --opus"; break;;
esac
done done
# ===Compression=== # ===Compression===
while true; do while true; do
clear; echo -e "$summery" clear; echo -e "$summary"
if [[ "$codec" = "mp3" ]]; then maxlevel=9 case "$codec" in
elif [[ "$codec" = "flac" ]]; then maxlevel=12 mp3 ) maxlevel=9;;
elif [[ "$codec" = "opus" ]]; then maxlevel=10 flac ) maxlevel=12;;
else break opus ) maxlevel=10;;
fi * ) break;;
esac
read -p "compression level (0-$maxlevel): " compression read -p "compression level (0-$maxlevel): " compression
if [[ ${compression} =~ $isnum ]] && [[ "$((${compression} > -1))" == "1" ]] && [[ "$((${compression} < ${maxlevel}+1))" == "1" ]]; then if [[ $compression =~ ^[0-9]+$ ]] && [[ "$compression" -ge "0" ]] && [[ "$compression" -le "$maxlevel" ]]; then
summery="$summery""\ncompression level: $compression" summary="$summary""\ncompression level: $compression"
call="$call --level $compression" call="$call --level $compression"
break break
fi fi
@ -66,45 +85,45 @@ done
# ===Chapters=== # ===Chapters===
while true; do while true; do
clear; echo -e "$summery" clear; echo -e "$summary"
read -p "chapters (yes/no/chapternumber to continue with): " chapters read -p "chapters (yes/no/chapternumber to continue with): " chapters
if [[ ${chapters} =~ $isnum ]]; then summery="$summery""\nchapters: $chapters"; call="$call -c --continue ${chapters}"; break case "$chapters" in
elif [[ "$chapters" = "yes" ]] ; then summery="$summery""\nchapters: $chapters"; call="$call -c"; break ^[0-9]+$ ) summary="$summary""\nchapters: $chapters"; call="$call -c --continue ${chapters}"; break;;
elif [[ "$chapters" = "no" ]] ; then summery="$summery""\nchapters: $chapters"; call="$call -s"; break yes ) summary="$summary""\nchapters: $chapters"; call="$call -c"; break;;
fi no ) summary="$summary""\nchapters: $chapters"; call="$call -s"; break;;
esac
done done
# ===Authcode=== # ===Authcode===
if ! [ -r .authcode ] || [ -r ~/.authcode ]; then if ! [ -r .authcode ] || [ -r ~/.authcode ]; then
clear; echo -e "$summery" clear; echo -e "$summary"
read -p "Authcode: " authcode read -p "Authcode: " authcode
summery="$summery""\nauthcode: $authcode" summary="$summary""\nauthcode: $authcode"
call="$call -A $authcode" call="$call -A $authcode"
fi fi
# ===Loglevel=== # ===Loglevel===
while true; do while true; do
clear; echo -e "$summery" clear; echo -e "$summary"
read -p "loglevel (0/1/2/3): " loglevel read -p "loglevel (0/1/2/3): " loglevel
if [[ ${loglevel} =~ $isnum ]] && [[ "$((${loglevel} > -1))" == "1" ]] && [[ "$((${loglevel} < 4))" == "1" ]]; then if [[ $loglevel =~ ^[0-9]+$ ]] && [[ "$loglevel" -ge "0" ]] && [[ "$loglevel" -le "3" ]]; then
summery="$summery""\nloglevel: $loglevel" summary="$summary""\nloglevel: $loglevel"
call="$call -l $loglevel" call="$call -l $loglevel"
break break
fi fi
done done
# ===File=== # ===File===
clear; echo -e "$summery" clear; echo -e "$summary"
read -p "aax-file: " file read -p "aax-file: " file
summery="$summery""\naax-file: $file" summary="$summary""\naax-file: $file"
call="$call $(echo $file | sed "s;~;$HOME;")" call="$call $(echo $file | $SED "s;~;$HOME;")"
# ===Summerize chosen options and call AAXtoMP3=================================================================================================== # ===Summerize chosen options and call AAXtoMP3===================================================================================================
# ===Summery=== # ===Summary===
clear; echo -e "$summery\n" clear; echo -e "$summary\n"
echo -e "$call\n" echo -e "$call\n"
# -----
# ===Call AAXtoMP3=== # ===Call AAXtoMP3===
$call $call