fix: #150, fix part of #149

error:
ebooks = [e for e in ebooks if e["origins"]["origin"]["type"] == "purchase"]
TypeError: list indices must be integers or slices,not str

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
yihong0618
2023-11-10 19:14:17 +08:00
parent abd89f779c
commit 0ac342f207
3 changed files with 10 additions and 6 deletions

View File

@@ -183,6 +183,7 @@ def login(email, password, domain="com", device_id=DEVICE_ID):
"device_os_family": "android",
"device_type": DEVICE_TYPE,
"device_serial": device_id,
"mac_address": secrets.token_hex(64).upper(),
"manufacturer": MANUFACTURER,
"model": DEVICE_NAME,
"os_version": "30",
@@ -346,7 +347,6 @@ def register_device(tokens=None, is_com=False):
parsed_response = xmltodict.parse(resp.text)
tokens["device_private_key"] = parsed_response["response"]["device_private_key"]
tokens["adp_token"] = parsed_response["response"]["adp_token"]
save_tokens(tokens, is_com=is_com)
return tokens

View File

@@ -522,7 +522,9 @@ class Kindle:
pass
except Exception as e:
logger.error(str(e))
logger.error(f"Index: {index + 1}, Title: {title}, Asin: {asin} download failed")
logger.error(
f"Index: {index + 1}, Title: {title}, Asin: {asin} download failed"
)
def download_books(self, start_index=0, filetype="EBOK"):
# use default device

View File

@@ -175,10 +175,13 @@ class NoKindle:
library = json.loads(json.dumps(library))
library = library["response"]["add_update_list"]
ebooks = [i for i in library["meta_data"] if i["cde_contenttype"] == "EBOK"]
ebooks = [e for e in ebooks if e["origins"]["origin"]["type"] == "Purchase"]
ebooks = [
e
for e in ebooks
if e.get("origins", {}).get("origin", {}).get("type", "") == "Purchase"
]
pdocs = [i for i in library["meta_data"] if i["cde_contenttype"] == "PDOC"]
unknow_index = 1
# for i in pdocs + ebooks:
for i in ebooks + pdocs:
if isinstance(i["title"], dict):
@@ -514,7 +517,6 @@ class NoKindle:
"X-ADP-AttemptCount": "1",
"X-ADP-CorrelationId": correlation_id,
"X-ADP-Transport": str(manifest["responseContext"]["transport"]),
"X-ADP-Reason": str(manifest["responseContext"]["reason"]),
"x-amzn-accept-type": "application/x.amzn.digital.deliverymanifest@1.0",
"X-ADP-SW": str(manifest["responseContext"]["swVersion"]),
"X-ADP-LTO": "60",
@@ -629,7 +631,7 @@ class NoKindle:
self._save_to_epub(out_dedrm, out_epub)
def download_all_ebooks(self):
for b in self.ebooks:
for b in self.ebooks[18:]:
try:
self.download_book(b["ASIN"])
except Exception as e: