:::cs
=== About
>How to convert the proprietary aax-audiobook format from Audible to mp3

[!ref icon="git-branch" text="inAudible-NG/tables Github Repo"](https://github.com/inAudible-NG/tables.git)  
[!ref icon="git-branch" text="aax2mp3 Bitbucket Repo"](https://bitbucket.org/kleberj/aax2mp3.git)  
[!ref icon="git-branch" text="audible-cli Bitbucket Repo"](https://github.com/mkb79/audible-cli)  

===
## Download entire Audible library
With the `audible-cli` package you can easily download your entire library.  
Install the package according to the README.md and follow the quickstart:  

### 🚀 Quickstart

1. Run the interactive setup:

   ```shell
   audible quickstart
   ```

   → creates config, profile, and auth file.

2. List your library:

   ```shell
   audible library list
   ```

3. Download your entire library to the current directory:

   ```shell
   audible download --all --aax
   ```

## First time setup
To convert your aax-files, you'll need your personal authentification token.  
To obtain it, first download an audiobook from your Audible library.  
Now clone the inAudible-NG/tables repository and enter the directory:  
~~~sh
git clone https://github.com/inAudible-NG/tables.git
cd tables
~~~
Next calculate the checksum of your aax-file with `ffmpeg` and use `rcrack.sh` from the tables repository to get the authentification token:  
~~~sh
ffprobe -i /path/to/your/file.aax 2>&1 | awk '/checksum/{print $NF}' 
# you get something like 999a6ab8...
./rcrack . -h 999a6ab8...
# statistics
# -------------------------------------------------------
# plaintext found:                              1 of 1
# total time:                                   13.98 s
# [...]
# result
# ----------------------------------------------------------------
# 999a6ab8...  \xa5\xd0Y1  hex:CAFED00D
~~~
Your personal authentification token can be found after "hex:", so in the above example `CAFED00D`.  
Store this token in your \*rc.file as `export AAX2MP3_AUTHCODE=CAFED00D` (or when using fish with `set -Ux AAX2MP3_AUTHCODE CAFED00D`).  

As the last preparation step, clone the aax2mp3 Bitbucket repository and copy the binary to your `.local/bin` directory:  
~~~sh
cd /tmp
git clone https://bitbucket.org/kleberj/aax2mp3.git
cd aax2mp3
cp aax2mp3 ~/.local/bin/aax2mp3
chmod u+x ~/.local/bin/aax2mp3
~~~

Logout and login again, to make the binary available. 

## Convert your audiobooks
~~~sh
aax2mp3 -i /path/to/your/file.aax
~~~  
This converts the given file in the current directory and splits the chapters in single files.  
To create a single mp3 file instead, use:  
~~~sh
aax2mp3 -S -i test.aax 
~~~

## Extract cover and add it to the files (optional)  
To add the cover to the files, you'll need a tool like `eyeD3`, so make sure to install it first.  

First enter the regarding audiobook directory and extract the cover from the first file using `ffmpeg`:
~~~sh
cd /path/to/the/converted/audiobook
ffmpeg -i chapter1.mp3 Cover.jpg
~~~

Now add it to the remaining chapter files with `eyeD3`:
~~~sh
eyeD3 *.mp3 --add-image=Cover.jpg:FRONT_COVER
~~~

:::
