Skip to content

Commit 3d5e6f6

Browse files
committed
MODIFY: get_manifest api endpoint
1 parent 3d8c8ef commit 3d5e6f6

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def read_from_file(key):
5151
'Pillow',
5252
'pyaes',
5353
'rsa',
54-
'xmltodict'
54+
'xmltodict',
55+
'amazon.ion'
5556
],
5657
extras_require={
5758
'docs': [

src/kindle/api.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# found api endpoints
2-
# have to find out more
3-
2+
# there are many more but what they do?
43

4+
import base64
55
import json
66
from datetime import datetime
77

88
import httpx
99
import xmltodict
10+
from amazon.ion import simpleion
1011

1112

1213
def get_library(auth):
@@ -27,6 +28,12 @@ def _build_correlation_id(auth, asin):
2728
return f"Device:{device}:{serial};kindle.EBOK:{asin}:{timestamp}"
2829

2930

31+
def _b64ion_to_dict(b64ion: str):
32+
ion = base64.b64decode(b64ion)
33+
ion = simpleion.loads(ion)
34+
return dict(ion)
35+
36+
3037
def get_manifest(auth, asin: str):
3138
asin = asin.upper()
3239
url = f"https://kindle-digital-delivery.amazon.com/delivery/manifest/kindle.ebook/{asin}"
@@ -42,7 +49,13 @@ def get_manifest(auth, asin: str):
4249
}
4350
with httpx.Client(auth=auth) as session:
4451
r = session.get(url, headers=headers)
45-
return r.json()
52+
manifest = r.json()
53+
54+
manifest["responseContext"] = _b64ion_to_dict(manifest["responseContext"])
55+
for resource in manifest["resources"]:
56+
if resource.get("responseContext"):
57+
resource["responseContext"] = _b64ion_to_dict(resource["responseContext"])
58+
return manifest
4659

4760

4861
def whispersync(auth):

0 commit comments

Comments
 (0)