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

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
omarroth committed Jun 16, 2019
1 parent 85e942e commit 6738f44
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,20 @@ Responses will often provide very little info without `response_groups` specifie

- num_results: \\d+ (max: 1000)
- page: \\d+
- response_groups: [badge_types, category_ladders, claim_code_url, contributors, is_downloaded, is_finished, is_returnable, media, origin_asin, pdf_url, percent_complete, price, product_attrs, product_desc, product_extended_attrs, product_plan_details, product_plans, provided_review, rating, relationships, review_attrs, reviews, sample, series, sku]
- purchased_after: [RFC3339](https://tools.ietf.org/html/rfc3339) (e.g. `2000-01-01T00:00:00Z`)
- response_groups: [badge_types, category_ladders, claim_code_url, contributors, is_downloaded, is_returnable, media, origin_asin, pdf_url, percent_complete, price, product_attrs, product_desc, product_extended_attrs, product_plan_details, product_plans, provided_review, rating, relationships, review_attrs, reviews, sample, series, sku]
- sort_by: [-Author, -Length, -Narrator, -PurchaseDate, -Title, Author, Length, Narrator, PurchaseDate, Title]

### GET /1.0/library/%{asin}

- response_groups: [badge_types, category_ladders, claim_code_url, contributors, is_downloaded, is_returnable, media, origin_asin, pdf_url, percent_complete, price, product_attrs, product_desc, product_extended_attrs, product_plan_details, product_plans, provided_review, rating, relationships, review_attrs, reviews, sample, series, sku]

### POST(?) /1.0/library/item

- asin:

### POST(?) /1.0/library/item/%s/%s

### GET /1.0/wishlist

- num_results: \\d+ (max: 50)
Expand Down Expand Up @@ -240,9 +251,19 @@ For a succesful request, returns JSON body with `content_url`.
- continuation_token:
- image_sizes:

### GET /1.0/stats/aggregates

- daily_listening_interval_duration: ([012]?[0-9])|(30) (0 to 30, inclusive)
- daily_listening_interval_start_date: YYYY-MM-DD (e.g. `2019-06-16`)
- locale: en_US
- monthly_listening_interval_duration: 0?[0-9]|1[012] (0 to 12, inclusive)
- monthly_listening_interval_start_date: YYYY-MM (e.g. `2019-02`)
- response_groups: [total_listening_stats]
- store: [AudibleForInstitutions, Audible, AmazonEnglish, Rodizio]

### GET /1.0/stats/status/finished

- asin:
- asin: asin

### POST(?) /1.0/stats/status/finished

Expand Down Expand Up @@ -326,14 +347,10 @@ For a succesful request, returns JSON body with `content_url`.
- reviews_sort_by: [MostHelpful, MostRecent]
- similarity_type: [InTheSameSeries, ByTheSameNarrator, RawSimilarities, ByTheSameAuthor, NextInSameSeries]

### POST(?) /1.0/library/item

- asin:

### POST(?) /1.0/library/item/%s/%s

## Downloading

For multipart books, it's necessary to use the `child_asin` provided with `response_groups=relationships` in order to download each part.

```crystal
require "audible"
Expand Down
28 changes: 18 additions & 10 deletions src/audible.cr
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module Audible
body["adp_token"] = @adp_token
body["access_token"] = @access_token
body["refresh_token"] = @refresh_token
body["device_private_key"] = @device_private_key.to_der
body["device_private_key"] = @device_private_key.to_der.delete("\n")
body["expires"] = @expires.to_unix

body.to_json
Expand Down Expand Up @@ -120,7 +120,7 @@ module Audible
headers["Accept-Language"] = "en-US"
headers["Host"] = "www.amazon.com"
headers["Origin"] = "https://www.amazon.com"
headers["User-Agent"] = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E304"
headers["User-Agent"] = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"

oauth_url = "/ap/signin?openid.oa2.response_type=token&openid.return_to=https://www.amazon.com/ap/maplanding&openid.assoc_handle=amzn_audible_ios_us&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&pageId=amzn_audible_ios&accountStatusPolicy=P1&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.mode=checkid_setup&openid.ns.oa2=http://www.amazon.com/ap/ext/oauth/2&openid.oa2.client_id=device:6a52316c62706d53427a5735505a76477a45375959566674327959465a6374424a53497069546d45234132435a4a5a474c4b324a4a564d&language=en_US&openid.ns.pape=http://specs.openid.net/extensions/pape/1.0&marketPlaceId=AF2M0KC94RCEA&openid.oa2.scope=device_auth_access&forceMobileLayout=true&openid.ns=http://specs.openid.net/auth/2.0&openid.pape.max_auth_age=0"

Expand Down Expand Up @@ -207,6 +207,7 @@ module Audible
def auth_register
body = JSON.build do |json|
json.object do
json.field "requested_extensions", ["device_info", "customer_info"]
json.field "requested_token_type", ["bearer", "mac_dms", "website_cookies"]

json.field "cookies" do
Expand All @@ -229,7 +230,7 @@ module Audible
json.field "registration_data" do
json.object do
json.field "domain", "Device"
json.field "app_version", "3.1.2"
json.field "app_version", "3.7"
json.field "device_serial", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
json.field "device_type", "A2CZJZGLK2JJVM"
json.field "device_name", "%FIRST_NAME%%FIRST_NAME_POSSESSIVE_STRING%%DUPE_STRATEGY_1ST%Audible for iPhone"
Expand All @@ -244,8 +245,6 @@ module Audible
json.field "access_token", @access_token
end
end

json.field "requested_extensions", ["device_info", "customer_info"]
end
end

Expand All @@ -256,7 +255,7 @@ module Audible
headers["Accept-Charset"] = "utf-8"
headers["x-amzn-identity-auth-domain"] = "api.amazon.com"
headers["Accept"] = "application/json"
headers["User-Agent"] = "AmazonWebView/Audible/3.1.2/iOS/10.3.1/iPhone"
headers["User-Agent"] = "AmazonWebView/Audible/3.7/iOS/12.3.1/iPhone"
headers["Accept-Language"] = "en_US"
headers["Cookie"] = @login_cookies.map { |key, value| "#{key}=#{value}" }.join("; ")

Expand Down Expand Up @@ -291,7 +290,7 @@ module Audible
headers["Accept-Charset"] = "utf-8"
headers["x-amzn-identity-auth-domain"] = "api.amazon.com"
headers["Accept"] = "application/json"
headers["User-Agent"] = "AmazonWebView/Audible/3.1.2/iOS/10.3.1/iPhone"
headers["User-Agent"] = "AmazonWebView/Audible/3.7/iOS/12.3.1/iPhone"
headers["Accept-Language"] = "en_US"
headers["Cookie"] = @login_cookies.map { |key, value| "#{key}=#{value}" }.join("; ")
headers["Authorization"] = "Bearer #{@access_token}"
Expand All @@ -311,7 +310,7 @@ module Audible

body = {
"app_name" => "Audible",
"app_version" => "3.1.2",
"app_version" => "3.7",
"source_token" => @refresh_token,
"requested_token_type" => "access_token",
"source_token_type" => "refresh_token",
Expand All @@ -326,9 +325,18 @@ module Audible
@expires = Time.now + body["expires_in"].as_i.seconds
end

def user_profile
def user_profile : JSON::Any
client = HTTP::Client.new(AMAZON_API)
headers = HTTP::Headers.new
headers["Host"] = "api.amazon.com"
headers["Cookie"] = @login_cookies.map { |key, value| "#{key}=#{value}" }.join("; ")
headers["Accept-Charset"] = "utf-8"
headers["User-Agent"] = "AmazonWebView/Audible/3.7/iOS/12.3.1/iPhone"
headers["Accept-Language"] = "en_US"
headers["Authorization"] = "Bearer #{@access_token}"

client = HTTP::Client.new(AMAZON_API)
return JSON.parse(client.get("/user/profile?access_token=#{@access_token}").body)
return JSON.parse(client.get("/user/profile", headers).body)
end

def refresh_or_register
Expand Down
2 changes: 1 addition & 1 deletion src/audible/crypto.cr
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module Audible
end

def self.decrypt_metadata(metadata)
metadata = metadata.lchop("ECdITeCs:")
metadata = URI.unescape(metadata).lchop("ECdITeCs:")
final_round = Base64.decode(metadata)

temp2 = [] of UInt32
Expand Down

0 comments on commit 6738f44

Please sign in to comment.