From ee01461f9a549fe53e4ec31d66b6cdb5589636b6 Mon Sep 17 00:00:00 2001 From: Jens Date: Wed, 6 Sep 2017 19:39:02 +0200 Subject: [PATCH] Added chapter padding As discussed in https://github.com/KrumpetPirate/AAXtoMP3/issues/26 I've added a quick and dirty fix to add chapter padding (for audio books containing up to 999 chapters) for non-single conversion mode. --- AAXtoMP3 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/AAXtoMP3 b/AAXtoMP3 index f482b51..731281e 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -59,6 +59,18 @@ normalize_whitespace() { echo $* } +chapter_padding() { + chaptercount=$(grep -Pc "title\s+:\sChapter\s\d+" $metadata_file) + if [[ $chaptercount -gt 9 && $chaptercount -lt 100 ]] + then + chapter=$(sed -e 's/Chapter \([[:digit:]]\)$/Chapter 0\1/' <<<$chapter) + elif [[ $chaptercount -gt 99 && $chaptercount -lt 999 ]] + then + chapter=$(sed -e 's/Chapter \([[:digit:]]\)$/Chapter 00\1/' <<<$chapter) + chapter=$(sed -e 's/Chapter \([[:digit:]]\{2\}\)$/Chapter 0\1/' <<<$chapter) + fi +} + for path do debug "Decoding ${path} with auth code ${auth_code}..." @@ -84,6 +96,7 @@ do then read -r -u9 _ read -r -u9 _ _ chapter + chapter_padding chapter_file="${output_directory}/${title} - ${chapter}.${extension}"