diff --git a/AAXtoMP3 b/AAXtoMP3 index 09176ed..4369991 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -5,7 +5,14 @@ set -o errexit -o noclobber -o nounset -o pipefail codec=libmp3lame extension=mp3 mode=chaptered -grep=$(grep --version | grep -q GNU && echo "grep" || echo "ggrep") +GREP=$(grep --version | grep -q GNU && echo "grep" || echo "ggrep") + +if ! [[ $(type -P "$GREP") ]]; then + echo "$GREP (GNU grep) is not in your PATH" + echo "Without it, this script will break." + echo "On macOS, you may want to try: brew install grep" + exit 1 +fi if [ "$#" -eq 0 ]; then echo "Usage: bash AAXtoMP3.sh [--flac] [--single] AUTHCODE {FILES}" @@ -49,11 +56,11 @@ save_metadata() { get_metadata_value() { local key key="$1" - normalize_whitespace "$(grep --max-count=1 --only-matching "${key} *: .*" "$metadata_file" | cut -d : -f 2 | sed -e 's#/##g;s/ (Unabridged)//' | tr -s '[:blank:]' ' ')" + normalize_whitespace "$($GREP --max-count=1 --only-matching "${key} *: .*" "$metadata_file" | cut -d : -f 2- | sed -e 's#/##g;s/ (Unabridged)//' | tr -s '[:blank:]' ' ')" } get_bitrate() { - get_metadata_value bitrate | grep --only-matching '[0-9]\+' + get_metadata_value bitrate | $GREP --only-matching '[0-9]\+' } normalize_whitespace() { @@ -61,7 +68,7 @@ normalize_whitespace() { } chapter_padding() { - chaptercount=$(grep -Pc "title\s+:\sChapter\s\d+" $metadata_file) + 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) diff --git a/README.md b/README.md index 96c1103..dd07450 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ can obtain this string from a tool like [audible-activator](https://github.com/i ## OSX Thanks to thibaudcolas, this script has been tested on OSX 10.11.6 El Capitan. YMMV, but it should work for -conversions in OSX. +conversions in OSX. It is recommended that you install GNU grep using 'brew install grep' for chapter padding to work. ## AUR Thanks to kbabioch, this script has also been packaged in the [AUR](https://aur.archlinux.org/packages/aaxtomp3-git/). Note that you will still need to extract your activation bytes before use.