foley.provenance.rights#
Export a sound with its rights and provenance, for a store outside foley (#66).
export_sound() returns (bytes, rights, provenance):
rightsis a plain dict keyed by the field names oflacing.Rights(pinned toan’sAssetSource:provider,id,title,license,license_url,attribution,source_page_url,author,author_url,cacheable,restrictions), so a consumer validates it withlacing.Rights(**rights). foley never imports lacing (it pulls pydantic), so the dict is the contract.restrictions(lacing#106) states what no licence code says, the revenue caps and excluded territories of the sound’s licences, aslacing.Restrictiondicts (foley.licensing.license_restrictions()); like lacing, the dict leaves it out when there is none, soRights(**rights).model_dump() == rights.provenanceis whatRightshas no field for and a consumer must not lose: foley’s id, the sha256 of the archived bytes AND of the exported bytes (a FLAC archive re-encoded to WAV hashes differently, so both are kept to chain them) and whether the re-encode was lossless, the eight licence flags (ai_training_ok,revenue_cap_usd, …), a required notice, the source’s API obligations (terms_notes), what the licence rests on (license_basisand its confidence), whether the vendor reuses its output, the vendor’s own watermark statement (beside foley’s AudioSeal one), excluded territories, the safety flags, the edit lineage and, for an AI-generated clip, its EU AI Act Art. 50 checklist with the generation block.
Two rules carry the rights:
Licence codes are what a consumer classifies, from the SSOT consumers import (
foley.licensing.consumer_license_code()):cc0-1.0,cc-by-4.0,stability-community, andNone– UNKNOWN, never unencumbered – when the rights are unverified (a Public Domain Mark is a claim, not a grant) or unknown. An edit is exported under the most restrictive licence of its lineage (foley.licensing.rights_license_id()), so it never reads wider than a source, and never under a code that implies more than the record’s flags allow (foley.licensing.code_implies_at_most(), elseNone). AI use is not in a code: a consumer reads it from the provenance (flags,ai_training_scope,gen_ai_preference). The code is judged together with the restrictions stated beside it (restrictions=offoley.licensing.rights_license_id()). A provider-terms licence names the terms’ owner asprovider(foley.licensing.LICENSE_TERMS_PROVIDER), since a consumer reads such a code only on that provider’s source.The export is fail-closed: bytes foley may not keep (
cache_bytes_ok=False, a Freesound API pull stored by reference) are not handed to another store either (foley.licensing.export_refusal()), and bytes are exported only when they match the content hash their record names.
Everything is read off the LicenseRecord SSOT through the
credits layer (title, author, licence URL, attribution line); no flag is re-derived.
The export also interoperates with library tools (Soundminer, Soundly, BaseHead; #231):
a UCS filename (
CatID_FXName_CreatorID_SourceID_<foley id>.wav,export_ucs_filename()) goes inprovenance["filename"], a suggestion theconsumer may use. It is not a fourth return value:
(bytes, rights, provenance)is the contract callers unpack, and the provenance already describes the exported bytes (format, subtype, hash).a WAV export carries its description in bext / iXML (
export_metadata(), written byfoley.embedded_metadata.write_embedded_metadata()): caption, tags, the UCS fields, and the licence, licence URL and attribution line ofrights, so the credit travels with the file. The samples are untouched andprovenance["sha256"]is taken after embedding, so it names the bytes returned.
Module Attributes
The format an export is encoded in when none is named. |
|
|
|
|
|
a foley row's own metadata must not use one, or it would read as that record's claim. |
|
The containers that take |
|
a source file's value is removed when the export has none, so the file never pairs foley's licence with a vendor's URL. |
|
a brief title of at most this many characters. |
Functions
|
The fields an export embeds ( |
|
Export a sound's bytes as |
|
The UCS filename of |
|
The foley id |
|
|
|
|
|
Who the rights come from: the owner of the provider-terms licence exported ( |
|
What an export must carry that |
|
|
- foley.provenance.rights.ASSET_SOURCE_EXTRAS: tuple[str, ...] = ('url', 'sha256', 'cost_usd', 'extra')#
an’sAssetSourcefields thatlacing.Rightshas no name for (a test pins them to an’s model when an is installed).
- foley.provenance.rights.DEFAULT_EXPORT_FORMAT = 'wav'#
The format an export is encoded in when none is named.
- foley.provenance.rights.EXPORT_OWNED_FIELDS = ('license', 'license_url', 'attribution')#
a source file’s value is removed when the export has none, so the file never pairs foley’s licence with a vendor’s URL.
- Type:
The fields an export owns in the file
- foley.provenance.rights.METADATA_FORMATS = ('wav', 'wavex')#
The containers that take
bext/iXMLchunks (RIFF WAVE, as libsndfile names them).
- foley.provenance.rights.PROVENANCE_FIELDS: tuple[str, ...] = ('provider', 'id', 'title', 'license', 'license_url', 'attribution', 'source_page_url', 'author', 'author_url', 'cacheable', 'restrictions', 'url', 'sha256', 'cost_usd', 'extra')#
a foley row’s own metadata must not use one, or it would read as that record’s claim.
- Type:
Every provenance field name a downstream record gives an asset
- foley.provenance.rights.RIGHTS_FIELDS: tuple[str, ...] = ('provider', 'id', 'title', 'license', 'license_url', 'attribution', 'source_page_url', 'author', 'author_url', 'cacheable', 'restrictions')#
lacing.Rights’ field names, the keys ofsound_rights()(lacing#34; a test pins them to lacing’s model when lacing is installed).
- foley.provenance.rights.UCS_FXNAME_MAX_CHARS = 25#
a brief title of at most this many characters.
- Type:
The UCS guidance for an FXName
- foley.provenance.rights.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.rights.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.rights.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.rights.id_from_user_data(block)[source]#
The foley id
id_to_user_data()encoded asblock.- Return type:
- foley.provenance.rights.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.rights.license_text(rights)[source]#
rights’ licence code with its restrictions in words, for a file’s licence field;Nonewhen the licence is unknown (a restriction alone grants nothing).>>> license_text({"license": "cc-by-4.0", "restrictions": ( ... {"kind": "revenue_cap", "terms": None, "usd": 5000},)}) 'cc-by-4.0; revenue cap USD 5000' >>> license_text({"license": "cc0-1.0"}), license_text({"license": None}) ('cc0-1.0', None)
- foley.provenance.rights.rights_provider(lic, *, license_id=None)[source]#
Who the rights come from: the owner of the provider-terms licence exported (
license_id, elselic’s own), else the source. Keyed on the exported code, so a terms owner is never paired with another licence’s code.>>> rights_provider(LicenseRecord(source="fal_stable_audio_3", license_id="Stability-Community")) 'stability-ai' >>> rights_provider(LicenseRecord(source="freesound", license_id="CC0-1.0")) 'freesound' >>> rights_provider(LicenseRecord(source="g", license_id="Stability-Community"), ... license_id="CC-BY-4.0") 'g'
- Return type:
- foley.provenance.rights.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.rights.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: