Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/audible_cli/cmds/cmd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,17 @@ async def create_download_jobs(

return processed_items

def item_info(item):
"""returns a string made from atim asin and full_title"""
return ("[%s] %s" % (item.asin, item.full_title))

def log_job(type_name: str, job: DownloadJob):
"""logs info about the download job"""
logger.info("Checking %s for: %s", type_name, item_info(job.item))


async def download_covers(job: DownloadJob) -> None:
log_job("cover", job)
base_filename = job.create_base_filename()

for cover_size in job.options.cover_sizes:
Expand All @@ -599,6 +608,7 @@ async def download_covers(job: DownloadJob) -> None:


async def download_pdf(job: DownloadJob) -> None:
log_job("PDF", job)
url = job.item.get_pdf_url()
if url is None:
logger.info("No PDF found for %s", job.item.full_title)
Expand All @@ -619,6 +629,7 @@ async def download_pdf(job: DownloadJob) -> None:


async def download_chapters(job: DownloadJob) -> None:
log_job("chapters", job)
options = job.options
if not options.output_dir.is_dir():
raise DirectoryDoesNotExists(options.output_dir)
Expand All @@ -645,6 +656,7 @@ async def download_chapters(job: DownloadJob) -> None:


async def download_annotations(job: DownloadJob) -> None:
log_job("annotations", job)
options = job.options
if not options.output_dir.is_dir():
raise DirectoryDoesNotExists(options.output_dir)
Expand All @@ -664,6 +676,9 @@ async def download_annotations(job: DownloadJob) -> None:
except RequestError:
logger.error("Failed to get annotations for %s.", job.item.full_title)
return None
#except:
# logger.error("Bug", exc_info=True)
# return None

annotation = json.dumps(annotation, indent=4)
async with aiofiles.open(file, "w") as f:
Expand Down Expand Up @@ -727,6 +742,7 @@ async def _add_audioparts_to_queue(queue: SmartQueue, job: DownloadJob, download


async def download_aax(job: DownloadJob, retry: int = 0) -> None:
log_job("aax", job)
# url, codec = await item.get_aax_url(quality)
options = job.options
try:
Expand Down Expand Up @@ -824,6 +840,7 @@ async def _reuse_voucher(lr_file, job: DownloadJob) -> tuple[dict, httpx.URL, st


async def download_aaxc(job: DownloadJob) -> None:
log_job("aaxc", job)
lr, url, codec = None, None, None
options = job.options
base_filename = job.create_base_filename()
Expand Down Expand Up @@ -940,15 +957,18 @@ async def consume_jobs(queue: SmartQueue, name: str) -> None:
try:
while not queue.is_shutdown():
cmd, job, *args = await queue.get()
await cmd(job, *args)
try:
await cmd(job, *args)
except asyncio.CancelledError:
logger.debug("job cancelled for: %s", item_info(job.item))
raise
queue.task_done()
except asyncio.CancelledError:
raise
except Exception as e:
except BaseException as e:
logger.error("error: %s", str(e))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rewrite the logger.error command with

tb_lines = traceback.format_exception(type(exc), exc, exc.__traceback__)
logger.error("".join(tb_lines).rstrip())

Then the redundant code in L413 (_done_callback) can be removed!

if job and not job.options.ignore_errors:
raise
else:
logger.error(e)


@click.command("download")
Expand Down