bibble.metadata.metadata_writer

See EOF for license/metadata/notes as applicable

Type Aliases

Field

Classes

ApplyMetadata

Apply metadata to files mentioned in bibtex entries

FileCheck

Like ApplyMetadata, but just checks for files that can't be modified or are missing,

_EntryFileGetter_m

Mixin for getting the paths of files in the entry

_Epub_Update_m

A Mixin for epub-specific metadata manipulation

_Metadata_Check_m

A mixin for checking the metadata fof files

_Pdf_Update_m

A Mixin for pdf specific metadata manipulation

Module Contents

bibble.metadata.metadata_writer.Field: TypeAlias = model.Field
class bibble.metadata.metadata_writer.ApplyMetadata(
*,
backup=None,
force=False,
**kwargs,
)

Bases: bibble.util.middlecore.IdenBlockMiddleware

Apply metadata to files mentioned in bibtex entries

uses xmp-prism tags and some custom ones for pdfs, and epub standard.

TODO add a ‘meta_update’ status field to the entry for [locked,failed]

Parameters:
on_write() <Unknown>
process_epub(epub, entry) <Unknown>
Parameters:
Return type:

list[Field]

process_pdf(pdf, entry) <Unknown>
Parameters:
Return type:

list[Field]

transform_Entry(entry, library) <Unknown>
Parameters:
Return type:

list[Entry]

_backup: jgdv.Maybe[pathlib.path]
_failures: list[Exception]
_force_update = False
class bibble.metadata.metadata_writer.FileCheck(*args, **kwargs)

Bases: bibble.util.middlecore.IdenBlockMiddleware

Like ApplyMetadata, but just checks for files that can’t be modified or are missing, so they can be fixed. ie: its faster

Annotate entries with ‘pdf_locked’ if the pdf can’t be modified, “orphan_file” if the pdf or epub does not exist

transform_Entry(entry, library) <Unknown>

TODO remove orphan/lock field if its no longer the case

Parameters:
Return type:

list[Entry]

class bibble.metadata.metadata_writer._EntryFileGetter_m

Mixin for getting the paths of files in the entry can return a list of all file_{N} field values

_get_file(entry) <Unknown>

Gets the main file fields path of an entry

Parameters:

entry (Entry)

Return type:

jgdv.Maybe[pathlib.Path]

_get_files(entry) <Unknown>

gets all paths of fields with ‘file’ in the field name

Parameters:

entry (Entry)

Return type:

list[pathlib.Path]

class bibble.metadata.metadata_writer._Epub_Update_m

A Mixin for epub-specific metadata manipulation

entry_to_calibre_args(entry) <Unknown>
Parameters:

entry (Entry)

Return type:

list[str]

update_epub_by_calibre(path, entry) <Unknown>

Uses calibre to modify epub metadata https://manual.calibre-ebook.com/generated/en/cli-index.html

Parameters:
Return type:

None

class bibble.metadata.metadata_writer._Metadata_Check_m

A mixin for checking the metadata fof files

backup_original_metadata(path) <Unknown>

If self._backup is set, backup the files metadata as jsonlines there Uses exiftool to export the metadata as json, which is then appended into the backup as a jsonlines file.

Parameters:

path (pathlib.Path)

Return type:

None

metadata_matches_entry(path, entry) <Unknown>

Test the given path to see if the metadata matches. This is quite naive. From exiftool, it looks for either: - a ‘Bibtex’ field, - a ‘Description’ field,

and compares that to the raw entry’s text.

TODO switch to use a stored hash instead

Parameters:
Return type:

bool

class bibble.metadata.metadata_writer._Pdf_Update_m

A Mixin for pdf specific metadata manipulation

_entry_to_exiftool_args(entry) <Unknown>

Extract and format the entry as exiftool args Uses XMP for the metadata under a custom XMP-bib namespace # TODO add exiftool config to bibble

Parameters:

entry (Entry)

Return type:

list[str]

pdf_finalize(path) <Unknown>

run qpdf –linearize,

on success, delete the original if it exists

Parameters:

path (pathlib.Path)

Return type:

None

pdf_is_modifiable(path) <Unknown>

Use qpdf to test the pdf for encryption or password locking,

Parameters:

path (pathlib.Path)

Return type:

bool

pdf_validate(path) <Unknown>

Validates a pdf using qpdf https://qpdf.readthedocs.io/en/stable/

code 0 for fine, code 2 for errors code 3 for warnings writes to stderr for issues

Parameters:

path (pathlib.Path)

Return type:

None

update_pdf_by_exiftool(path, entry) <Unknown>

exiftool -{tag}=”{content}” {file} https://exiftool.org/

Parameters:
Return type:

None