.. _bibble.metadata.metadata_writer: =============================== bibble.metadata.metadata_writer =============================== .. py:module:: bibble.metadata.metadata_writer .. autoapi-nested-parse:: See EOF for license/metadata/notes as applicable Type Aliases ------------ .. autoapisummary:: bibble.metadata.metadata_writer.Field Classes ------- .. autoapisummary:: bibble.metadata.metadata_writer.ApplyMetadata bibble.metadata.metadata_writer.FileCheck bibble.metadata.metadata_writer._EntryFileGetter_m bibble.metadata.metadata_writer._Epub_Update_m bibble.metadata.metadata_writer._Metadata_Check_m bibble.metadata.metadata_writer._Pdf_Update_m Module Contents =============== .. py:data:: Field :type: TypeAlias :value: model.Field .. _bibble.metadata.metadata_writer.ApplyMetadata: .. py:class:: ApplyMetadata(*, backup = None, force = False, **kwargs) Bases: :py:obj:`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] .. py:method:: on_write() -> .. py:method:: process_epub(epub, entry) -> .. py:method:: process_pdf(pdf, entry) -> .. py:method:: transform_Entry(entry, library) -> .. py:attribute:: _backup :type: jgdv.Maybe[pathlib.path] .. py:attribute:: _failures :type: list[Exception] .. py:attribute:: _force_update :value: False .. _bibble.metadata.metadata_writer.FileCheck: .. py:class:: FileCheck(*args, **kwargs) Bases: :py:obj:`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 .. py:method:: transform_Entry(entry, library) -> TODO remove orphan/lock field if its no longer the case .. bibble.metadata.metadata_writer._EntryFileGetter_m: .. py:class:: _EntryFileGetter_m Mixin for getting the paths of files in the entry can return a list of all file_{N} field values .. py:method:: _get_file(entry) -> Gets the main file fields path of an entry .. py:method:: _get_files(entry) -> gets all paths of fields with 'file' in the field name .. bibble.metadata.metadata_writer._Epub_Update_m: .. py:class:: _Epub_Update_m A Mixin for epub-specific metadata manipulation .. py:method:: entry_to_calibre_args(entry) -> .. py:method:: update_epub_by_calibre(path, entry) -> Uses calibre to modify epub metadata https://manual.calibre-ebook.com/generated/en/cli-index.html .. bibble.metadata.metadata_writer._Metadata_Check_m: .. py:class:: _Metadata_Check_m A mixin for checking the metadata fof files .. py:method:: backup_original_metadata(path) -> 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. .. py:method:: metadata_matches_entry(path, entry) -> 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 .. bibble.metadata.metadata_writer._Pdf_Update_m: .. py:class:: _Pdf_Update_m A Mixin for pdf specific metadata manipulation .. py:method:: _entry_to_exiftool_args(entry) -> 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 .. py:method:: pdf_finalize(path) -> run qpdf --linearize, on success, delete the original if it exists .. py:method:: pdf_is_modifiable(path) -> Use qpdf to test the pdf for encryption or password locking, .. py:method:: pdf_validate(path) -> 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 .. py:method:: update_pdf_by_exiftool(path, entry) -> exiftool -{tag}="{content}" {file} https://exiftool.org/