From ad86f187f8d7201cfe211b0a67cbb412a7b785f3 Mon Sep 17 00:00:00 2001 From: fabh2o Date: Mon, 8 Feb 2021 21:29:26 +0100 Subject: [PATCH 01/15] keep n-th artist only --- AAXtoMP3 | 15 ++++++++++++--- README.md | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index ec2ce38..390cf7f 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -5,7 +5,7 @@ # Command Line Options # Usage Synopsis. -usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level ]\n[--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode ] [--no-clobber]\n[--target_dir ] [--complete_dir ] [--validate]\n[--continue ]{FILES}\n' +usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level ]\n[--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode ] [--no-clobber]\n[--target_dir ] [--complete_dir ] [--validate]\n[--continue ] [--keep-artist ] {FILES}\n' codec=libmp3lame # Default encoder. extension=mp3 # Default encoder extension. level=-1 # Compression level. Can be given for mp3, flac and opus. -1 = default/not specified. @@ -19,6 +19,7 @@ DEBUG=0 # Default off, If set extremely verbose output. noclobber=0 # Default off, clobber only if flag is enabled continue=0 # Default off, If set Transcoding is skipped and chapter splitting starts at chapter continueAt. continueAt=1 # Optional chapter to continue splitting the chapters. +keepArtist=-1 # Default off, if set change artist metadata to use the passed argument as field # ----- # Code tip Do not have any script above this point that calls a function or a binary. If you do @@ -59,6 +60,8 @@ while true; do --continue ) continueAt="$2"; continue=1; shift 2 ;; # Compression level --level ) level="$2"; shift 2 ;; + # Keep artist number n + --keep-artist ) keepArtist="$2"; shift 2 ;; # Command synopsis. -h | --help ) printf "$usage" $0 ; exit ;; # Standard flag signifying the end of command line processing. @@ -410,7 +413,14 @@ do # Make sure everything is a variable. Simplifying Command interpretation save_metadata "${aax_file}" genre=$(get_metadata_value genre) - artist=$(get_metadata_value artist) + if [ "${keepArtist}" != "-1" ]; then + # sed command: 'C. S. Lewis' -> 'C.S. Lewis' + artist=$(get_metadata_value artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)+)|\1 |g') + album_artist="$(get_metadata_value album_artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)')" + else + artist=$(get_metadata_value artist) + album_artist="$(get_metadata_value album_artist)" + fi title=$(get_metadata_value title | $SED 's/'\:'/'-'/g' | $SED 's/- /-/g' | xargs -0) title=${title:0:100} if [ "x${targetdir}" != "x" ] ; then @@ -420,7 +430,6 @@ do fi output_file="${output_directory}/${title}.${extension}" bitrate="$(get_bitrate)k" - album_artist="$(get_metadata_value album_artist)" album="$(get_metadata_value album)" album_date="$(get_metadata_value date)" copyright="$(get_metadata_value copyright)" diff --git a/README.md b/README.md index ab3dd87..c3af0a2 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level Date: Mon, 8 Feb 2021 21:39:10 +0100 Subject: [PATCH 02/15] rephrased flag description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c3af0a2..cb421e6 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level Date: Mon, 8 Feb 2021 21:46:57 +0100 Subject: [PATCH 03/15] typo in sed --- AAXtoMP3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 390cf7f..1bec38b 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -416,7 +416,7 @@ do if [ "${keepArtist}" != "-1" ]; then # sed command: 'C. S. Lewis' -> 'C.S. Lewis' artist=$(get_metadata_value artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)+)|\1 |g') - album_artist="$(get_metadata_value album_artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)')" + album_artist="$(get_metadata_value album_artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)+)|\1 |g')" else artist=$(get_metadata_value artist) album_artist="$(get_metadata_value album_artist)" From 1e7802ac3fdb9b16349efe95a86187ef7158c13c Mon Sep 17 00:00:00 2001 From: fabh2o Date: Mon, 8 Feb 2021 22:04:32 +0100 Subject: [PATCH 04/15] force author name --- AAXtoMP3 | 25 +++++++++++++++++-------- README.md | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 1bec38b..bedf2aa 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -5,7 +5,7 @@ # Command Line Options # Usage Synopsis. -usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level ]\n[--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode ] [--no-clobber]\n[--target_dir ] [--complete_dir ] [--validate]\n[--continue ] [--keep-artist ] {FILES}\n' +usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level ]\n[--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode ] [--no-clobber]\n[--target_dir ] [--complete_dir ] [--validate]\n[--continue ] [--keep-artist ] [--author ] {FILES}\n' codec=libmp3lame # Default encoder. extension=mp3 # Default encoder extension. level=-1 # Compression level. Can be given for mp3, flac and opus. -1 = default/not specified. @@ -20,6 +20,7 @@ noclobber=0 # Default off, clobber only if flag is enabled continue=0 # Default off, If set Transcoding is skipped and chapter splitting starts at chapter continueAt. continueAt=1 # Optional chapter to continue splitting the chapters. keepArtist=-1 # Default off, if set change artist metadata to use the passed argument as field +authorOverride= # Override the author, ignoring the metadata # ----- # Code tip Do not have any script above this point that calls a function or a binary. If you do @@ -62,6 +63,8 @@ while true; do --level ) level="$2"; shift 2 ;; # Keep artist number n --keep-artist ) keepArtist="$2"; shift 2 ;; + # Author override + --author ) authorOverride="$2"; shift 2 ;; # Command synopsis. -h | --help ) printf "$usage" $0 ; exit ;; # Standard flag signifying the end of command line processing. @@ -144,7 +147,7 @@ log() { # ----- # Print out what we have already after command line processing. -debug_vars "Command line options as set" codec extension mode container targetdir completedir auth_code +debug_vars "Command line options as set" codec extension mode container targetdir completedir auth_code keepArtist authorOverride # ======================================================================== # Variable validation @@ -413,13 +416,19 @@ do # Make sure everything is a variable. Simplifying Command interpretation save_metadata "${aax_file}" genre=$(get_metadata_value genre) - if [ "${keepArtist}" != "-1" ]; then - # sed command: 'C. S. Lewis' -> 'C.S. Lewis' - artist=$(get_metadata_value artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)+)|\1 |g') - album_artist="$(get_metadata_value album_artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)+)|\1 |g')" + if [ "x${authorOverride}" != "x" ]; then + #Override + artist="${authorOverride}" + album_artist="${authorOverride}" else - artist=$(get_metadata_value artist) - album_artist="$(get_metadata_value album_artist)" + if [ "${keepArtist}" != "-1" ]; then + # sed command: 'C. S. Lewis' -> 'C.S. Lewis' + artist=$(get_metadata_value artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)+)|\1 |g') + album_artist="$(get_metadata_value album_artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)+)|\1 |g')" + else + artist=$(get_metadata_value artist) + album_artist="$(get_metadata_value album_artist)" + fi fi title=$(get_metadata_value title | $SED 's/'\:'/'-'/g' | $SED 's/- /-/g' | xargs -0) title=${title:0:100} diff --git a/README.md b/README.md index cb421e6..93fc18c 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level Date: Tue, 9 Feb 2021 03:15:22 +0100 Subject: [PATCH 05/15] faster chapter splitting Since there is an issue with this fix when applied on flac option, the changes dont take effect on flac. For more information have a look in KrumpetPirate/AAXtoMP3 issue #142. --- AAXtoMP3 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index ec2ce38..8fb3490 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -542,14 +542,18 @@ do chapter_title="${title}-$(printf %0${#chaptercount}d $chapternum) ${chapter}" chapter_file="${output_directory}/${chapter_title}.${extension}" - # the ID3 tags must only be specified for *.mp3 files, - # the other container formats come with their own - # tagging mechanisms. - id3_version_param="" - if test "${extension}" = "mp3"; then - id3_version_param="-id3v2_version 3" + # Since the .aax file allready got converted we can use + # -acodec copy, which is much faster than a reencodation. + # Since there is an issue when using copy on flac, where + # the duration of the chapters gets shown as if they where + # as long as the whole audiobook. + chapter_codec="" + if test "${extension}" = "flac"; then + chapter_codec="-acodec flac "${compression_level_param}"" + else + chapter_codec="-acodec copy" fi - + # Big Long chapter debug debug_vars "Chapter Variables:" cover_file chapter_start chapter_end id3_version_param chapternum chapter_title chapter_file if [ "$((${continueAt} > ${chapternum}))" = "0" ]; then @@ -564,8 +568,7 @@ do -i "${cover_file}" \ -map 0:0 \ -map 1:0 \ - -acodec "${codec}" ${id3_version_param} \ - ${compression_level_param} \ + ${chapter_codec} \ -metadata:s:v title="Album cover" \ -metadata:s:v comment="Cover (Front)" \ -metadata track="${chapternum}" \ From 2b31c7defa978e6751235e179c9ad9d20ae3b79a Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Tue, 9 Feb 2021 03:24:20 +0100 Subject: [PATCH 06/15] faster chapter splitting Since there is an issue with this fix when applied on flac option, the changes dont take effect on flac. For more information have a look in KrumpetPirate/AAXtoMP3 issue #142. --- AAXtoMP3 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 8fb3490..b6e9363 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -549,11 +549,11 @@ do # as long as the whole audiobook. chapter_codec="" if test "${extension}" = "flac"; then - chapter_codec="-acodec flac "${compression_level_param}"" + chapter_codec="flac "${compression_level_param}"" else - chapter_codec="-acodec copy" + chapter_codec="copy" fi - + # Big Long chapter debug debug_vars "Chapter Variables:" cover_file chapter_start chapter_end id3_version_param chapternum chapter_title chapter_file if [ "$((${continueAt} > ${chapternum}))" = "0" ]; then @@ -568,7 +568,7 @@ do -i "${cover_file}" \ -map 0:0 \ -map 1:0 \ - ${chapter_codec} \ + -acodec ${chapter_codec} \ -metadata:s:v title="Album cover" \ -metadata:s:v comment="Cover (Front)" \ -metadata track="${chapternum}" \ From e6f34b5f97473554c67bd78ed010042d92db238f Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Tue, 9 Feb 2021 12:39:15 +0100 Subject: [PATCH 07/15] faster chapter splitting Since there is an issue with this fix when applied on flac option, the changes dont take effect on flac. For more information have a look in KrumpetPirate/AAXtoMP3 issue #142. --- AAXtoMP3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index b6e9363..fa85260 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -555,7 +555,7 @@ do fi # Big Long chapter debug - debug_vars "Chapter Variables:" cover_file chapter_start chapter_end id3_version_param chapternum chapter_title chapter_file + debug_vars "Chapter Variables:" cover_file chapter_start chapter_end chapternum chapter_title chapter_file if [ "$((${continueAt} > ${chapternum}))" = "0" ]; then # Extract chapter by time stamps start and finish of chapter. # This extracts based on time stamps start and end. From fcef788bc41abb70f0f14fb8c44b7b8103d341bd Mon Sep 17 00:00:00 2001 From: fabh2o Date: Tue, 9 Feb 2021 17:48:21 +0100 Subject: [PATCH 08/15] artist --> author --- AAXtoMP3 | 8 ++++---- README.md | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 3535ccc..14cd779 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -5,7 +5,7 @@ # Command Line Options # Usage Synopsis. -usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level ]\n[--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode ] [--no-clobber]\n[--target_dir ] [--complete_dir ] [--validate]\n[--continue ] [--keep-artist ] [--author ] {FILES}\n' +usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level ]\n[--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode ] [--no-clobber]\n[--target_dir ] [--complete_dir ] [--validate]\n[--continue ] [--keep-author ] [--author ] {FILES}\n' codec=libmp3lame # Default encoder. extension=mp3 # Default encoder extension. level=-1 # Compression level. Can be given for mp3, flac and opus. -1 = default/not specified. @@ -19,7 +19,7 @@ DEBUG=0 # Default off, If set extremely verbose output. noclobber=0 # Default off, clobber only if flag is enabled continue=0 # Default off, If set Transcoding is skipped and chapter splitting starts at chapter continueAt. continueAt=1 # Optional chapter to continue splitting the chapters. -keepArtist=-1 # Default off, if set change artist metadata to use the passed argument as field +keepArtist=-1 # Default off, if set change author metadata to use the passed argument as field authorOverride= # Override the author, ignoring the metadata # ----- @@ -61,8 +61,8 @@ while true; do --continue ) continueAt="$2"; continue=1; shift 2 ;; # Compression level --level ) level="$2"; shift 2 ;; - # Keep artist number n - --keep-artist ) keepArtist="$2"; shift 2 ;; + # Keep author number n + --keep-author ) keepArtist="$2"; shift 2 ;; # Author override --author ) authorOverride="$2"; shift 2 ;; # Command synopsis. diff --git a/README.md b/README.md index 93fc18c..5f78bfb 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level Date: Tue, 9 Feb 2021 18:54:37 +0100 Subject: [PATCH 09/15] remove leading space after cut --- AAXtoMP3 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 14cd779..623c52d 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -417,15 +417,17 @@ do save_metadata "${aax_file}" genre=$(get_metadata_value genre) if [ "x${authorOverride}" != "x" ]; then - #Override + #Manual Override artist="${authorOverride}" album_artist="${authorOverride}" else if [ "${keepArtist}" != "-1" ]; then - # sed command: 'C. S. Lewis' -> 'C.S. Lewis' - artist=$(get_metadata_value artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)+)|\1 |g') - album_artist="$(get_metadata_value album_artist | cut -d',' -f"$keepArtist" | $SED -E 's|\. +|\.|g; s|((\w+\.)+)|\1 |g')" + # Choose artist from the one that are present in the metadata. Comma separated list of names + # remove leading space; 'C. S. Lewis' -> 'C.S. Lewis' + artist="$(get_metadata_value artist | cut -d',' -f"$keepArtist" | $SED -E 's|^ ||g; s|\. +|\.|g; s|((\w+\.)+)|\1 |g')" + album_artist="$(get_metadata_value album_artist | cut -d',' -f"$keepArtist" | $SED -E 's|^ ||g; s|\. +|\.|g; s|((\w+\.)+)|\1 |g')" else + # The default artist=$(get_metadata_value artist) album_artist="$(get_metadata_value album_artist)" fi From fb48899cb780b6cdae417c7de5b90cdacf7c8eb4 Mon Sep 17 00:00:00 2001 From: fabh2o Date: Tue, 9 Feb 2021 19:03:55 +0100 Subject: [PATCH 10/15] precedence --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f78bfb..2cf91c6 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level Date: Tue, 9 Feb 2021 20:00:11 +0100 Subject: [PATCH 11/15] Added different loglevels I added different loglevels and (for loglevel 0 and 1) a progress bar for chapter splitting. 0 = show progress only, chapter splitting shown as progress bar 1 (default) = fewer information, chapter splitting shown as progress bar 2 = as it has been up until now 3 = debug mode --- AAXtoMP3 | 129 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 105 insertions(+), 24 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index fa85260..f642ac0 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -5,7 +5,7 @@ # Command Line Options # Usage Synopsis. -usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level ]\n[--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode ] [--no-clobber]\n[--target_dir ] [--complete_dir ] [--validate]\n[--continue ]{FILES}\n' +usage=$'\nUsage: AAXtoMP3 [--flac] [--aac] [--opus ] [--single] [--level ]\n[--chaptered] [-e:mp3] [-e:m4a] [-e:m4b] [--authcode ] [--no-clobber]\n[--target_dir ] [--complete_dir ] [--validate]\n[--continue ]{FILES} [--loglevel ]\n' codec=libmp3lame # Default encoder. extension=mp3 # Default encoder extension. level=-1 # Compression level. Can be given for mp3, flac and opus. -1 = default/not specified. @@ -15,7 +15,7 @@ targetdir= # Optional output location. Note default is basedir completedir= # Optional location to move aax files once the decoding is complete. container=mp3 # Just in case we need to change the container. Used for M4A to M4B VALIDATE=0 # Validate the input aax file(s) only. No Transcoding of files will occur -DEBUG=0 # Default off, If set extremely verbose output. +loglevel=1 # Default off, If set extremely verbose output. noclobber=0 # Default off, clobber only if flag is enabled continue=0 # Default off, If set Transcoding is skipped and chapter splitting starts at chapter continueAt. continueAt=1 # Optional chapter to continue splitting the chapters. @@ -52,7 +52,9 @@ while true; do # Don't overwrite the target directory if it already exists -n | --no-clobber ) noclobber=1; shift ;; # Extremely verbose output. - -d | --debug ) DEBUG=1; shift ;; + -d | --debug ) loglevel=3; shift ;; + # Set loglevel. + -l | --loglevel ) loglevel="$2"; shift 2 ;; # Validate ONLY the aax file(s) No transcoding occurs -V | --validate ) VALIDATE=1; shift ;; # continue splitting chapters at chapter continueAt @@ -86,7 +88,7 @@ set -o errexit -o noclobber -o nounset -o pipefail # debug # debug "Some longish message" debug() { - if [ $DEBUG == 1 ] ; then + if [ $loglevel == 3 ] ; then echo "$(date "+%F %T%z") DEBUG ${1}" fi } @@ -95,7 +97,7 @@ debug() { # debug dump contents of a file to STDOUT # debug "" debug_file() { - if [ $DEBUG == 1 ] ; then + if [ $loglevel == 3 ] ; then echo "$(date "+%F %T%z") DEBUG" echo "=Start==========================================================================" cat "${1}" @@ -107,7 +109,7 @@ debug_file() { # debug dump a list of internal script variables to STDOUT # debug_vars "Some Message" var1 var2 var3 var4 var5 debug_vars() { - if [ $DEBUG == 1 ] ; then + if [ $loglevel == 3 ] ; then msg="$1"; shift ; # Grab the message args=("$@") # Grab the rest of the args @@ -136,10 +138,37 @@ debug_vars() { # ----- # log log() { - echo "$(date "+%F %T%z") ${1}" + if [ "$((${loglevel} > 1))" == "1" ] ; then + echo "$(date "+%F %T%z") ${1}" + else + echo "${1}" + fi } # ----- +#progressbar produces a progressbar in the style of +# process: |####### | XX% (part/total unit) +# which is gonna be overwritten by the next line. + +progressbar() { + #get input + part=${1} + total=${2} + + #compute percentage and make print_percentage the same length regardless of the number of digits. + percentage=$((part*100/total)) + if [ "$((percentage<10))" = "1" ]; then print_percentage=" $percentage" + elif [ "$((percentage<100))" = "1" ]; then print_percentage=" $percentage" + else print_percentage="$percentage"; fi + + #draw progressbar with one # for every 5% and blank spaces for the missing part. + progressbar="" + for (( n=0; n<(percentage/5); n++ )) ; do progressbar="$progressbar#"; done + for (( n=0; n<(20-(percentage/5)); n++ )) ; do progressbar="$progressbar "; done + + #print progressbar + echo -ne "Chapter splitting: |$progressbar| $print_percentage% ($part/$total chapters)\r" +} # Print out what we have already after command line processing. debug_vars "Command line options as set" codec extension mode container targetdir completedir auth_code @@ -266,6 +295,17 @@ if [[ "x${completedir}" != "x" ]]; then fi fi +# ----- +# Check whether the loglevel is valid +if [ "$((${loglevel} < 0 || ${loglevel} > 3 ))" = "1" ]; then + echo "ERROR loglevel has to be in the range from 0 to 3!" + echo " 0: Show progress only" + echo " 1: default" + echo " 2: a little more information, timestamps" + echo " 3: debug" + echo "$usage" + exit 1 +fi # ----- # If a compression level is given, check whether the given codec supports compression level specifiers and whether the level is valid. if [ "${level}" != "-1" ]; then @@ -441,16 +481,28 @@ do fi mkdir -p "${output_directory}" - # Fancy declaration of which book we are decoding. Including the AUTHCODE. - dashline="----------------------------------------------------" - log "$(printf '\n----Decoding---%s%s--%s--' "${title}" "${dashline:${#title}}" "${auth_code}")" - log "Source ${aax_file}" + if [ "$((${loglevel} > 0))" = "1" ]; then + # Fancy declaration of which book we are decoding. Including the AUTHCODE. + dashline="----------------------------------------------------" + log "$(printf '\n----Decoding---%s%s--%s--' "${title}" "${dashline:${#title}}" "${auth_code}")" + log "Source: ${aax_file}" + fi # Big long DEBUG output. Fully describes the settings used for transcoding. # Note this is a long debug command. It's not critical to operation. It's purely for people debugging # and coders wanting to extend the script. debug_vars "Book and Variable values" title auth_code mode aax_file container codec bitrate artist album_artist album album_date genre copyright narrator description publisher output_file metadata_file working_directory + # Display the total length of the audiobook in format hh:mm:ss + total_length="$(ffprobe -v error -activation_bytes "${auth_code}" -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ${aax_file} | cut -d . -f 1)" + hours="$((total_length/3600))" + if [ "$((hours<10))" = "1" ]; then hours="0$hours"; fi + minutes="$((total_length/60-60*hours))" + if [ "$((minutes<10))" = "1" ]; then minutes="0$minutes"; fi + seconds="$((total_length-3600*hours-60*minutes))" + if [ "$((seconds<10))" = "1" ]; then seconds="0$seconds"; fi + log "Total length: $hours:$minutes:$seconds" + # If level != -1 specify a compression level in ffmpeg. compression_level_param="" if [ "${level}" != "-1" ]; then @@ -484,14 +536,17 @@ do -metadata publisher="${publisher}" \ -f ${container} \ "${output_file}" - - log "Created ${output_file}." + if [ "$((${loglevel} > 0))" == "1" ]; then + log "Created ${output_file}." + fi # ----- fi # Grab the cover art if available. cover_file="${output_directory}/cover.jpg" if [ "${continue}" == "0" ]; then - log "Extracting cover into ${cover_file}..." + if [ "$((${loglevel} > 1))" == "1" ]; then + log "Extracting cover into ${cover_file}..." + fi 0))" == "1" ]; then + log "Creating PlayList ${title}.m3u" + fi echo '#EXTM3U' > "${playlist_file}" fi # Determine the number of chapters. chaptercount=$($GREP -Pc "Chapter.*start.*end" $metadata_file) - log "Extracting ${chaptercount} chapter files from ${output_file}..." - if [ "${continue}" == "1" ]; then - log "Continuing at chapter ${continueAt}:" + if [ "$((${loglevel} > 0))" == "1" ]; then + log "Extracting ${chaptercount} chapter files from ${output_file}..." + if [ "${continue}" == "1" ]; then + log "Continuing at chapter ${continueAt}:" + fi fi chapternum=1 + #start progressbar for loglevel 0 and 1 + if [ "$((${loglevel} < 2))" == "1" ]; then + progressbar 0 ${chaptercount} + fi # We pipe the metadata_file in read. # Example of the section that we are interested in: # @@ -559,7 +622,9 @@ do if [ "$((${continueAt} > ${chapternum}))" = "0" ]; then # Extract chapter by time stamps start and finish of chapter. # This extracts based on time stamps start and end. - log "Splitting chapter ${chapternum}/${chaptercount} start:${chapter_start%?}(s) end:${chapter_end}(s)" + if [ "$((${loglevel} > 1))" == "1" ]; then + log "Splitting chapter ${chapternum}/${chaptercount} start:${chapter_start%?}(s) end:${chapter_end}(s)" + fi 1))" == "1" ]; then + log "Added cover art to ${chapter_title}" + fi fi fi @@ -599,14 +669,21 @@ do # Clean up of working directory stuff. rm "${output_file}" - log "Done creating chapters for ${output_directory}." + if [ "$((${loglevel} > 1))" == "1" ]; then + log "Done creating chapters for ${output_directory}." + else + #ending progress bar + echo "" + fi else # Perform file tasks on output file. # ---- # Add the cover art to m4a and m4b file types. if [[ ${container} == "mp4" && $(type -P mp4art) ]]; then mp4art -q --add "${cover_file}" "${output_file}" - log "Added cover art to ${title}.${extension}" + if [ "$((${loglevel} > 1))" == "1" ]; then + log "Added cover art to ${title}.${extension}" + fi fi if [[ ${container} == "mp4" && $(type -P mp4chaps) ]]; then ffprobe -i "${aax_file}" -print_format csv -show_chapters 2>/dev/null | awk -F "," '{printf "CHAPTER%02d=%02d:%02d:%02.3f\nCHAPTER%02dNAME=%s\n", NR, $5/60/60, $5/60%60, $5%60, NR, $8}' > "${output_directory}/${title}.chapters.txt" @@ -616,14 +693,18 @@ do # ----- # Announce that we have completed the transcode - log "Complete ${title}" + if [ "$((${loglevel} > 0))" == "1" ]; then + log "Complete ${title}" + fi # Lastly get rid of any extra stuff. rm "${metadata_file}" # Move the aax file if the decode is completed and the --complete_dir is set to a valid location. # Check the target dir for if set if it is writable if [[ "x${completedir}" != "x" ]]; then - log "Moving Transcoded ${aax_file} to ${completedir}" + if [ "$((${loglevel} > 0))" == "1" ]; then + log "Moving Transcoded ${aax_file} to ${completedir}" + fi mv "${aax_file}" "${completedir}" fi From 7bef1bd5696d2b75b34af978c87745bbc3c53df2 Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Tue, 9 Feb 2021 20:05:43 +0100 Subject: [PATCH 12/15] Readme updated for loglevels --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ab3dd87..3bf9655 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level Date: Tue, 9 Feb 2021 20:19:53 +0100 Subject: [PATCH 13/15] Added different loglevels I added different loglevels and (for loglevel 0 and 1) a progress bar for chapter splitting. 0 = show progress only, chapter splitting shown as progress bar 1 (default) = fewer information, chapter splitting shown as progress bar 2 = as it has been up until now 3 = debug mode --- AAXtoMP3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index f642ac0..378088b 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -15,7 +15,7 @@ targetdir= # Optional output location. Note default is basedir completedir= # Optional location to move aax files once the decoding is complete. container=mp3 # Just in case we need to change the container. Used for M4A to M4B VALIDATE=0 # Validate the input aax file(s) only. No Transcoding of files will occur -loglevel=1 # Default off, If set extremely verbose output. +loglevel=1 # Loglevel: 0: Show progress only"; 1: default"; 2: a little more information, timestamps"; 3: debug" noclobber=0 # Default off, clobber only if flag is enabled continue=0 # Default off, If set Transcoding is skipped and chapter splitting starts at chapter continueAt. continueAt=1 # Optional chapter to continue splitting the chapters. From 6646b84e72bb45f4fac4fd8089c2be79c8f8d1d7 Mon Sep 17 00:00:00 2001 From: Nicko98 <39709875+Nicko98@users.noreply.github.com> Date: Tue, 9 Feb 2021 20:21:55 +0100 Subject: [PATCH 14/15] Added different loglevels I added different loglevels and (for loglevel 0 and 1) a progress bar for chapter splitting. 0 = show progress only, chapter splitting shown as progress bar 1 (default) = fewer information, chapter splitting shown as progress bar 2 = as it has been up until now 3 = debug mode --- AAXtoMP3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 378088b..4bc09bc 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -15,7 +15,7 @@ targetdir= # Optional output location. Note default is basedir completedir= # Optional location to move aax files once the decoding is complete. container=mp3 # Just in case we need to change the container. Used for M4A to M4B VALIDATE=0 # Validate the input aax file(s) only. No Transcoding of files will occur -loglevel=1 # Loglevel: 0: Show progress only"; 1: default"; 2: a little more information, timestamps"; 3: debug" +loglevel=1 # Loglevel: 0: Show progress only; 1: default; 2: a little more information, timestamps; 3: debug noclobber=0 # Default off, clobber only if flag is enabled continue=0 # Default off, If set Transcoding is skipped and chapter splitting starts at chapter continueAt. continueAt=1 # Optional chapter to continue splitting the chapters. From 36839646c47c262d1987178ee1f44036e8664c13 Mon Sep 17 00:00:00 2001 From: fabh2o Date: Wed, 10 Feb 2021 09:26:25 +0100 Subject: [PATCH 15/15] deleted empty line --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ba9cf7d..d736c0b 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,6 @@ bash AAXtoMP3 [-f|--flac] [-o|--opus] [-a|-aac] [-s|--single] [--level