mkb79 / audible-cli

A command line interface for audible package. With the cli you can download your Audible books, cover, chapter files.
GNU Affero General Public License v3.0
451 stars 46 forks source link

Get voucher (activation_bytes) for aaxc. #136

Open nospam2k opened 1 year ago

nospam2k commented 1 year ago

I'm sorry for asking for a how to but I have seen bits and pieces about using api to get activation_bytes for aaxc. It seems that aaxc files have per file activation_bytes. Can you please direct me to the proper command line for getting the activation_bytes for aaxc for a specific audio book in my library?

Thank you and again, sorry for using this for a how to but I'm running out of options online.

mkb79 commented 1 year ago

Here you can find the code to make a licenserequest and decrypting the license.

nospam2k commented 1 year ago

Thanks for that. I'm having a hard time trying to translate that into how to provide command line parameters. I would appreciate it if you could provide an example command line using audible-cli. Thanks!

mkb79 commented 1 year ago

When you download an aaxc book with audible-cli the voucher file is automatically downloaded. Or do you want the voucher file only?

nospam2k commented 1 year ago

Yes, I just want the voucher file. Thank you. I have a script that just runs ffmpeg against a folder of aax files that uses the activation_bytes I grabbed from a different script. This works fine for aax. I only recently found out that aaxc uses a per book activation_bytes so I just want to store those codes separately per book. I ran into a problem where something went wrong with Audible and a book I had downloaded was no longer available, but I still had the aaxc file on my phone. I had been trying to figure out how to get the aaxc activation_bytes when I ran across your code. Fortunately, in the mean time, Audible was able to fix the problem but I want to be able to be sure and have all the aaxc activation_bytes for safe keeping.

mkb79 commented 1 year ago

Aaxc files make use of a key/iv pair to decrypt the book. The key/iv pair is responded with a licenserequest. But the key/iv pair is encrypted. For decrypting the key/iv pair you need the device serial and other stuff (look here). So the key/iv is unique for every book, account and device. audible-cli creates a virtual device for this. So I does not know if you can use these key/iv with books downloaded from another source/app.

You can test these out by downloading an aaxc book with my app. You can abort the progress after the voucher is saved - you don’t need the aaxc file for this to finish. Then use the key/iv with your other already downloaded book.

lchiocca commented 11 months ago

Just as a side note: If you have the voucher and the aaxc files, the you can simply use ffmpeg to decrypt the aaxc as follows: ffmpeg -y -audible_key {voucher.content_license.license_response.key} -audible_iv {voucher.content_license.license_response.iv} -i {filepath.aaxc} -c copy -map 0 {filepath.mp4} "-y" to allow overwriting the target / "audible_key/audible_iv" are the decryption key and the initialization vector / "-i" is the input aaxc file / "-c copy" will tell ffmpeg to not reencode / "-map 0" will take over all the streams from the aaxc file

M05QU170 commented 10 months ago

ffmpeg -y -audible_key {voucher.content_license.license_response.key} -audible_iv {voucher.content_license.license_response.iv} -i {filepath.aaxc} -c copy -map 0 {filepath.mp4}

It feels like it is part of script. How does beginning and ending looks like?

mkb79 commented 10 months ago

@M05QU170 If you use audible-cli you have to replace:

  1. {voucher.content_license.license_response.key} with the key value from the voucher file.
  2. {voucher.content_license.license_response.iv} with the iv value from the voucher file
  3. {filepath.aaxc} with the file path of the downloaded aaxc file.
  4. {filepath.mp4} with the file path of the target (decrypted) file.

Please ignore the leading { and trailing }!

But you can use this script for `audible-cli too. This will make the work for you.

M05QU170 commented 10 months ago

@M05QU170 If you use audible-cli you have to replace:

1. {voucher.content_license.license_response.key} with the `key` value from the voucher file.

2. {voucher.content_license.license_response.iv} with the `iv` value from the voucher file

3. {filepath.aaxc} with the file path of the downloaded aaxc file.

4. {filepath.mp4} with the file path of the target (decrypted) file.

Please ignore the leading { and trailing }!

But you can use this script for `audible-cli too. This will make the work for you.

Thank you, I have checked it, it's working very well. Just quick question why there is chapter intergration work going on? If converting from aax/aaxc to m4b all it needs to pass "-c copy" flag to ffmpeg.

mkb79 commented 10 months ago

Just quick question why there is chapter intergration work going on? If converting from aax/aaxc to m4b all it needs to pass "-c copy" flag to ffmpeg.

If you use ffmpeg this way, the chapter information from the aaxc file are taken. Often this will result in chapter names like Chapter 1, Chapter 2 and so on. The Audible app for iOS and Android will display you more detailed chapter names, because they take the chapter information from the API and not from the file. Therefore audible-cli will let you download chapter information from the API too. You can now manually integrate this information in your final m4b file or you can use my decrypt plugin for this purpose.