From 3ed9f72963732faa209387f0d836c06dee4c0cd4 Mon Sep 17 00:00:00 2001 From: fnuesse Date: Thu, 14 Jun 2018 18:05:10 +0200 Subject: [PATCH] Refined Parameterparsing --- AAXtoMP3 | 98 +++++++++++++------ .../Amalthea - Teil 4/Amalthea - Teil 4.flac | 0 2 files changed, 68 insertions(+), 30 deletions(-) delete mode 100644 Hörbuch/Neal Stephenson/Amalthea - Teil 4/Amalthea - Teil 4.flac diff --git a/AAXtoMP3 b/AAXtoMP3 index 89848b4..fe4156d 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -6,6 +6,7 @@ codec=libmp3lame extension=mp3 mode=chaptered authcode=".authcode"; +auth=""; if [ -z ${HOME+x} ] && ! [ -z ${USERPROFILE+x} ]; then HOME="$USERPROFILE"; fi authcodeDirs="${HOME}/ ./" GREP=$(grep --version | grep -q GNU && echo "grep" || echo "ggrep") @@ -23,44 +24,77 @@ if ! [[ $(type -P ffmpeg) ]]; then exit 1 fi +function print_manual(){ + echo "" + echo "Usage: bash AAXtoMP3 [--flac] [--aac] [--opus ] [--single] --auth=AUTHCODE {FILES}" + echo " Note that when you enter conflicting parameters, the last one will be the one used." + echo " You HAVE to use the equals-sign. You may also use -a=AUTHCODE. But the '=' is mandatory." + echo " Everything after the authcode must be a filename to a file which you want to convert" + echo "" + echo " [--flac]: The flac codec is used in the resulting files. Default is MP3" + echo " [--aac]: The aac codec is used in the resulting files. Default is MP3" + echo " [--opus]: The opus codec is used in the resulting files. Default is MP3" + echo " [--single] : Prevents creation of chapters. Results in a single file." + echo " --authcode=XXXXXXXX: Your personal autcode. Everything after this parameter will be used as an inputfile!" + echo " {FILES}: Files to convert, seperated by spaces." + echo "" +} + if [ "$#" -eq 0 ]; then - echo "Usage: bash AAXtoMP3 [--flac] [--aac] [--opus ] [--single] AUTHCODE {FILES}" - echo "Note that any optional flags have to be inputed in order to function correctly." - echo "[--flac] : The flac codec is used in the resulting files. Default is MP3" - echo "[--aac] : The aac codec is used in the resulting files. Default is MP3" - echo "[--opus] : The opus codec is used in the resulting files. Default is MP3" - echo "[--single]: Prevents creation of chapters. Results in a single file." - exit 1 + print_manual + exit 1 fi -if [[ "$1" = '--flac' ]] -then - codec=flac - extension=flac - shift + +if [[ "$1" = '-h' ]]; then + print_manual + exit 1 +fi +if [[ "$1" = '--help' ]]; then + print_manual + exit 1 fi -if [[ "$1" == '--aac' ]] -then - codec=copy - extension=m4a - mode=single - shift -fi -if [[ "$1" = '--opus' ]] -then - codec=libopus - extension=ogg - shift -fi +#Iterate over the parameter to find all entered ones +for var in "$@" +do + + if [[ "$var" = '--flac' ]] + then + codec=flac + extension=flac + shift + fi + + if [[ "$var" == '--aac' ]] + then + codec=copy + extension=m4a + mode=single + shift + fi + + if [[ "$var" = '--opus' ]] + then + codec=libopus + extension=ogg + shift + fi + + if [[ "$var" == '--single' ]] + then + mode=single + shift + fi + + case "$var" in + -a=*|--auth=*) echo "found"; + auth="${var#*=}"; + esac +done -if [[ "$1" == '--single' ]] -then - mode=single - shift -fi auth_code=""; for dir in $authcodeDirs; do @@ -79,6 +113,10 @@ else auth_code=`head -1 "$codeFile"` fi +if [ -z "$auth_code" ]; then + auth_code="$auth"; +fi; + if [ -z "$auth_code" ]; then echo "INFO: Sorry, no authcode provided."; exit 1; diff --git a/Hörbuch/Neal Stephenson/Amalthea - Teil 4/Amalthea - Teil 4.flac b/Hörbuch/Neal Stephenson/Amalthea - Teil 4/Amalthea - Teil 4.flac deleted file mode 100644 index e69de29..0000000