adsfolio.pdf.sidecar

Sidecar JSON management for PDF identification metadata.

class adsfolio.pdf.sidecar.Sidecar(directory, filename='.adsfolio-pdfs.json')[source]

Bases: object

Manage .adsfolio-pdfs.json files for a single directory.

Parameters:
property data: dict[str, Any][source]

Return a copy of the current sidecar payload.

duplicates_by_sha256()[source]

Return SHA digests that map to multiple original files.

Return type:

dict[str, list]

property files: dict[str, dict[str, Any]][source]

Return a copy of file records keyed by original filename.

find_by_current_filename(filename)[source]

Find a record by current filename (or original key fallback).

Parameters:

filename (str)

Return type:

tuple[str, dict[str, Any]] | None

find_by_sha256(sha256)[source]

Find a sidecar record by SHA-256 digest.

Parameters:

sha256 (str)

Return type:

tuple[str, dict[str, Any]] | None

get_file(original_filename)[source]

Return metadata for an original filename, if present.

Parameters:

original_filename (str)

Return type:

dict[str, Any] | None

property identify_profile: dict[str, Any] | None[source]

Return copied identify profile metadata if present.

property identify_settings: adsfolio.pdf.identify_settings.IdentifySettings | None[source]

Return reusable Identify behavior when explicitly present.

reload()[source]

Reload the sidecar from disk and return a copy.

Return type:

dict[str, Any]

remove_file(original_filename)[source]

Remove record for original filename.

Parameters:

original_filename (str)

Return type:

bool

save()[source]

Persist current sidecar payload to disk.

Return type:

pathlib.Path

set_current_filename(original_filename, current_filename)[source]

Update current filename for an existing record.

Parameters:
  • original_filename (str)

  • current_filename (str)

Return type:

bool

set_identify_profile(profile)[source]

Set identify-profile metadata.

Returns True when the sidecar payload changes.

Parameters:

profile (collections.abc.Mapping[str, Any] | None)

Return type:

bool

set_identify_settings(settings)[source]

Set reusable Identify settings and report whether they changed.

Parameters:

settings (adsfolio.pdf.identify_settings.IdentifySettings | None)

Return type:

bool

upsert_file(original_filename, metadata)[source]

Insert or replace a file metadata record.

Parameters:
Return type:

dict[str, Any]

exception adsfolio.pdf.sidecar.SidecarError[source]

Bases: Exception

Raised when sidecar data cannot be loaded or validated.