audiamus / BookLibConnect

A standalone Audible downloader and decrypter
GNU General Public License v3.0
672 stars 38 forks source link

Download formats #91

Closed wjabrams closed 1 year ago

wjabrams commented 1 year ago

Why are you converting into m4b files with no chapters and downloading aaxc files instead of aax files which even your old program won't decrypt?

audiamus commented 1 year ago

Since this is basically a question, I will move this topic to the Discussions section.

Originally Audible produced encrypted MP3 files which they fitted with file type .aa. Around 15 years ago they switched to audio-only MP4 containers and named them .aax. The audio stream became AAC, the de-facto standard for MP4. They encrypt the audio stream using standard and widespread AES, but the meta data, including chapters, adheres to the MP4 specs, with some proprietary tags added. There are two different chapter specs for MP4, I never seem to remember which is which, and Audible picked one of the two.

AES (Advanced Encryption Standard), which they apply to the audio stream, has a few options and the one used by Audible allows hardware accelerated decryption by most CPUs, desktop and mobile. The weakness with .aax, at least in Audible's eyes, was the poor key they applied to encrypt AES. This could be easily cracked with a brute force approach. So they switched to a much more sophisticated key/seed combination later, individually created for each user/book combination. They call these files .aaxc on their official apps for mobile devices. But it's still MP4, the audio stream still AAC and the encryption still AES. But you'll need the key for .aaxc, you can't break it.

So, why downloading .aaxc then? Because that's the most convenient way to do it. All the modern 3rd party apps that download directly from Audible servers make use of the same Audible web API as the official Audible apps for mobile devices. This API also hands out the individual keys for each book in form of a so-called voucher. The Open Source community has figured out and documented the essentials of the API and provided kind of reference implementations. .aax, on the other hand, is no longer really featured in this API, treated as legacy.

.m4b and .m4a are simply naming conventions for audio-only MP4 containers. .m4a is the older one, with the a presumably standing for "audio", nowadays mostly used to indicate music. .m4b is the newer one with the b pointing to (audio)-"book". So basically, .m4a, .m4b, .aax and .aaxc are all the same file format, with .aax and .aaxc having AES encrypted audio. However, aax may also contain plain audio, as it does when exported by Book Lib Connect.

Chapters: MP4 supports embedded chapter meta data in two variants. Audible .aaxc uses one of them. Book Lib Connect does not look at or touch any meta data. It simply delegates the entire audio stream to another brilliant Open Source library to decrypt it and saves the result as a now plain audio .mb4 file, all meta data intact, including the chapters.

Many multimedia players recognize both MP4 chapter variants but some do not. With such a player, the .m4b file could appear as being chapter-less.

There is more to chapters, though. The embedded chapters featured only chapter numbers in Audible books, never explicit names, even if present in the book text source. (It has changed recently, some new publications now come with full chapter titles). Apparently to compensate for this shortcoming, the Audible web API offers separate chapter data, independent of the MP4 container. For certain books, these external chapters come with full chapter names, albeit sometimes at the cost of inaccurate chapter marks. Often, however, the extra chapter data is the same as the embedded and mere numbers.

The export function in Book Lib Connect does two things:

  1. It renames the .m4b file to .aax which allows AAX Audio Converter to read it for further processing.
  2. It reformats the extra chapter data and saves it as a .json file, again to allow AAX Audio Converter to read and process it.

If enabled in the settings, AAX Audio Converter will process the extra chapters and merge them with the embedded chapters. In any case, the final .m4b (or .m4a) file(s) will have have embedded chapters in both(!) variants, thanks to yet another smart Open Source library. If you prefer MP3, you will even have MP3 embedded chapters, although very few MP3 players can read them. The great MPC-HC is a positive exception.

AAX Audio Converter will also replace Audible proprietary meta tags with standard ones.