diff --git a/.gitignore b/.gitignore index 71a9d6a..bc3dd24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ ACTIVATION .authcode +*aax +Audiobook/* diff --git a/AAXtoM4A b/AAXtoM4A deleted file mode 100755 index 7288d08..0000000 --- a/AAXtoM4A +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o noclobber -o nounset -o pipefail - -codec=copy -extension=m4a -mode=chaptered -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 AAXtoM4A [--single] AUTHCODE {FILES}" - exit 1 -fi - -if [[ "$1" == '--single' ]] -then - mode=single - shift -fi - -if [ ! -f .authcode ]; then - auth_code=$1 - shift -else - auth_code=`head -1 .authcode` -fi - -debug() { - echo "$(date "+%F %T%z") ${1}" -} - -trap 'rm -r -f "${working_directory}"' EXIT -working_directory=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'` -metadata_file="${working_directory}/metadata.txt" - -save_metadata() { - local media_file - media_file="$1" - ffprobe -i "$media_file" 2> "$metadata_file" -} - -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:]' ' ')" -} - -get_bitrate() { - get_metadata_value bitrate | $GREP --only-matching '[0-9]\+' -} - -normalize_whitespace() { - echo $* -} - -for path -do - debug "Decoding ${path} with auth code ${auth_code}..." - - save_metadata "${path}" - genre=$(get_metadata_value genre) - artist=$(get_metadata_value artist) - title=$(get_metadata_value title) - output_directory="$(dirname "${path}")/${genre}/${artist}/${title}" - mkdir -p "${output_directory}" - full_file_path="${output_directory}/${title}.${extension}" - - "$metadata_file" + debug "Metadata file $metadata_file" + debug_file "$metadata_file" } get_metadata_value() { @@ -135,9 +147,17 @@ do fi mkdir -p "${output_directory}" full_file_path="${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)" + + # Big long DEBUG output. Fully describes the settings used for transcoding. I could probably do this better. + debug "$(printf '\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %sn%-18s: %s' title "${title}" auth_code "${auth_code}" mode "${mode}" path "${path}" codec "${codec}" bitrate "${bitrate}" artist "${artist}" album_artist "${album_artist}" album "${album}" album_date "${album_date}" genre "${genre}" copyright "${copyright}" full_file_path "${full_file_path}" metadata_file "${metadata_file}" working_directory "${working_directory}" )" # This is the primary transcode. All the heavy lifting is here. - ] [-o|--output_dir ] ... -bash AAXtoM4A [AUTHCODE] ... bash AAXtoM4B [AUTHCODE] ... ```