1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/// see API docs at https://audible.readthedocs.io/en/latest/misc/external_api.html
use serde_json::Value;
use super::Client;
use crate::Result;
impl Client {
/// GET /1.0/content/(string:asin)/metadata
///
/// Parameters:
/// - `asin` (string) – The ASIN of the book
///
/// Query Parameters:
/// - `response_groups` (string) – [chapter_info, always-returned, content_reference, content_url]
/// - `acr` (string)
/// - `quality` (string) – [High, Normal]
/// - `chapter_titles_type` (string) – [Tree, Flat]
/// - `drm_type` (string) – [Mpeg, PlayReady, Hls, Dash, FairPlay, Widevine, HlsCmaf, Adrm]
pub async fn get_content_metadata(&self, asin: &str, params: Option<Value>) -> Result<Value> {
let url = format!("{}/1.0/content/{}/metadata", self.base_url, asin);
let mut req = self.client.get(url);
if let Some(params) = params {
req = req.query(¶ms);
}
let req = req.build()?;
let res = self.send_request(req).await?;
let json: Value = res.json().await?;
Ok(json)
}
/// POST /1.0/content/(string:asin)/drmlicense
///
/// Parameters:
/// - `asin` (string) – The ASIN of the book
///
/// Request JSON Object:
/// - `licenseChallenge` (string) – The license challenge
/// - `asin` (string) – The ASIN of the book
/// - `consumption_type` (string) – "Download"
/// - `drm_type` (string) – "FairPlay"
///
/// Response JSON Object:
/// - `license` (string) – The encrypted license
pub async fn post_drm_license(&self, asin: &str, params: Option<Value>) -> Result<Value> {
let url = format!("{}/1.0/content/{}/drmlicense", self.base_url, asin);
let mut req = self.client.post(url);
if let Some(params) = params {
req = req.json(¶ms);
}
let req = req.build()?;
let res = self.send_request(req).await?;
let json: Value = res.json().await?;
Ok(json)
}
/// GET 1.0/content/FairPlay/certificate
///
/// Response JSON Object:
/// - `certificate` (string) – The base64 encoded FairPlay certificate
pub async fn get_fairplay_certificate(&self, params: Option<Value>) -> Result<Value> {
let url = format!("{}/1.0/content/FairPlay/certificate", self.base_url);
let mut req = self.client.get(url);
if let Some(params) = params {
req = req.query(¶ms);
}
let req = req.build()?;
let res = self.send_request(req).await?;
let json: Value = res.json().await?;
Ok(json)
}
/// POST /1.0/content/(string:asin)/licenserequest
///
/// Parameters:
/// - `asin` (string) – The ASIN of the book
///
/// Request JSON Object:
/// - `use_adaptive_bit_rate` (boolean) – [true, false]
/// - `quality` (string) – [High, Normal]
/// - `chapter_titles_type` (string) – [Tree, Flat]
/// - `response_groups` (string) – [chapter_info, content_reference, last_position_heard, pdf_url, ad_insertion, certificate]
/// - `consumption_type` (string) – [Streaming, Offline, Download]
/// - `spatial` (boolean) – [true, false]
/// - `supported_media_features` (dict) – [codecs, drm_types]
/// - `codecs` (list) – [mp4a.40.2, mp4a.40.42, ec+3, ac-4]
/// - `drm_types` (list) – [Mpeg, PlayReady, Hls, Dash, Adrm, FairPlay, Widevine, HlsCmaf]
/// - `num_active_offline_licenses` (integer) – (max: 10)
///
/// Example:
/// ```json
/// {
/// "quality": "High",
/// "response_groups": "chapter_info,content_reference,last_position_heard,pdf_url,ad_insertion,certificate",
/// "consumption_type": "Download",
/// "supported_media_features": {
/// "codecs": [
/// "mp4a.40.2",
/// "mp4a.40.42",
/// "ec+3",
/// "ac-4"
/// ],
/// "drm_types": [
/// "Mpeg",
/// "PlayReady",
/// "Hls",
/// "Dash",
/// "Adrm",
/// "FairPlay",
/// "Widevine",
/// "HlsCmaf"
/// ]
/// },
/// "spatial": false
/// }
/// ```
///
/// For a succesful request, returns JSON body with content_url.
pub async fn post_license_request(&self, asin: &str, params: Option<Value>) -> Result<Value> {
let url = format!("{}/1.0/content/{}/licenserequest", self.base_url, asin);
let mut req = self.client.post(url);
if let Some(params) = params {
req = req.query(¶ms);
}
let req = req.build()?;
let res = self.send_request(req).await?;
let json: Value = res.json().await?;
Ok(json)
}
}