From 26ec1901c34346608a3d89e91729ff8b4c564b45 Mon Sep 17 00:00:00 2001 From: xenofem Date: Tue, 12 Mar 2024 15:56:40 -0400 Subject: [PATCH] display progress for extracting pdf images as well as for analyzing them --- dlibrary/dlibrary.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index 0d8a3c3..8d60a62 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -388,10 +388,14 @@ class Collator: return None self.dest.mkdir(parents=True, exist_ok=True) + + print(f'0 pages collated...', end='') for (idx, image) in enumerate(images, start=self.index): file_path = self.dest / f'{idx:04d}.{image["ext"]}' with open(file_path, 'wb') as f: f.write(image["image"]) + print(f'\x1b[2K\r{idx+1-self.index} pages collated...', end='') + print() self.index += pdf.page_count return True @@ -575,7 +579,7 @@ def pdf_images(pdf, strategy): return (extract_image(pdf, images[0][0]) for (images, _) in images_by_page) print("Checking PDF images the quick way failed, trying the slow way") - print(f'0/{pdf.page_count} pages processed...', end='') + print(f'0/{pdf.page_count} pages analyzed...', end='') image_extractors = [] for (idx, page) in enumerate(pdf): page_images = page.get_image_info(xrefs=True) @@ -610,7 +614,7 @@ def pdf_images(pdf, strategy): display_sixel_page(page) choice = input(f'[N]ope out / [c]onvert page{"" if xref is None else " / e[x]tract image"} / [d]rop page / [s]how page? [n/c{"" if xref is None else "/x"}/d/s] ') - print(f'\x1b[2K\r{idx+1}/{pdf.page_count} pages processed...', end=('' if idx+1 < pdf.page_count else '\n')) + print(f'\x1b[2K\r{idx+1}/{pdf.page_count} pages analyzed...', end=('' if idx+1 < pdf.page_count else '\n')) return (extractor() for extractor in image_extractors)