ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
132.61k stars 10.05k forks source link

Audible support #28317

Open nullbasis opened 3 years ago

nullbasis commented 3 years ago

Checklist

Example URLs

Description

Username and password would be required to download books. Since Audible only supports listening to books in the browser or in an app, it would be incredible if yt-dl could download one's purchases.

I'm not sure which of the above example links would be better as input. The latter is the page where the book plays directly, but the former is more obviously accessible to the average user.

nullbasis commented 3 years ago

Honestly, if it would help, I'd be willing to buy and gift some cheap book to someone who could do the dev work.

babbittw commented 3 years ago

I use Audible a good amount. I'll take a shot at it.

DerZyklop commented 2 years ago

Maybe interesting here: Some people who know how to find a specific network request with devTools downloaded stuff with youtube-dl.

https://forum.videohelp.com/threads/396514-Downloading-audio-from-stories-audible-com

They wrote that the links to audio files expire qickly (~60 seconds).

I did not have any luck with that, because i had an Error 403 no matter how fast i did it.

nullbasis commented 2 years ago

I also keep getting 403 errors with the method in that forum post. Amazon must have "fixed" things since then.

89z, an API would be great!

LinusU commented 1 year ago

This could probable help:

https://github.com/openaudible/openaudible/blob/34a305bd384c1918b3ef12b917aab53aed30aa74/src/main/java/org/openaudible/download/DownloadJob.java#L70-L84

For me, clicking "Download" on the Audible site is basically useless unless my internet connection is super stable. Since I'm currently out traveling in Asia it never is, and thus I have been having a really hard time getting my books. I manage to use curl with the continue-flag to resume my transfer, and trying repeatedly seems to make progress!

curl \
  -C - \
  -o my-book.aax \
  "https://cds.audible.com/download?user_id=$USERID&product_id=$SKU&codec=LC_128_44100_Stereo&awtype=AAX&cust_id=$USERID" \
  --header 'User-Agent: Audible ADM 6.6.0.19;Windows Vista  Build 9200'

I managed to find my $USERID by having the developer console open whilst trying to download the file from the Audible site, and the $SKU can be found in the source for the page of the book e.g:

Screenshot 2023-03-16 at 11 05 54
LinusU commented 1 year ago

I just published a little tool that downloads, and most importantly, retries on each lost connection 🎉

https://github.com/LinusU/audible-dl

dirkf commented 1 year ago

The tool implements https://github.com/ytdl-org/youtube-dl/issues/28317#issuecomment-1471274712.

As this solution is to populate

https://cds.audible.com/download?user_id={USERID}&product_id={SKU}&codec=LC_128_44100_Stereo&awtype=AAX&cust_id={USERID}

an extractor has to find USERID and SKU. The regional page https://www.audible.co.uk/pd/The-Invasion-Audiobook/1338641158, non-JS, not logged in, has the SKU value in a JS assignment matching "sku": "(.+)".

Possibly if logged-in cookies were sent the .member of the JS object would also be set with the USERID value.

For a URL like https://www.audible.com/webplayer?asin=1338641158, the SKU isn't available: perhaps rewrite the URL using the regional domain: apparently even this works:

https://www.audible.co.uk/pd/whatever-Audiobook/1338641158
ghost commented 1 year ago

this appears to download AAX files, which are encrypted:

https://wikipedia.org/wiki/Audible_(service)#Quality

if thats the case, I believe that is explicitly an anti-feature of YouTube-DL. @LinusU, do you have some reason to believe these are unencrypted files?

LinusU commented 1 year ago

@4cq2 yes, they are encrypted. I should probably say that I just threw this tool together quickly to solve my particular problem right now: I can't download this specific audiobook on the internet connection I'm on right now.

It's clunky to use for sure since you need to know your customer_id, and the sku of the book.

In order to actually listen to the book, I'm using the instructions here: https://gist.github.com/r15ch13/0c548be006431607bf1eaecefdc0591a?permalink_comment_id=2800421#gistcomment-2800421

I once extracted my activation bytes from a Windows computer and have saved it in 1Password, so for me personally this is really easy.


It would be great with a PR to this repo that does all of the things: 1) variable extraction from url + login or cookies, 2) download the AAX file, and finally 3) decrypt it using ffmpeg. Ultimately, I only had an hour to spare on this, and I like Rust very much, so I did a separat tool that only solved my problem...


Possibly if logged-in cookies were sent the .member of the JS object would also be set with the USERID value.

@dirkf this is very interesting! Unfortunately, it doesn't seem to work for me though, member is an empty object in the source served to me when logged in. Maybe this has something to do with my membership not being active though 🤔 (that is, I'm not currently on an active plan)

Screenshot 2023-03-18 at 10 48 26

(e.g. https://www.audible.com/pd/The-Hobbit-Dramatised-Audiobook/B002VA91WK)

ghost commented 1 year ago

@LinusU decrypting media is typically an anti-feature of YouTube-DL. which means that any issues or pull requests discussing that are usually closed on those grounds. The line is somewhat blurry, as stuff like Widevine is explicitly not allowed, while other stuff like HLSe is allowed. this seems to pull a static key from the registry, which seems like it might be OK, in regards to the nebulous YouTube-DL rules.

YouTube-DL already can accept an argument that gets passed to FFmpeg, so that would apply here with -activation_bytes. I dont think it should be YouTube-DL job to go digging into a users registry, just like I dont think it should be YouTube-DL job to go digging into a users cookies, but I guess that ship has sailed, so who knows. I will be interested to see how a maintainer views this issue.

dirkf commented 1 year ago

If all that's needed is to pass a "password" available to a properly authenticated user to ffmpeg, that's fine. The "live reenactment" shown here won't happen.

ghost commented 1 year ago

The "live reenactment" shown here won't happen.

with version L3 (as detailed in that article), the CDM is not "looked inside of", but rather the ClientId bytes are used as part of the license request/response process. However, I get your point.