From 4698f7728ada9c98e2f3159bb8eacdb84f928186 Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Mon, 1 Mar 2021 04:31:39 +0100 Subject: [PATCH 1/7] Call AAXtoMP3 Interactively This script interactively asks you for the options to call AAXtoMP3 with. --- interactiveAAXtoMP3 | 110 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 interactiveAAXtoMP3 diff --git a/interactiveAAXtoMP3 b/interactiveAAXtoMP3 new file mode 100644 index 0000000..e5a44a9 --- /dev/null +++ b/interactiveAAXtoMP3 @@ -0,0 +1,110 @@ +#!/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==================================================================================================================================== + +# Usage synopsis +usage=$'\nUsage: interactiveAAXtoMP3 [--advanced] [--help]\n' +# Help mesaage +help=$'\nUsage: interactiveAAXtoMP3 [--advanced] [--help]\n +--advanced More options +--help Print this message\n' +summery="" # This will contain a summery of the options allready set. +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. + +# ===Options====================================================================================================================================== + +while true; do + case "$1" in + # Advanced options. + -a | --advanced ) advanced=1; shift ;; + # Command synopsis. + -h | --help ) echo -e "$help"; exit ;; + # Anything else stops command line processing. + * ) echo -e "$usage"; exit ;; + esac +done + +# ===Get options for AAXtoMP3===================================================================================================================== + +# ===Codec=== +while true; do + clear; + read -p "codec (mp3/m4a/m4b/flac/aac/opus): " codec + if [[ "$codec" = "mp3" ]]; then summery="$summery""codec: $codec"; call="$call -e:mp3"; break + elif [[ "$codec" = "m4a" ]]; then summery="$summery""codec: $codec"; call="$call -e:m4a"; break + elif [[ "$codec" = "m4b" ]]; then summery="$summery""codec: $codec"; call="$call -e:m4b"; break + elif [[ "$codec" = "flac" ]]; then summery="$summery""codec: $codec"; call="$call --flac"; break + elif [[ "$codec" = "aac" ]]; then summery="$summery""codec: $codec"; call="$call --aac"; break + elif [[ "$codec" = "opus" ]]; then summery="$summery""codec: $codec"; call="$call --opus"; break + fi +done + +# ===Compression=== +while true; do + clear; echo -e "$summery" + if [[ "$codec" = "mp3" ]]; then maxlevel=9 + elif [[ "$codec" = "flac" ]]; then maxlevel=12 + elif [[ "$codec" = "opus" ]]; then maxlevel=10 + else break + fi + read -p "compression level (0-$maxlevel): " compression + if [[ ${compression} =~ $isnum ]] && [[ "$((${compression} > -1))" == "1" ]] && [[ "$((${compression} < ${maxlevel}+1))" == "1" ]]; then + summery="$summery""\ncompression level: $compression" + call="$call --level $compression" + break + fi +done + +# ===Chapters=== +while true; do + clear; echo -e "$summery" + read -p "chapters (yes/no/chapternumber to continue with): " chapters + if [[ ${chapters} =~ $isnum ]]; then summery="$summery""\nchapters: $chapters"; call="$call -c --continue ${chapters}"; break + elif [[ "$chapters" = "yes" ]] ; then summery="$summery""\nchapters: $chapters"; call="$call -c"; break + elif [[ "$chapters" = "no" ]] ; then summery="$summery""\nchapters: $chapters"; call="$call -s"; break + fi +done + +# ===Authcode=== +if ! [ -r .authcode ] || [ -r ~/.authcode ]; then + clear; echo -e "$summery" + read -p "Authcode: " authcode + summery="$summery""\nauthcode: $authcode" + call="$call -A $authcode" +fi + +# ===Loglevel=== +while true; do + clear; echo -e "$summery" + read -p "loglevel (0/1/2/3): " loglevel + if [[ ${loglevel} =~ $isnum ]] && [[ "$((${loglevel} > -1))" == "1" ]] && [[ "$((${loglevel} < 4))" == "1" ]]; then + summery="$summery""\nloglevel: $loglevel" + call="$call -l $loglevel" + break + fi +done + +# ===File=== +clear; echo -e "$summery" +read -p "aax-file: " file +summery="$summery""\naax-file: $file" +call="$call $(echo $file | sed "s;~;$HOME;")" + +# ===Summerize chosen options and call AAXtoMP3=================================================================================================== + +# ===Summery=== +clear; echo -e "$summery\n" +echo -e "$call\n" +# ----- + +# ===Call AAXtoMP3=== +$call From 7f2309248f5cdf132b0a7653d28ca58cdeb7f3b6 Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Tue, 2 Mar 2021 01:06:45 +0100 Subject: [PATCH 2/7] Some little improvements --- interactiveAAXtoMP3 | 103 ++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 42 deletions(-) diff --git a/interactiveAAXtoMP3 b/interactiveAAXtoMP3 index e5a44a9..2a3b233 100644 --- a/interactiveAAXtoMP3 +++ b/interactiveAAXtoMP3 @@ -9,56 +9,75 @@ # ===Variables==================================================================================================================================== -# Usage synopsis -usage=$'\nUsage: interactiveAAXtoMP3 [--advanced] [--help]\n' # Help mesaage help=$'\nUsage: interactiveAAXtoMP3 [--advanced] [--help]\n --advanced More options --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. -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====================================================================================================================================== while true; do case "$1" in - # Advanced options. - -a | --advanced ) advanced=1; shift ;; - # Command synopsis. - -h | --help ) echo -e "$help"; exit ;; - # Anything else stops command line processing. - * ) echo -e "$usage"; exit ;; + # Advanced options. + -a | --advanced ) advanced=1; shift ;; + # Command synopsis. + -h | --help ) echo -e "$help"; exit ;; + # Anything else stops command line processing. + * ) break ;; esac 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===================================================================================================================== # ===Codec=== while true; do clear; read -p "codec (mp3/m4a/m4b/flac/aac/opus): " codec - if [[ "$codec" = "mp3" ]]; then summery="$summery""codec: $codec"; call="$call -e:mp3"; break - elif [[ "$codec" = "m4a" ]]; then summery="$summery""codec: $codec"; call="$call -e:m4a"; break - elif [[ "$codec" = "m4b" ]]; then summery="$summery""codec: $codec"; call="$call -e:m4b"; break - elif [[ "$codec" = "flac" ]]; then summery="$summery""codec: $codec"; call="$call --flac"; break - elif [[ "$codec" = "aac" ]]; then summery="$summery""codec: $codec"; call="$call --aac"; break - elif [[ "$codec" = "opus" ]]; then summery="$summery""codec: $codec"; call="$call --opus"; break - fi + 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 done # ===Compression=== while true; do - clear; echo -e "$summery" - if [[ "$codec" = "mp3" ]]; then maxlevel=9 - elif [[ "$codec" = "flac" ]]; then maxlevel=12 - elif [[ "$codec" = "opus" ]]; then maxlevel=10 - else break - fi + clear; echo -e "$summary" + case "$codec" in + mp3 ) maxlevel=9;; + flac ) maxlevel=12;; + opus ) maxlevel=10;; + * ) break;; + esac read -p "compression level (0-$maxlevel): " compression - if [[ ${compression} =~ $isnum ]] && [[ "$((${compression} > -1))" == "1" ]] && [[ "$((${compression} < ${maxlevel}+1))" == "1" ]]; then - summery="$summery""\ncompression level: $compression" + if [[ $compression =~ ^[0-9]+$ ]] && [[ "$compression" -ge "0" ]] && [[ "$compression" -le "$maxlevel" ]]; then + summary="$summary""\ncompression level: $compression" call="$call --level $compression" break fi @@ -66,45 +85,45 @@ done # ===Chapters=== while true; do - clear; echo -e "$summery" + clear; echo -e "$summary" read -p "chapters (yes/no/chapternumber to continue with): " chapters - if [[ ${chapters} =~ $isnum ]]; then summery="$summery""\nchapters: $chapters"; call="$call -c --continue ${chapters}"; break - elif [[ "$chapters" = "yes" ]] ; then summery="$summery""\nchapters: $chapters"; call="$call -c"; break - elif [[ "$chapters" = "no" ]] ; then summery="$summery""\nchapters: $chapters"; call="$call -s"; break - fi + 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 done # ===Authcode=== if ! [ -r .authcode ] || [ -r ~/.authcode ]; then - clear; echo -e "$summery" + clear; echo -e "$summary" read -p "Authcode: " authcode - summery="$summery""\nauthcode: $authcode" + summary="$summary""\nauthcode: $authcode" call="$call -A $authcode" fi # ===Loglevel=== while true; do - clear; echo -e "$summery" + clear; echo -e "$summary" read -p "loglevel (0/1/2/3): " loglevel - if [[ ${loglevel} =~ $isnum ]] && [[ "$((${loglevel} > -1))" == "1" ]] && [[ "$((${loglevel} < 4))" == "1" ]]; then - summery="$summery""\nloglevel: $loglevel" + if [[ $loglevel =~ ^[0-9]+$ ]] && [[ "$loglevel" -ge "0" ]] && [[ "$loglevel" -le "3" ]]; then + summary="$summary""\nloglevel: $loglevel" call="$call -l $loglevel" break fi done # ===File=== -clear; echo -e "$summery" +clear; echo -e "$summary" read -p "aax-file: " file -summery="$summery""\naax-file: $file" -call="$call $(echo $file | sed "s;~;$HOME;")" +summary="$summary""\naax-file: $file" +call="$call $(echo $file | $SED "s;~;$HOME;")" # ===Summerize chosen options and call AAXtoMP3=================================================================================================== -# ===Summery=== -clear; echo -e "$summery\n" +# ===Summary=== +clear; echo -e "$summary\n" echo -e "$call\n" -# ----- # ===Call AAXtoMP3=== $call From 4dfb59e09157619015345c1d946aec93a51b5bea Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Tue, 2 Mar 2021 01:28:47 +0100 Subject: [PATCH 3/7] Updated README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3c319a4..52595b1 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ Thanks to kbabioch, this script has also been packaged in the [AUR](https://aur. ``` bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level ] [-c|--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [-A|--authcode ] [-n|--no-clobber] [-t|--target_dir ] [-C|--complete_dir ] [-V|--validate] [-d|--debug] [-h|--help] [--continue ] ... ``` +or if you want to get guided through the options +``` +bash interactiveAAXtoMP3 [-a|--advanced] [-h|--help] +``` * **<AAX INPUT_FILES>**... are considered input file(s), useful for batching! From 4537c7d01d93d411ba30924714f9d8f59b2b144b Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Tue, 2 Mar 2021 01:51:12 +0100 Subject: [PATCH 4/7] Just a little correction regarding sed --- AAXtoMP3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index e9f4eeb..3838c98 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -684,7 +684,7 @@ do #ffmpeg version 4+ and on the output for all older versions. split_input="" split_output="" - if [ "$(($(ffmpeg -version | sed -E 's/[^0-9]*([0-9]).*/\1/g;1q') > 3))" = "1" ]; then + if [ "$(($(ffmpeg -version | $SED -E 's/[^0-9]*([0-9]).*/\1/g;1q') > 3))" = "1" ]; then split_input="-ss ${chapter_start%?} -to ${chapter_end}" else split_output="-ss ${chapter_start%?} -to ${chapter_end}" From 88c9b1701fd233574bfcf5a2d8daa0ee851107ee Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Tue, 9 Mar 2021 22:26:48 +0100 Subject: [PATCH 5/7] Save chosen options for next time Now this script creates a save-file from which it loads the option the next time the script is used Additionally aax-File drag'n'drop works now, at least on Ubuntu. --- interactiveAAXtoMP3 | 48 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/interactiveAAXtoMP3 b/interactiveAAXtoMP3 index 2a3b233..a9495d9 100644 --- a/interactiveAAXtoMP3 +++ b/interactiveAAXtoMP3 @@ -9,7 +9,7 @@ # ===Variables==================================================================================================================================== -# Help mesaage +# Help message help=$'\nUsage: interactiveAAXtoMP3 [--advanced] [--help]\n --advanced More options --help Print this message\n' @@ -22,11 +22,11 @@ advanced=0 # Toggles advanced options on or off. while true; do case "$1" in # Advanced options. - -a | --advanced ) advanced=1; shift ;; + -a | --advanced ) advanced=1; shift ;; # Command synopsis. - -h | --help ) echo -e "$help"; exit ;; + -h | --help ) echo -e "$help"; exit ;; # Anything else stops command line processing. - * ) break ;; + * ) break ;; esac done @@ -50,12 +50,36 @@ if ! [[ $(type -P "$SED") ]]; then exit 1 fi +# ===Get options from last time=================================================================================================================== + +# ===Set default values=== +lastcodec="mp3" +lastcompression="4" +lastchapters="yes" +lastauthcode="" +lastloglevel="1" + +# ===Get Values from last time=== +if [ -f "interactive.txt" ]; then + for ((i=1;i<=$(wc -l interactive.txt | cut -d " " -f 1);i++)) do + line=$(head -$i interactive.txt | tail -1) + case $(echo $line | cut -d " " -f 1 | $SED 's/.$//') in + codec ) lastcodec="$(echo $line | cut -d " " -f 2)";; + compression ) lastcompression="$(echo $line | cut -d " " -f 2)";; + chapters ) lastchapters="$(echo $line | cut -d " " -f 2)";; + authcode ) lastauthcode="$(echo $line | cut -d " " -f 2)";; + loglevel ) lastloglevel="$(echo $line | cut -d " " -f 2)";; + * ) rm interactive.txt; exit 1;; + esac + done +fi + # ===Get options for AAXtoMP3===================================================================================================================== # ===Codec=== while true; do clear; - read -p "codec (mp3/m4a/m4b/flac/aac/opus): " codec + read -e -p "codec (mp3/m4a/m4b/flac/aac/opus): " -i "$lastcodec" codec case "$codec" in mp3 ) summary="$summary""codec: $codec"; call="$call -e:mp3"; break;; m4a ) summary="$summary""codec: $codec"; call="$call -e:m4a"; break;; @@ -75,7 +99,7 @@ while true; do opus ) maxlevel=10;; * ) break;; esac - read -p "compression level (0-$maxlevel): " compression + read -e -p "compression level (0-$maxlevel): " -i "$lastcompression" compression if [[ $compression =~ ^[0-9]+$ ]] && [[ "$compression" -ge "0" ]] && [[ "$compression" -le "$maxlevel" ]]; then summary="$summary""\ncompression level: $compression" call="$call --level $compression" @@ -86,7 +110,7 @@ done # ===Chapters=== while true; do clear; echo -e "$summary" - read -p "chapters (yes/no/chapternumber to continue with): " chapters + read -e -p "chapters (yes/no/chapternumber to continue with): " -i "$lastchapters" chapters case "$chapters" in ^[0-9]+$ ) summary="$summary""\nchapters: $chapters"; call="$call -c --continue ${chapters}"; break;; yes ) summary="$summary""\nchapters: $chapters"; call="$call -c"; break;; @@ -97,7 +121,7 @@ done # ===Authcode=== if ! [ -r .authcode ] || [ -r ~/.authcode ]; then clear; echo -e "$summary" - read -p "Authcode: " authcode + read -e -p "Authcode: " -i "$lastauthcode" authcode summary="$summary""\nauthcode: $authcode" call="$call -A $authcode" fi @@ -105,7 +129,7 @@ fi # ===Loglevel=== while true; do clear; echo -e "$summary" - read -p "loglevel (0/1/2/3): " loglevel + read -e -p "loglevel (0/1/2/3): " -i "$lastloglevel" loglevel if [[ $loglevel =~ ^[0-9]+$ ]] && [[ "$loglevel" -ge "0" ]] && [[ "$loglevel" -le "3" ]]; then summary="$summary""\nloglevel: $loglevel" call="$call -l $loglevel" @@ -116,6 +140,9 @@ done # ===File=== clear; echo -e "$summary" read -p "aax-file: " file +file="${file%\'}" #remove suffix ' if file is given via drag'n'drop +file="${file#\'}" #remove prefix ' if file is given via drag'n'drop +savefile="$summary" summary="$summary""\naax-file: $file" call="$call $(echo $file | $SED "s;~;$HOME;")" @@ -125,5 +152,8 @@ call="$call $(echo $file | $SED "s;~;$HOME;")" clear; echo -e "$summary\n" echo -e "$call\n" +# ===Save chosen options=== +echo -e $savefile | $SED "s;\ level:;:;" > interactive.txt + # ===Call AAXtoMP3=== $call From 2206cf9dd8f8c7b2f827a19bcbb6732b4cb958f0 Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Tue, 9 Mar 2021 22:44:26 +0100 Subject: [PATCH 6/7] Updated Readme.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 52595b1..00a45b0 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ bash interactiveAAXtoMP3 [-a|--advanced] [-h|--help] * **<AAX INPUT_FILES>**... are considered input file(s), useful for batching! -## Options +## Options for AAXtoMP3 * **-f** or **--flac** Flac Encoding and as default produces a single file. * **-o** or **--opus** Ogg/Opus Encoding defaults to multiple file output by chapter. The extension is .ogg * **-a** or **--aac** AAC Encoding and produce a m4a single files output. @@ -62,6 +62,11 @@ bash interactiveAAXtoMP3 [-a|--advanced] [-h|--help] * **--file-naming-scheme <STRING>** or **-F** Use a custom file naming scheme, with variables. See [below](#custom-naming-scheme) for more info. * **--chapter-naming-scheme <STRING>** Use a custom chapter naming scheme, with variables. See [below](#custom-naming-scheme) for more info. +## Options for interactiveAAXtoMP3 +* **-a** or **--advanced** Get more options to choose. Not used right now. +* **-h** or **--help** Get a help prompt. +This script presents you the options you chose last time as default. +When you get asked for the aax-file you may just drag'n'drop it to the terminal. ### [AUTHCODE] **Your** Audible auth code (it won't correctly decode otherwise) (required). From 051f37b3ffa87e90013a7ca70723e7da0093a37e Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Tue, 9 Mar 2021 22:49:54 +0100 Subject: [PATCH 7/7] Made savefile invisible --- interactiveAAXtoMP3 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interactiveAAXtoMP3 b/interactiveAAXtoMP3 index a9495d9..f3e4223 100644 --- a/interactiveAAXtoMP3 +++ b/interactiveAAXtoMP3 @@ -60,16 +60,16 @@ lastauthcode="" lastloglevel="1" # ===Get Values from last time=== -if [ -f "interactive.txt" ]; then - for ((i=1;i<=$(wc -l interactive.txt | cut -d " " -f 1);i++)) do - line=$(head -$i interactive.txt | tail -1) +if [ -f ".interactivesave" ]; then + for ((i=1;i<=$(wc -l .interactivesave | cut -d " " -f 1);i++)) do + line=$(head -$i .interactivesave | tail -1) case $(echo $line | cut -d " " -f 1 | $SED 's/.$//') in codec ) lastcodec="$(echo $line | cut -d " " -f 2)";; compression ) lastcompression="$(echo $line | cut -d " " -f 2)";; chapters ) lastchapters="$(echo $line | cut -d " " -f 2)";; authcode ) lastauthcode="$(echo $line | cut -d " " -f 2)";; loglevel ) lastloglevel="$(echo $line | cut -d " " -f 2)";; - * ) rm interactive.txt; exit 1;; + * ) rm .interactivesave; exit 1;; esac done fi @@ -153,7 +153,7 @@ clear; echo -e "$summary\n" echo -e "$call\n" # ===Save chosen options=== -echo -e $savefile | $SED "s;\ level:;:;" > interactive.txt +echo -e $savefile | $SED "s;\ level:;:;" > .interactivesave # ===Call AAXtoMP3=== $call