Updated grep detection with README changes and better colon support

This commit is contained in:
KrumpetPirate 2017-10-12 20:27:04 -05:00
parent c500062c96
commit 1017f9a6e7
2 changed files with 12 additions and 5 deletions

View File

@ -5,7 +5,14 @@ set -o errexit -o noclobber -o nounset -o pipefail
codec=libmp3lame codec=libmp3lame
extension=mp3 extension=mp3
mode=chaptered 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 if [ "$#" -eq 0 ]; then
echo "Usage: bash AAXtoMP3.sh [--flac] [--single] AUTHCODE {FILES}" echo "Usage: bash AAXtoMP3.sh [--flac] [--single] AUTHCODE {FILES}"
@ -49,11 +56,11 @@ save_metadata() {
get_metadata_value() { get_metadata_value() {
local key local key
key="$1" 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_bitrate() {
get_metadata_value bitrate | grep --only-matching '[0-9]\+' get_metadata_value bitrate | $GREP --only-matching '[0-9]\+'
} }
normalize_whitespace() { normalize_whitespace() {
@ -61,7 +68,7 @@ normalize_whitespace() {
} }
chapter_padding() { 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 ]] if [[ $chaptercount -gt 9 && $chaptercount -lt 100 ]]
then then
chapter=$(sed -e 's/Chapter \([[:digit:]]\)$/Chapter 0\1/' <<<$chapter) chapter=$(sed -e 's/Chapter \([[:digit:]]\)$/Chapter 0\1/' <<<$chapter)

View File

@ -24,7 +24,7 @@ can obtain this string from a tool like [audible-activator](https://github.com/i
## OSX ## OSX
Thanks to thibaudcolas, this script has been tested on OSX 10.11.6 El Capitan. YMMV, but it should work for 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 ## 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. 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.