add subcommand to show page counts and image sizes of an extracted work's files
This commit is contained in:
parent
cdf06d9aa0
commit
c2f516a281
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue