From deef5e03e38e41bb12a8fbf6a477fd923b5de206 Mon Sep 17 00:00:00 2001 From: ping Date: Thu, 14 Sep 2023 14:33:35 +0800 Subject: [PATCH] Handle error when downloading bundled content (audiobook attachments), ref #54 --- odmpy/odm.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/odmpy/odm.py b/odmpy/odm.py index 0f590e7..18805aa 100644 --- a/odmpy/odm.py +++ b/odmpy/odm.py @@ -322,9 +322,18 @@ def extract_bundled_contents( ) if not libby_client.is_downloadable_ebook_loan(bundled_media): continue - # patch in cardId from parent loan details - bundled_media["cardId"] = selected_loan["cardId"] - extract_loan_file(libby_client, bundled_media, args) + try: + # patch in cardId from parent loan details + bundled_media["cardId"] = selected_loan["cardId"] + extract_loan_file(libby_client, bundled_media, args) + except ClientError: + # Oddly having a valid loan to the audiobook does not always mean + # having access to the bundled content? Ref https://github.com/ping/odmpy/issues/54 + # Let this fail without affecting the main download since it's not critical + logger.exception( + 'Unable to download bundled content for "%s"', + bundled_media.get("title", ""), + ) def extract_loan_file( @@ -1206,7 +1215,11 @@ def run(custom_args: Optional[List[str]] = None, be_quiet: bool = False) -> None cleanup_odm_license=not args.keepodm, ) extract_bundled_contents( - libby_client, overdrive_client, selected_loan, cards, args + libby_client, + overdrive_client, + selected_loan, + cards, + args, ) continue elif libby_client.is_downloadable_ebook_loan(