From 2fc7329bf5d64e39a7def6cf977217d8222674b7 Mon Sep 17 00:00:00 2001 From: cb1 Date: Fri, 20 Oct 2017 14:44:32 +0200 Subject: [PATCH] Update of chapter titles with sortable 0padded numbers * Removed chapter_padding() * Fixed $chaptercount * Redone 0-padded chapter titles with printf() --- AAXtoMP3 | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 4369991..9b8f872 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -67,18 +67,6 @@ 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}..." @@ -96,17 +84,19 @@ do debug "Created ${full_file_path}." if [ "${mode}" == "chaptered" ]; then - debug "Extracting chapter files from ${full_file_path}..." + chaptercount=$($GREP -Pc "Chapter.*start.*end" $metadata_file) + debug "Extracting ${chaptercount} chapter files from ${full_file_path}..." + chapternum=1 while read -r -u9 first _ _ start _ end do if [[ "${first}" = "Chapter" ]] then read -r -u9 _ read -r -u9 _ _ chapter - chapter_padding - chapter_file="${output_directory}/${title} - ${chapter}.${extension}" + chapter_file="${output_directory}/${title} - $(printf %0${#chaptercount}d $chapternum) ${chapter}.${extension}"