Skip to content
This repository has been archived by the owner on Apr 3, 2021. It is now read-only.

Commit

Permalink
Add updated example for downloading books
Browse files Browse the repository at this point in the history
  • Loading branch information
omarroth committed Aug 5, 2019
1 parent 48735b0 commit 4dc27da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,27 @@ content_url = JSON.parse(client.post("/1.0/content/B002V0QUOC/licenserequest", b
```

**Note**: `content_url` is now provided in `.aaxc` format, which ffmpeg does **not** currently support, see [mkb79/Audible#3](https://github.com/mkb79/Audible/issues/3). For now you can use the following to get files in `.aax` format:

```crystal
require "audible"
asin = "some_asin"
codec = "some_codec" # Desired quality from /1.0/library/{asin}?response_groups=product_attrs,relationships
client = Audible::Client.from_json(File.read("session.json"))
request = HTTP::Request.new("GET", "/FionaCDEServiceEngine/FSDownloadContent?type=AUDI&currentTransportMethod=WIFI&key=#{asin}&codec=#{codec}")
request = client.sign_request(request)
tld = Audible::LOCALES[client.locale]["AUDIBLE_API"].to_s.split("api.audible.")[1]
content_url = HTTP::Client.new(URI.parse("https://cde-ta-g7g.amazon.com")).exec(request)
.headers["Location"].gsub("https://cds.audible.com", "https://cds.audible.#{tld}") # => https://cds.audible.com/download...
# `content_url` can then be downloaded using any tool
```

Assuming you have your activation bytes, you can convert .aax into another format with the following:

```
Expand Down
2 changes: 1 addition & 1 deletion src/audible.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module Audible
def self.from_json(body : Hash(String, JSON::Any))
client = new

client.login_cookies = Hash.zip(body["login_cookies"].as_h.keys, body["login_cookies"].as_h.values.map { |value| value.as_s })
client.login_cookies = body["login_cookies"].as_h.transform_values { |value| value.as_s }
client.adp_token = body["adp_token"].as_s
client.access_token = body["access_token"].as_s
client.refresh_token = body["refresh_token"].as_s
Expand Down

0 comments on commit 4dc27da

Please sign in to comment.