implement metadata viewing/editing and basic PDF image extraction

This commit is contained in:
xenofem 2024-01-22 02:58:17 -05:00
parent e907deda75
commit 3714eecab9

View file

@ -150,7 +150,18 @@ def collate(args):
con.close()
def link_pdf(src, dest):
print(f'PDF support not yet implemented, skipping {src}')
with fitz.open(src) as pdf:
images_by_page = [page.get_images() for page in pdf]
if all(len(images) == 1 for images in images_by_page):
dest.mkdir(parents=True)
for (idx, images) in enumerate(images_by_page):
xref = images[0][0]
image = pdf.extract_image(xref)
file_path = dest / f'{idx:04d}.{image["ext"]}'
with open(file_path, 'wb') as f:
f.write(image["image"])
else:
print(f'Support for weirder PDFs not yet implemented, skipping {src}')
def complete_prefix_number_ordering(entries):
matches = reversed(list(NUMBER_REGEX.finditer(entries[0].name)))
@ -182,7 +193,32 @@ def link_ordered_files(ordering, dest):
link_path.symlink_to(relpath(src_path, dest))
def metadata(args):
pass
con = sqlite3.connect(args.destdir / 'meta.db')
cur = con.cursor()
if args.virtual is not None:
cur.execute("UPDATE works SET virtual = ? WHERE id = ?", (1 if args.virtual else 0, args.work_id))
con.commit()
res = cur.execute(
"SELECT title, circle, date, description, series, virtual FROM works WHERE id = ?",
(args.work_id,),
).fetchone()
if res is None:
print(f'Work id {args.work_id} not found!')
return
(title, circle, date, description, series, virtual) = res
print(f'Work ID: {args.work_id}')
print(f'Title: {title}')
print(f'Circle: {circle}')
print(f'Pub date: {date}')
print(f'Description: {description}')
print(f'Series: {series}')
print(f'Virtual: {"Yes" if virtual == 1 else "No"}')
con.close()
def publish(args):
pass