mirror of
https://github.com/KrumpetPirate/AAXtoMP3.git
synced 2025-07-09 20:37:30 +02:00
Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
219255826b | |||
ee0c971544 | |||
a691b5fd54 | |||
db014f8f51 | |||
1d1f738713 | |||
120f02fe07 | |||
2ae7e326bb | |||
e3d9a9ea35 | |||
15945b18b1 | |||
1031e3ae1d | |||
626bab226a | |||
83e83d959f | |||
d7752b4779 | |||
0c2c439d55 | |||
ed084692a2 | |||
da3ca76930 | |||
a09e502574 | |||
1132602f65 | |||
de01589b94 | |||
972123a932 | |||
1ac66d1a94 | |||
15abb34c0e | |||
6c33459f24 | |||
f06b768c55 | |||
2fc7329bf5 | |||
f7c4d0dce8 | |||
1017f9a6e7 | |||
c500062c96 | |||
05274634d4 | |||
240068be87 | |||
ee01461f9a | |||
8002baf1c5 | |||
56b6b6ad98 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
ACTIVATION
|
||||
.authcode
|
||||
*aax
|
||||
Audiobook/*
|
||||
|
87
AAXtoMP3
87
AAXtoMP3
@ -5,9 +5,21 @@ set -o errexit -o noclobber -o nounset -o pipefail
|
||||
codec=libmp3lame
|
||||
extension=mp3
|
||||
mode=chaptered
|
||||
authcode=".authcode";
|
||||
if [ -z ${HOME+x} ] && ! [ -z ${USERPROFILE+x} ]; then HOME="$USERPROFILE"; fi
|
||||
authcodeDirs="${HOME}/ ./"
|
||||
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}"
|
||||
echo "Usage: bash AXtoMP3 [--flac] [--aac] [--opus ] [--single] AUTHCODE {FILES}"
|
||||
echo " Note that order does matter!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -18,18 +30,47 @@ then
|
||||
shift
|
||||
fi
|
||||
|
||||
if [[ "$1" == '--aac' ]]
|
||||
then
|
||||
codec=copy
|
||||
extension=m4a
|
||||
mode=single
|
||||
shift
|
||||
fi
|
||||
|
||||
if [[ "$1" = '--opus' ]]
|
||||
then
|
||||
codec=libopus
|
||||
extension=ogg
|
||||
shift
|
||||
fi
|
||||
|
||||
if [[ "$1" == '--single' ]]
|
||||
then
|
||||
mode=single
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ ! -f .authcode ]; then
|
||||
auth_code="";
|
||||
for dir in $authcodeDirs; do
|
||||
codeFile="${dir}$authcode";
|
||||
|
||||
if [ ! -f "$codeFile" ]; then
|
||||
auth_code=$1
|
||||
shift
|
||||
else
|
||||
auth_code=`head -1 .authcode`
|
||||
fi
|
||||
break;
|
||||
elif [ -s "$codeFile" ]; then
|
||||
auth_code=`head -1 "$codeFile"`
|
||||
break;
|
||||
else
|
||||
echo "INFO: Sorry, empty \"$codeFile\" found, skipping.";
|
||||
fi;
|
||||
done;
|
||||
|
||||
if [ -z "$auth_code" ]; then
|
||||
echo "INFO: Sorry, no authcode provided.";
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
debug() {
|
||||
echo "$(date "+%F %T%z") ${1}"
|
||||
@ -48,11 +89,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() {
|
||||
@ -66,7 +107,7 @@ do
|
||||
save_metadata "${path}"
|
||||
genre=$(get_metadata_value genre)
|
||||
artist=$(get_metadata_value artist)
|
||||
title=$(get_metadata_value title)
|
||||
title=$(get_metadata_value title | sed 's/'\:'/'-\ '/g' | xargs -0)
|
||||
output_directory="$(dirname "${path}")/${genre}/${artist}/${title}"
|
||||
mkdir -p "${output_directory}"
|
||||
full_file_path="${output_directory}/${title}.${extension}"
|
||||
@ -75,26 +116,42 @@ do
|
||||
|
||||
debug "Created ${full_file_path}."
|
||||
|
||||
if [ "${mode}" == "chaptered" ]; then
|
||||
debug "Extracting chapter files from ${full_file_path}..."
|
||||
cover_path="${output_directory}/cover.jpg"
|
||||
debug "Extracting cover into ${cover_path}..."
|
||||
</dev/null ffmpeg -loglevel error -activation_bytes "${auth_code}" -i "${path}" -an -codec:v copy "${cover_path}"
|
||||
|
||||
if [ "${mode}" == "chaptered" ]; then
|
||||
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_file="${output_directory}/${title} - ${chapter}.${extension}"
|
||||
</dev/null ffmpeg -loglevel error -stats -i "${full_file_path}" -ss "${start%?}" -to "${end}" -codec:a copy -metadata track="${chapter}" "${chapter_file}"
|
||||
chapter_title="${title} - $(printf %0${#chaptercount}d $chapternum) ${chapter}"
|
||||
chapter_file="${output_directory}/${chapter_title}.${extension}"
|
||||
|
||||
# the ID3 tags must only be specified for *.mp3 files,
|
||||
# the other container formats come with their own
|
||||
# tagging mechanisms.
|
||||
id3_version_param=""
|
||||
if test "${extension}" = "mp3"; then
|
||||
id3_version_param="-id3v2_version 3"
|
||||
fi
|
||||
|
||||
</dev/null ffmpeg -loglevel error -stats -i "${full_file_path}" -i "${cover_path}" -ss "${start%?}" -to "${end}" -map 0:0 -map 1:0 -acodec copy ${id3_version_param} \
|
||||
-metadata:s:v title="Album cover" -metadata:s:v comment="Cover (Front)" -metadata track="${chapternum}" -metadata title="${chapter_title}" \
|
||||
"${chapter_file}"
|
||||
chapternum=$((chapternum + 1 ))
|
||||
fi
|
||||
done 9< "$metadata_file"
|
||||
rm "${full_file_path}"
|
||||
debug "Done creating chapters. Chaptered files contained in ${output_directory}."
|
||||
fi
|
||||
|
||||
cover_path="${output_directory}/cover.jpg"
|
||||
debug "Extracting cover into ${cover_path}..."
|
||||
</dev/null ffmpeg -loglevel error -activation_bytes "${auth_code}" -i "${path}" -an -codec:v copy "${cover_path}"
|
||||
debug "Done."
|
||||
rm "${metadata_file}"
|
||||
done
|
||||
|
22
README.md
22
README.md
@ -24,33 +24,21 @@ 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.
|
||||
|
||||
## Usage
|
||||
```
|
||||
bash AAXtoMP3 <AUTHCODE> {INPUT_FILES}
|
||||
```bash
|
||||
bash AAXtoMP3 [--flac] [--aac] [--opus] [--single] AUTHCODE {FILES}
|
||||
```
|
||||
* AUTHCODE: **your** Audible auth code (it won't correctly decode otherwise) (required)
|
||||
* Everything else is considered an input file, useful for batching!
|
||||
|
||||
You can also convert the output to FLAC encoding instead of MP3 by doing the following *in order*:
|
||||
```
|
||||
bash AAXtoMP3 --flac <AUTHCODE> {INPUT_FILES}
|
||||
```
|
||||
Note that FLAC encoding is typically a little faster, at the cost of compatibility with some players.
|
||||
Note that any optional flags have to be inputed *in order* to function correctly.
|
||||
|
||||
If you wish to convert to a single file you can add --single to the input. This will prevent chaptered content from being extracted.
|
||||
|
||||
Additionally, if you have a .authcode file available in the current working directory, it will read the first line of
|
||||
that line and treat it like your auth_code. When you do this you do not need to specify an AUTHCODE input.
|
||||
|
||||
Here is the full usage (NOTE: Order matters!)
|
||||
```
|
||||
bash AAXtoMP3 [--flac] [--single] AUTHCODE {FILES}
|
||||
```
|
||||
Additionally, if you have a .authcode file available in either your home directory or the current working directory, it will read the first line of that line and treat it like your auth_code. When you do this you do not need to specify an AUTHCODE input.
|
||||
|
||||
## Anti-Piracy Notice
|
||||
Note that this project does NOT ‘crack’ the DRM. It simply allows the user to
|
||||
|
1
_config.yml
Normal file
1
_config.yml
Normal file
@ -0,0 +1 @@
|
||||
theme: jekyll-theme-slate
|
Reference in New Issue
Block a user