foley.provenance#
Provenance layer for foley — attribution/credits (and, later, disclosure).
This subpackage keeps published output legal and traceable. Its first half (#9a)
is foley.provenance.credits — the stdlib-only TASL attribution / credits
generator (CREDITS.md + JSON manifest) that reads the LicenseRecord SSOT.
Its second half (#9b) is foley.provenance.disclosure — AudioSeal
watermarking, the portable C2PA content-credential sidecar, the EU AI Act Art. 50
checklist, and the trademarked-audio / recognizable-voice safety scan. It is
intentionally NOT imported here so import foley stays dependency-light: its
module top level is stdlib-only, but audioseal / torch / torchaudio
(the foley[provenance] extra) are imported lazily inside its watermark
functions. Import it explicitly (from foley.provenance import disclosure) or
reach the pure helpers via foley.art50_checklist / foley.scan_prompt.
foley.provenance.rights exports a sound for a store outside foley (#66):
export_sound() gives (bytes, rights, provenance), rights keyed by
lacing.Rights field names.
Functions
|
Render one sound's TASL attribution line. |
|
Build a |
|
Build the deduplicated |
|
The machine-readable manifest for |
|
The fields an export embeds ( |
|
Export a sound's bytes as |
|
The UCS filename of |
|
The foley id |
|
|
|
A |
|
A throwaway C2PA-conformant |
|
Render |
|
What an export must carry that |
|
|
Classes
|
One rendered TASL credit for a single sound (a flat, serializable row). |
|
A deduplicated, ordered collection of |
- class foley.provenance.CreditEntry(sound_id, title=None, author=None, author_url=None, source=None, source_url=None, license_id='unknown', license_name=None, license_url=None, modified=False, requires_attribution=False, attribution_text=None, notice_text_required=None, terms_notes=list(), is_ai_generated=False, generator_model=None, disclosure_recommended=False, watermark=None, c2pa_manifest_ref=None, derived_from=list(), derived_license_ids=list())[source]#
Bases:
SerializableMixinOne rendered TASL credit for a single sound (a flat, serializable row).
Built by
credit_entry()from a record’s rights fields; rendered to a single attribution line byattribution_line(). Carries the AI-disclosurewatermark / C2PA fields as pass-throughs so the JSON manifest becomes the content-credentials carrier once #6/#9b populate them (
Nonetoday).
- class foley.provenance.Credits(entries=(), title='Credits', schema_version=1)[source]#
Bases:
SerializableMixinA deduplicated, ordered collection of
CreditEntryfor one run.Iterable and sized; renders to
CREDITS.mdviamarkdownand to a JSON manifest viamanifest(==to_dict()). Both are deterministic (no timestamps) and diffable.
- foley.provenance.attribution_line(source, *, fmt='markdown')[source]#
Render one sound’s TASL attribution line.
A source-supplied
attribution_text(if non-empty) is returned verbatim; otherwise the line is synthesized from Title/Author/Source/License, with a(modified)notice and an AI-disclosure segment appended as applicable. A clip made by editing another (#162) then credits its source:; derived fromand the source’s own credit line (which names the source’s licence, and its own source in turn, for an edit of an edit).- Parameters:
source (
Union[CreditEntry,SoundRecord,Candidate,LicenseRecord]) – ACreditEntry, or any credit input (coerced first).fmt (
str) –'markdown'(hyperlinked list-item body) or'plain'(text with URLs in parentheses).
- Return type:
- Returns:
The attribution line (no leading bullet / trailing newline).
- foley.provenance.credit_entry(record, *, title=None)[source]#
Build a
CreditEntryfrom a record (title override optional).Every field is read straight off the
LicenseRecord(flags never re-derived);modifiedreflects a non-emptytransformationslist, andderived_fromthe sources an edit was made from (derived_sources()),derived_license_idsthe licence of every sound it derives from (each bounds it on top of its own).- Parameters:
record (
Union[SoundRecord,Candidate,LicenseRecord]) – ASoundRecord,Candidate, orLicenseRecord.title (
Optional[str]) – Explicit title override (else resolved from caption/tags/…).
- Return type:
- foley.provenance.credits_for(sounds, *, title='Credits', only_required=False, sort='appearance')[source]#
Build the deduplicated
Creditsfor the sounds used in a run.- Parameters:
sounds (
Iterable[Union[SoundRecord,Candidate,LicenseRecord]]) – An iterable of records / candidates / license records.title (
str) – The credits heading (also carried in the manifest).only_required (
bool) – Keep only entries whose license requires attribution (drops CC0 / user-owned courtesy credits). DefaultFalsecredits everything (never-discard-provenance).sort (
str) –'appearance'(default: first-seen order),'author', or'title'(case-insensitive alpha).
- Return type:
- Returns:
A
Credits; identical sounds (same id) are credited once (first-writer-wins).
- foley.provenance.credits_manifest(credits)[source]#
The machine-readable manifest for
credits— a JSON-native dict.entriesis a plainlistof per-credit dicts (not thetuplethatdataclasses.asdictwould preserve), so the manifest equalsjson.loads(credits.to_json())— the exact shape written tocredits.json. It carries the full field set, including therequires_attributionmark and thewatermark/c2pa_manifest_refpass-throughs (Noneuntil #9b).- Return type:
- foley.provenance.export_metadata(record, rights, ucs_name=None)[source]#
The fields an export embeds (
foley.embedded_metadata.FIELDSnames).The caption and tags, the UCS fields of
ucs_name(the parse of the export’s filename, so the file and its name agree), the designer (rights’ author) andrights’ licence, licence URL and attribution line, verbatim. A file has no restrictions field, so the licence text states them after the code (license_text()): the file never reads wider than the rights. Empty values are left out by the writer.- Return type:
- foley.provenance.export_sound(sound_id, fmt='wav', *, library=None, subtype=None, embed_metadata=True, ucs_filename=True, ucs_table=None)[source]#
Export a sound’s bytes as
fmtwith its rights and provenance (#66, #231).The sound’s bytes are fetched from
library, checked against the record’s content hash, and re-encoded (foley.audio.transcode(): PCM, the archive’s own depth wherefmtallows, so aPCM_24FLAC gives a sample-exactPCM_24WAV; bytes already infmtand subtype are not re-encoded). A WAV then gets itsbext/iXMLmetadata (export_metadata()).- Parameters:
sound_id (
str) – The record id inlibrary.fmt (
str) – The container to export (any libsndfile format:'wav','flac').library (
Optional[SoundLibrary]) – TheSoundLibraryto read (default:foley.default_library()).subtype (
Optional[str]) – The sample format (default:foley.audio.export_subtype()).embed_metadata (
bool) – Writebext/iXMLinto a WAV export (default on: it adds chunks only, never touches the samples, and makes the file carry its own credit; other formats, and a WAV the writer refuses, such as a streamed one sized0xFFFFFFFF, are left as encoded, with a note). The licence fields (EXPORT_OWNED_FIELDS) are foley’s: a source file’s value is removed whenrightshas none.ucs_filename (
bool) – Put the UCS filename inprovenance["filename"](default on: it is only a suggestion, so it costs a consumer nothing to ignore). The embedded UCS fields do not depend on it: they followembed_metadata.ucs_table (
Optional[UcsTable]) – The UCS table the CatID is resolved in (default:foley.index.taxonomy.default_ucs_table()).
- Returns:
rightsfromsound_rights(),provenancefromsound_provenance(), plusfilename(the UCS filename, orNone),embedded(the chunks written:['ixml', 'bext'], or[]) andexport_notes(why a filename or chunks are missing, and what of a source file’s own metadata was not kept).provenance["sha256"]is the hash of the bytes returned.- Return type:
- Raises:
KeyError –
sound_idis not inlibrary.LicenseRefusal – the sound’s terms forbid keeping its bytes (
cache_bytes_ok=False).LookupError – the bytes are not available locally.
ValueError – the record names no content hash, or the bytes no longer match it.
- foley.provenance.export_ucs_filename(record, rights, *, ext='wav', table=None, fx_name_max_chars=25)[source]#
The UCS filename of
record’s export, orNonewhen it has no CatID intable.CatID_FXName_CreatorID_SourceID_UserData.ext: the CatID isrecord.ucs_category(which holds the CatID), looked up intable(default:foley.index.taxonomy.default_ucs_table()); the FXName is the caption (else the tags) cut tofx_name_max_chars; the creator isrights’ author, else its provider; the source is foley’s source name; the UserData is the foley id (id_to_user_data(): injective, case-safe, reversible), so two exports of one library never share a name. The other blocks are cut to fit the filename limit (UCS_NAME_MAX_BYTES); the id is never cut.parse_ucs_name()reads it back.- Raises:
ValueError – the id alone does not fit in a filename.
- Return type:
- foley.provenance.id_from_user_data(block)[source]#
The foley id
id_to_user_data()encoded asblock.- Return type:
- foley.provenance.id_to_user_data(sound_id)[source]#
sound_idas a filename block, injectively:id_from_user_data()inverts it.Every character but lower-case ASCII letters, digits,
-and~is percent-encoded (its UTF-8 bytes, upper-case hex), so the block holds no_,., path or reserved character, and two ids never give names that differ only in case (which a case-insensitive filesystem, macOS or Windows, would merge).>>> id_to_user_data("fs:1_A.b"), id_from_user_data("fs%3A1%5F%41%2Eb") ('fs%3A1%5F%41%2Eb', 'fs:1_A.b')
- Return type:
- foley.provenance.make_c2pa_signer(cert_chain_pem, private_key_pem, *, alg='es256', tsa_url=None, password=None)[source]#
A
c2pa.Signerforfoley.weave(..., sign_cert=...)from a cert chain and key.- Parameters:
cert_chain_pem (
Union[str,bytes]) – The end-entity certificate followed by its issuer(s), PEM. A bare leaf is accepted (not enforced): C2PA validators then need the issuer among their trust anchors, and it is not embedded in the manifest.private_key_pem (
Union[str,bytes]) – The signing key, PEM (PKCS#8BEGIN PRIVATE KEYor SEC1).alg (
str) – One ofSIGNING_ALGORITHMS(default'es256'); it must match the key.tsa_url (
Optional[str]) – An RFC 3161 timestamp-authority URL (None: no timestamp).password (
Union[str,bytes,None]) – The key’s passphrase, if it is encrypted (str or bytes).
- Raises:
ValueError – An unknown or non-string
alg, a key (or curve) that does not fit it, a chain that is not PEM or does not start with the key’s own certificate, or an end-entity certificate outside the C2PA signing profile (a CA, no digitalSignature, no acceptable ExtendedKeyUsage, an invalid validity window, or an RSA key underMIN_RSA_KEY_BITS).ImportError –
c2pa-python/cryptographymissing (pip install 'foley[c2pa]').
- foley.provenance.make_self_signed_c2pa_certs(*, common_name='foley-dev-signer', valid_days=3650, backdate_days=1, key=None, end_entity_extensions=None)[source]#
A throwaway C2PA-conformant
(cert_chain_pem, private_key_pem)for dev and tests.A CA plus an end-entity certificate with the profile C2PA requires. The chain is not trusted by validators; use a real CA for anything you publish. The key is PKCS#8 PEM.
- Parameters:
key (
Union[str,bytes,object,None]) – the end-entity private key, any familymake_c2pa_signersupports (acryptographyprivate key object, or PEM text/bytes). Default: a fresh ES256 (P-256) key. The CA is always ES256.end_entity_extensions (
Optional[Iterable[tuple[object,bool]]]) –[(extension, critical), ...]replacing the default end-entity profile (BasicConstraints, KeyUsage, ExtendedKeyUsage), e.g. to make a deliberately non-conformant chain for negative tests.backdate_days (
int) – days before now that the certificates start being valid (negative: not yet valid). A negativevalid_dayssmaller in magnitude thanbackdate_daysgives an expired chain.
- Return type:
Lazy dependency:
cryptography.
- foley.provenance.render_credits_md(credits, *, title=None, heading_level=2)[source]#
Render
creditsas a deterministicCREDITS.mddocument.- Parameters:
- Return type:
- Returns:
The Markdown document (bulleted attribution lines, then each distinct
notice_text_required; a placeholder note when empty), ending in a single trailing newline.
- foley.provenance.sound_provenance(record, *, archived_sha256, sha256, fmt, subtype, archived_subtype=None, lossless=True)[source]#
What an export must carry that
Rightshas no field for (JSON-native).- Parameters:
record (
SoundRecord) – The exported sound.archived_sha256 (
str) – The sha256 of the bytes foley holds (its content key).sha256 (
str) – The sha256 of the exported bytes (an’sAssetSource.sha256).fmt (
str) – The exported format ('wav').subtype (
str) – The exported sample format ('PCM_24').archived_subtype (
Optional[str]) – The sample format of the bytes foley holds.lossless (
bool) – Whether the exported samples are exactly the archived ones.
- Return type:
- foley.provenance.sound_rights(record)[source]#
record’s rights as a dict keyed bylacing.Rightsfield names.licenseisrights_license_id()as a consumer code (the most restrictive licence of an edit’s lineage),license_urlthat licence’s.attributionis foley’s plain-text credit line, so it carries the(modified)notice, the AI disclosure (AI-generated with <model>) and an edit’s sources.authorisNonewhen no creator or rights holder is recorded (the credit line falls back to the source name; a rights record does not).restrictions(only when there are any) states the revenue caps and excluded territories, and the code is judged together with them.- Return type:
Modules
TASL attribution / credits generator — the provenance render layer (#9a). |
|
Disclosure, watermarking & safety for AI-generated audio (#9b). |
|
Export a sound with its rights and provenance, for a store outside foley (#66). |
|
Build a C2PA signer from a certificate chain + private key (the #38 gotchas, solved once). |