From e69b2129823bdde64680c0a660967f84930f6bfc Mon Sep 17 00:00:00 2001 From: upuv Date: Sat, 19 May 2018 21:29:20 +1000 Subject: [PATCH] diferentiated between a log and debug message --- AAXtoMP3 | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 6fa2421..0f0490f 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -9,7 +9,13 @@ extension=mp3 mode=chaptered auth_code= targetdir= +DEBUG=0 +# ----- +# Code tip Do not have any scritp above this point that calls a function or a binary. If you do +# the $1 will no longer be a ARGV element. So you should only do basic variable setting above here. +# +# Process the command line options. This allows for un-ordered options. Sorta like a getops style while true; do case "$1" in -f | --flac ) codec=flac; extension=flac; mode=single ; shift ;; @@ -18,13 +24,14 @@ while true; do -s | --single ) mode=single; shift ;; -t | --target_dir ) targetdir="$2"; shift 2 ;; -A | --authcode ) auth_code="$2"; shift 2 ;; - -d | --debug ) DEBUG=1; shift ;; # Not so secret flag for debug output. to use in code [ $DEBUG == 1 ] && sample=2 + -d | --debug ) DEBUG=1; shift ;; -h | --help ) printf "$usage" $0 ; exit ;; -- ) shift; break ;; * ) break ;; esac done +# Empty argv means we have nothing to do so lets bark some help. if [ "$#" -eq 0 ]; then printf "$usage" $0 exit 1 @@ -43,6 +50,7 @@ if ! [[ $(type -P "$GREP") ]]; then exit 1 fi +# ----- # Obtain the authcode from either the command line, local directory or home directory. if [ -z $auth_code ]; then if [ -r .authcode ]; then @@ -57,6 +65,7 @@ if [ -z $auth_code ]; then exit 1 fi +# ----- # Check the target dir for if set if it is writable if [[ ! -w "${targetdir}" || ! -d "${targetdir}" ]] ; then echo "ERROR Target Directory is not writable: \"$targetdir\"" @@ -67,7 +76,15 @@ fi # ======================================================================== # Utility Functions +# debug debug() { + if [ $DEBUG == 1 ] ; then + echo "$(date "+%F %T%z") DEBUG ${1}" + fi +} + +# log +log() { echo "$(date "+%F %T%z") ${1}" } @@ -99,7 +116,7 @@ normalize_whitespace() { # Main Transcode Loop for path do - debug "Decoding ${path} with auth code ${auth_code}..." + log "Decoding ${path} with auth code ${auth_code}..." # Check for Presense of Audiobook if [[ ! -r "${path}" ]] ; then @@ -122,23 +139,23 @@ do # This is the primary transcode. All the heavy lifting is here. "${playlist_file}" chaptercount=$($GREP -Pc "Chapter.*start.*end" $metadata_file) - debug "Extracting ${chaptercount} chapter files from ${full_file_path}..." + log "Extracting ${chaptercount} chapter files from ${full_file_path}..." chapternum=1 while read -r -u9 first _ _ start _ end @@ -169,9 +186,9 @@ do fi done 9< "$metadata_file" rm "${full_file_path}" - debug "Done creating chapters. Chaptered files contained in ${output_directory}." + log "Done creating chapters. Chaptered files contained in ${output_directory}." fi - debug "Done." + log "Done. ${title}" rm "${metadata_file}" done