From c2f516a281d5a2b9c8c2cc3d58dd055be7dde5ec Mon Sep 17 00:00:00 2001 From: xenofem Date: Tue, 6 Feb 2024 23:52:59 -0500 Subject: [PATCH] add subcommand to show page counts and image sizes of an extracted work's files --- dlibrary/dlibrary.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index faaa066..3d313b5 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -527,6 +527,28 @@ def manual_collate(args): print(f'Unknown file type {path}, stopping') return +def fmt_size(s): + return f'{s[0]}x{s[1]}px' + +def analyze(args): + extract_dir = args.destdir / 'extract' + files = descendant_files_ignore(extract_dir / args.work_id) + files.sort() + + for f in files: + print(f'{relpath(f, extract_dir)}', end='') + if f.suffix.lower() in IMAGE_FILE_EXTENSIONS: + size = standalone_image_size(f) + print(f'\t{fmt_size(size)}') + elif f.suffix.lower() == '.pdf': + sizes = pdf_image_sizes(f) + if len(sizes) == 0: + print(f'\tContains no images') + else: + print(f'\t{len(sizes)} images, median {fmt_size(median(sizes))}, min {fmt_size(min(sizes))}, max {fmt_size(max(sizes))}') + else: + print() + def metadata(args): con = sqlite3.connect(args.destdir / 'meta.db') cur = con.cursor() @@ -813,6 +835,10 @@ parser_manual_collate.add_argument( ) parser_manual_collate.set_defaults(func=manual_collate) +parser_analyze = subparsers.add_parser('analyze', help='analyze an extracted folder to assist in collation') +parser_analyze.add_argument('work_id') +parser_analyze.set_defaults(func=analyze) + parser_metadata = subparsers.add_parser('metadata', help='view or modify metadata for a work') parser_metadata.add_argument('work_id') parser_metadata.add_argument(