foley.licensing#

License policy for foley: the license_id -> flag-set SSOT, flag derivation (with per-source overrides), and the fail-closed candidate keep() gate.

Stdlib-only (imports only foley.base). The dependency direction is one-way: licensing -> base.

The two operational vs copyright flags are DISTINCT and must not be conflated:

  • redistribute_standalone_ok is a COPYRIGHT question (may the raw file be re-exposed standalone?).

  • cache_bytes_ok is a TOS/OPERATIONAL question (may foley persist the bytes at all?).

E.g. Freesound CC0 is legally redistributable yet its API TOS forbids caching, so the Freesound adapter passes overrides={'cache_bytes_ok': False} — the item is redistributable but stored by-reference.

Module Attributes

DEFAULT_INTENDED_USE

The ONE rights intent every verb and surface defaults to (#63, maintainer decision 2026-10-03): commercial publishing, attributable.

UNKNOWN_LICENSE_FLAGS

Fail-closed fallback for unknown / Proprietary-* license ids (all False, cap None).

LICENSE_FLAGS

license_id -> default flag set (report 07 §8.1 seed table).

CC_VERSIONS

The CC versions foley has rows for (Freesound, FSD50K, Clotho and Wikimedia use these).

SHARE_ALIKE_LICENSE_FLAGS

it may keep the bytes, and must credit them; nothing else.

SHARE_ALIKE_FLAGS

The share-alike licence ids foley can name -> SHARE_ALIKE_LICENSE_FLAGS.

UNASSERTABLE_LICENSE_IDS

Licence ids that can never be asserted as verified (on ingest, restamp or in a folder sidecar): unknown by definition, PDM-1.0 (a claim about the work, not a grant — verify it by building the LicenseRecord yourself), and the legacy ElevenLabs-SFX row (say the plan).

ASSERTABLE_LICENSE_IDS

The ids a user may assert (foley ingest --license, a foley-license.toml).

DEFAULT_CC_VERSION

The version assumed when a source gives a CC family with no version at all (Freesound's search labels: "Attribution").

UNKNOWN_LICENSE_META

Fail-closed display fallback for unknown / Proprietary-* license ids.

LICENSE_META

license_id -> display name + canonical URL (one row per LICENSE_FLAGS key).

GENERATION_FIELDS

carry_lineage() keeps the stored record's.

AI_TRAINING_SCOPES

The ai_training_scope values (None = no narrowing beyond ai_training_ok).

GEN_AI_PREFERENCE_SCOPES

Freesound gen_ai_preference -> (ai_training_ok override, ai_training_scope).

LICENSE_BASES

the model's own licence (its weights), the vendor's terms of service, or a label an aggregator put on it (fal's commercial, an Openverse row), which is a claim about another party's licence and never that licence itself.

LICENSE_BASIS_CONFIDENCES

How sure foley is that the basis applies to the route the sound came by.

VENDOR_WATERMARK_REPORTERS

Who stated a vendor's watermark (LicenseRecord.vendor_watermark['reported_by']): the source's config (its terms), or the vendor's response for this clip.

SOURCE_STATED_FIELDS

The LicenseRecord fields a source states (in its config's license block, or per clip): none is derived from a license_id row and none is a permission, so stamping them never widens a record.

EU_MEMBER_STATES

The EU's member states (ISO 3166-1 alpha-2), for a licence that excludes "EU", with the EU territories that carry their own codes: France's outermost regions (Réunion, French Guiana, Guadeloupe, Martinique, Mayotte, Saint-Martin) and Finland's Åland.

LICENSE_EXCLUDED_TERRITORIES

license_id -> the territories where it grants nothing (ISO 3166-1 alpha-2 codes, plus "EU" for every member state).

REVENUE_CAP

The usage restrictions an export states beside its licence code, as lacing.Restriction kinds (lacing#106; a test pins them to lacing's names).

LICENSE_TERMS_PROVIDER

Whose terms a provider-terms license_id is, under the provider names a consumer classifies them by (an's PROVIDER_TERMS: a code counts only on a source whose provider is that provider).

CONSUMER_LICENSE_CODES

foley licence ids whose consumer code is not the id in lowercase.

PUBLIC_LICENSE_IDS

the public CC ones.

CONSUMER_LICENSE_CLASSES

A licence's class for a consumer, from the least to the most restrictive (the classes an's license_class gives).

RESTAMP_FIELDS

The fields that say a stored licence and a fresh one differ besides their rights (wider_rights(), either way); verified_at does not.

REMADE_CREDIT_FIELDS

The credit fields a re-made sound's fresh record corrects besides RESTAMP_FIELDS (restamped_license(remade=True)): who made it, from where.

NO_RECORD_REASON

The reason a placed sound with no record (nothing to read a licence from) is refused.

Functions

ai_scope_from_gen_ai_preference(preference)

Map a Freesound gen_ai_preference to (ai_training_ok override, scope).

ai_use_permitted(record, *, ...)

Whether AI use of the sound (CLAP-embedding it counts) is allowed here.

apply_license_flags(record, *[, overrides])

Populate record's eight derived flags from its license_id (+ overrides), in place, and return it.

carries_own_restriction(license_id)

Whether license_id restricts beyond what its class says, so that no other licence's code can stand in for it: a revenue cap, or a provider's own terms (LICENSE_TERMS_PROVIDER, which a consumer attaches restrictions to).

carries_share_alike(record, license_id)

Whether a work made from record may be released under the share-alike license_id.

carry_lineage(new, old)

Copy old's lineage onto new, in place, and return new.

cc_refused_terms(url)

The NoDerivatives / ShareAlike terms of a CC licence URL or label.

check_placed(records, intended_use, *, what)

The one rights gate for placed sounds (a plan's, a weave's): raise, warn, or pass.

checked_refusal_reason(record, intended_use)

refusal_reason(), fail-closed: an error while checking is itself a reason.

code_implies_at_most(code, record, *[, ...])

Whether exporting record under the licence code, with restrictions stated beside it (lacing.Restriction dicts, license_restrictions()), tells a consumer no more than record allows (None, UNKNOWN, implies nothing).

consumer_license_class(license_id)

The CONSUMER_LICENSE_CLASSES entry of license_id, from its flag row.

consumer_license_code(license_id)

foley's license_id as a consumer's licence code: the SSOT consumers import.

derivative_refusal(source)

Why a sound with rights source may not be edited into a new sound, or None.

derive_license_flags(license_id, *[, overrides])

Look up the flag set for a license_id (fail-closed fallback), then apply per-source overrides.

derived_license_ids(record)

The licence ids of every sound record derives from ([]: not derived).

excluded_territories(record)

Where record's licence, or any licence it derives from, grants nothing.

export_refusal(source)

Why the bytes of a sound with rights source may not be exported, or None.

exported_licence_wider(record, bound)

What the licence record is exported under allows that bound's does not.

granted_flags(license_id)

What license_id grants anyone, as a consumer reads its code (fail closed).

intended_use_for([intended_use, ...])

The rights intent a verb runs under — every verb and surface resolves it here (#63).

is_cc_license_token(token)

Whether token is a search constraint a CC-reading source understands.

is_share_alike(license_id)

Whether license_id (or a licence URL / label) is share-alike.

keep(record, intended_use)

Fail-closed candidate license gate (report 07 §8.2).

keep_sound(sound_record, intended_use)

Convenience: apply keep() to a SoundRecord's nested license.

license_id_from_cc_url(url)

Map a Creative-Commons license URL or label to (license_id, verified).

license_meta(license_id)

Return the display LicenseMeta for license_id (fail-closed fallback).

license_restrictions(record)

What record may not be used for that no licence code says, as lacing.Restriction dicts (the shape Restriction.model_dump() gives).

narrow_to_source(output, source)

Narrow output's rights to what source allows, in place (never widening).

placed_record(library, sound_id, *[, ...])

library's record for sound_id as a rights gate reads it, never raising.

refusal_reason(record, intended_use)

Why keep() refuses record for intended_use, or None if it keeps it.

refusals(sound_records, intended_use)

{sound id: reason} for each sound record keep() refuses for intended_use.

restamped_license(stored, fresh, *[, widen, ...])

What a stored sound's licence becomes when its source now states fresh.

rights_license_id(record, *[, restrictions])

The licence id a consumer should read record under, or None (UNKNOWN).

shared_share_alike(*records)

The share-alike licence a work made of records may be released under, or None.

stamp_source_terms(record, stated)

Write what a source stated about its terms onto record, in place, and return it.

territory_excluded(excluded, territory)

Whether territory is in excluded ("EU" covers its member states).

upload_refusal(source)

Why the bytes of a sound with rights source may not be sent to an edit backend, or None.

vendor_training_refusal(source, backend_config)

Why a sound with rights source may not be sent to the backend backend_config declares, because its vendor trains on what it is sent, or None.

wanted_license_ids(config, license)

The licence ids a license= request keeps, or None for every accepted one.

wider_rights(record, bound)

What record allows that bound does not ([]: no wider than bound).

Classes

LicenseFlags([commercial_ok, ...])

The eight derivable flags for one license_id (the table row type).

LicenseMeta(display_name[, url])

Human-facing display metadata for one license_id (name + canonical URL).

Exceptions

LicenseRefusal(refused)

A plan or a weave refused because a placed sound's licence does not serve the intent.

foley.licensing.AI_TRAINING_SCOPES: tuple[str, ...] = ('none', 'open_source_only', 'nc_open_source_only')#

The ai_training_scope values (None = no narrowing beyond ai_training_ok).

foley.licensing.ASSERTABLE_LICENSE_IDS = frozenset({'CC-BY-2.0', 'CC-BY-2.5', 'CC-BY-3.0', 'CC-BY-4.0', 'CC-BY-NC-2.0', 'CC-BY-NC-2.5', 'CC-BY-NC-3.0', 'CC-BY-NC-4.0', 'CC-Sampling+-1.0', 'CC0-1.0', 'MIT', 'Pixabay-Content', 'RemArc', 'Sonniss-GDC', 'Stability-Community', 'Tencent-Hunyuan-Community', 'elevenlabs-free-plan', 'elevenlabs-paid-plan', 'fal-partner-unverified', 'owned-pack', 'procedural-free', 'research-only', 'user-owned'})#

The ids a user may assert (foley ingest --license, a foley-license.toml).

foley.licensing.CC_VERSIONS: tuple[str, ...] = ('2.0', '2.5', '3.0', '4.0')#

The CC versions foley has rows for (Freesound, FSD50K, Clotho and Wikimedia use these).

foley.licensing.CONSUMER_LICENSE_CLASSES: tuple[str, ...] = ('free', 'attribution', 'noncommercial', 'unknown')#

A licence’s class for a consumer, from the least to the most restrictive (the classes an’s license_class gives).

foley.licensing.CONSUMER_LICENSE_CODES: dict[str, Optional[str]] = {'unknown': None}#

foley licence ids whose consumer code is not the id in lowercase. None is UNKNOWN (lacing.Rights.license is None), never unencumbered. Consumers (an’s music library and its foley fetcher) import consumer_license_code() rather than keep a copy of this table.

foley.licensing.DEFAULT_CC_VERSION = '4.0'#

The version assumed when a source gives a CC family with no version at all (Freesound’s search labels: "Attribution"). Rights are the same across versions; only the credit’s version is a guess, so the record keeps the label it was given.

foley.licensing.DEFAULT_INTENDED_USE = IntendedUse(commercial=True, publish=True, redistribute_standalone=False, will_train=False, can_attribute=True, revenue_usd=0, allow_voice_or_trademark=False, territory=None)#

The ONE rights intent every verb and surface defaults to (#63, maintainer decision 2026-10-03): commercial publishing, attributable. NC and SA material is refused unless a caller explicitly passes a different IntendedUse (or commercial_ok=False). Treat it as read-only; copy with dataclasses.replace.

foley.licensing.EU_MEMBER_STATES: frozenset = frozenset({'AT', 'AX', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GF', 'GP', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MF', 'MQ', 'MT', 'NL', 'PL', 'PT', 'RE', 'RO', 'SE', 'SI', 'SK', 'YT'})#

The EU’s member states (ISO 3166-1 alpha-2), for a licence that excludes “EU”, with the EU territories that carry their own codes: France’s outermost regions (Réunion, French Guiana, Guadeloupe, Martinique, Mayotte, Saint-Martin) and Finland’s Åland. (The Canaries, Azores, Madeira, Ceuta and Melilla have none.)

foley.licensing.GENERATION_FIELDS = ('generator_model', 'generator_version', 'generation_prompt', 'generation_prompt_used', 'generation_seed', 'generation_params', 'watermark', 'c2pa_manifest_ref')#

carry_lineage() keeps the stored record’s.

Type:

How a clip’s bytes were made

foley.licensing.GEN_AI_PREFERENCE_SCOPES: dict[str, tuple[Optional[bool], Optional[str]]] = {'no-additional-preferences': (None, None), 'no-gen-ai': (False, 'none'), 'noncommercial-open-source-models': (None, 'nc_open_source_only'), 'open-source-models': (None, 'open_source_only')}#

Freesound gen_ai_preference -> (ai_training_ok override, ai_training_scope). None as the override leaves the CC row’s flag alone. An unlisted value fails closed (see ai_scope_from_gen_ai_preference()).

foley.licensing.LICENSE_BASES: tuple[str, ...] = ('model-licence', 'vendor-tos', 'aggregator-label')#

the model’s own licence (its weights), the vendor’s terms of service, or a label an aggregator put on it (fal’s commercial, an Openverse row), which is a claim about another party’s licence and never that licence itself.

Type:

What a record’s rights rest on (LicenseRecord.license_basis)

foley.licensing.LICENSE_BASIS_CONFIDENCES: tuple[str, ...] = ('confirmed', 'unverified')#

How sure foley is that the basis applies to the route the sound came by.

foley.licensing.LICENSE_EXCLUDED_TERRITORIES: dict[str, frozenset] = {'Tencent-Hunyuan-Community': frozenset({'EU', 'GB', 'GG', 'GI', 'IM', 'JE', 'KR'})}#

license_id -> the territories where it grants nothing (ISO 3166-1 alpha-2 codes, plus "EU" for every member state). A row here makes the territory part of the use: keep() refuses when it is excluded, and when it is not stated.

foley.licensing.LICENSE_FLAGS: dict[str, LicenseFlags] = {'CC-BY-2.0': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=True, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-2.5': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=True, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-3.0': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=True, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-4.0': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=True, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-NC-2.0': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-NC-2.5': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-NC-3.0': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-NC-4.0': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-Sampling+-1.0': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC0-1.0': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=True, requires_attribution=False, revenue_cap_usd=None), 'ElevenLabs-SFX': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None), 'MIT': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=True, requires_attribution=True, revenue_cap_usd=None), 'PDM-1.0': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=True, requires_attribution=False, revenue_cap_usd=None), 'Pixabay-Content': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None), 'RemArc': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'Sonniss-GDC': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None), 'Stability-Community': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=1000000), 'Tencent-Hunyuan-Community': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None), 'elevenlabs-free-plan': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'elevenlabs-paid-plan': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None), 'fal-partner-unverified': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None), 'owned-pack': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=True, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None), 'procedural-free': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=True, requires_attribution=False, revenue_cap_usd=None), 'research-only': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=False, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None), 'unknown': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=False, modification_ok=False, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None), 'user-owned': LicenseFlags(commercial_ok=True, embed_in_derivative_ok=True, redistribute_standalone_ok=True, cache_bytes_ok=True, modification_ok=True, ai_training_ok=True, requires_attribution=False, revenue_cap_usd=None)}#

license_id -> default flag set (report 07 §8.1 seed table).

Order of LicenseFlags positional args:

commercial, embed, redistribute_standalone, cache_bytes, modification,
ai_training, requires_attribution, revenue_cap_usd
Type:

SSOT

foley.licensing.LICENSE_META: dict[str, LicenseMeta] = {'CC-BY-2.0': LicenseMeta(display_name='CC BY 2.0', url='https://creativecommons.org/licenses/by/2.0/'), 'CC-BY-2.5': LicenseMeta(display_name='CC BY 2.5', url='https://creativecommons.org/licenses/by/2.5/'), 'CC-BY-3.0': LicenseMeta(display_name='CC BY 3.0', url='https://creativecommons.org/licenses/by/3.0/'), 'CC-BY-4.0': LicenseMeta(display_name='CC BY 4.0', url='https://creativecommons.org/licenses/by/4.0/'), 'CC-BY-NC-2.0': LicenseMeta(display_name='CC BY-NC 2.0', url='https://creativecommons.org/licenses/by-nc/2.0/'), 'CC-BY-NC-2.5': LicenseMeta(display_name='CC BY-NC 2.5', url='https://creativecommons.org/licenses/by-nc/2.5/'), 'CC-BY-NC-3.0': LicenseMeta(display_name='CC BY-NC 3.0', url='https://creativecommons.org/licenses/by-nc/3.0/'), 'CC-BY-NC-4.0': LicenseMeta(display_name='CC BY-NC 4.0', url='https://creativecommons.org/licenses/by-nc/4.0/'), 'CC-BY-NC-SA-2.0': LicenseMeta(display_name='CC BY-NC-SA 2.0', url='https://creativecommons.org/licenses/by-nc-sa/2.0/'), 'CC-BY-NC-SA-2.5': LicenseMeta(display_name='CC BY-NC-SA 2.5', url='https://creativecommons.org/licenses/by-nc-sa/2.5/'), 'CC-BY-NC-SA-3.0': LicenseMeta(display_name='CC BY-NC-SA 3.0', url='https://creativecommons.org/licenses/by-nc-sa/3.0/'), 'CC-BY-NC-SA-4.0': LicenseMeta(display_name='CC BY-NC-SA 4.0', url='https://creativecommons.org/licenses/by-nc-sa/4.0/'), 'CC-BY-SA-2.0': LicenseMeta(display_name='CC BY-SA 2.0', url='https://creativecommons.org/licenses/by-sa/2.0/'), 'CC-BY-SA-2.5': LicenseMeta(display_name='CC BY-SA 2.5', url='https://creativecommons.org/licenses/by-sa/2.5/'), 'CC-BY-SA-3.0': LicenseMeta(display_name='CC BY-SA 3.0', url='https://creativecommons.org/licenses/by-sa/3.0/'), 'CC-BY-SA-4.0': LicenseMeta(display_name='CC BY-SA 4.0', url='https://creativecommons.org/licenses/by-sa/4.0/'), 'CC-Sampling+-1.0': LicenseMeta(display_name='CC Sampling+ 1.0', url='https://creativecommons.org/licenses/sampling+/1.0/'), 'CC0-1.0': LicenseMeta(display_name='CC0 1.0 Universal (Public Domain Dedication)', url='https://creativecommons.org/publicdomain/zero/1.0/'), 'ElevenLabs-SFX': LicenseMeta(display_name='ElevenLabs Sound Effects Terms (legacy: paid plan assumed)', url='https://elevenlabs.io/terms-of-use'), 'MIT': LicenseMeta(display_name='MIT License', url='https://opensource.org/license/mit'), 'PDM-1.0': LicenseMeta(display_name='Public Domain Mark 1.0 (unverified claim)', url='https://creativecommons.org/publicdomain/mark/1.0/'), 'Pixabay-Content': LicenseMeta(display_name='Pixabay Content License', url='https://pixabay.com/service/license-summary/'), 'RemArc': LicenseMeta(display_name='BBC RemArc Licence', url='https://sound-effects.bbcrewind.co.uk/licensing'), 'Sonniss-GDC': LicenseMeta(display_name='Sonniss GDC Game Audio Bundle License', url='https://sonniss.com/gdc-bundle-license'), 'Stability-Community': LicenseMeta(display_name='Stability AI Community License', url='https://stability.ai/community-license-agreement'), 'Tencent-Hunyuan-Community': LicenseMeta(display_name='Tencent Hunyuan Community License (not valid in the EU, the UK or South Korea)', url='https://huggingface.co/tencent/HunyuanVideo-Foley/blob/main/LICENSE'), 'elevenlabs-free-plan': LicenseMeta(display_name='ElevenLabs Terms (free plan: non-commercial, attribution required)', url='https://elevenlabs.io/terms-of-use'), 'elevenlabs-paid-plan': LicenseMeta(display_name='ElevenLabs Terms (paid plan)', url='https://elevenlabs.io/terms-of-use'), 'fal-partner-unverified': LicenseMeta(display_name='fal.ai partner model (vendor terms for fal-routed calls unverified: treated as non-commercial)', url='https://fal.ai/legal/terms-of-service'), 'owned-pack': LicenseMeta(display_name='Purchased sound-effects library (its EULA: use in productions, no redistribution of the raw files)', url=None), 'procedural-free': LicenseMeta(display_name='Procedural synthesis output (no licence attaches)', url=None), 'research-only': LicenseMeta(display_name='Research use only (no commercial or public use)', url=None), 'unknown': LicenseMeta(display_name='Unknown / unverified license', url=None), 'user-owned': LicenseMeta(display_name='User-owned / original work', url=None)}#

license_id -> display name + canonical URL (one row per LICENSE_FLAGS key). Used only for human-readable credits; never for permission decisions (those come from LICENSE_FLAGS).

Type:

SSOT

foley.licensing.LICENSE_TERMS_PROVIDER: dict[str, str] = {'ElevenLabs-SFX': 'elevenlabs', 'Stability-Community': 'stability-ai', 'elevenlabs-free-plan': 'elevenlabs', 'elevenlabs-paid-plan': 'elevenlabs'}#

Whose terms a provider-terms license_id is, under the provider names a consumer classifies them by (an’s PROVIDER_TERMS: a code counts only on a source whose provider is that provider). Used as Rights.provider on export (#66), so a Stable Audio clip reads as Stability’s Community License, with its revenue cap, whichever foley source (local, fal) made it. Ids not listed are their source’s own.

class foley.licensing.LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=False, modification_ok=False, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None)[source]#

Bases: object

The eight derivable flags for one license_id (the table row type).

class foley.licensing.LicenseMeta(display_name, url=None)[source]#

Bases: object

Human-facing display metadata for one license_id (name + canonical URL).

The presentation sibling of LicenseFlags: where LicenseFlags holds the permission row consulted by keep(), LicenseMeta holds the display row consulted by the credits/attribution layer (foley.provenance.credits). Kept here so licensing stays the single license authority; a record’s own license_name / license_url (when a source populated them) take precedence over this default.

exception foley.licensing.LicenseRefusal(refused)[source]#

Bases: ValueError

A plan or a weave refused because a placed sound’s licence does not serve the intent.

Raised by foley.plan() and foley.weave() when they are given an explicit intended_use= (#208). refused is {sound id: reason} for every refused sound (refusals()); the message names each of them.

>>> err = LicenseRefusal({"a": "no grant in EU"})
>>> err.refused, str(err)
({'a': 'no grant in EU'}, 'not licensed for this use: a: no grant in EU')
foley.licensing.NO_RECORD_REASON = 'it has no record in the library, so its licence cannot be checked'#

The reason a placed sound with no record (nothing to read a licence from) is refused.

foley.licensing.PUBLIC_LICENSE_IDS: frozenset = frozenset({'CC-BY-2.0', 'CC-BY-2.5', 'CC-BY-3.0', 'CC-BY-4.0', 'CC-BY-NC-2.0', 'CC-BY-NC-2.5', 'CC-BY-NC-3.0', 'CC-BY-NC-4.0', 'CC0-1.0'})#

the public CC ones. A provider-terms or private code (stability-community, user-owned, owned-pack) is classifiable only on its own provider’s record, so in an edit’s lineage, where that provider is gone, it reads as UNKNOWN. MIT is left out until consumers agree it owes a credit (foley’s row says it does; an reads mit as free with nothing owed), so an MIT link fails closed.

Type:

Licences whose code means the same to any consumer, whoever the provider

foley.licensing.REMADE_CREDIT_FIELDS = ('source', 'source_id', 'source_url', 'creator_name', 'creator_url')#

The credit fields a re-made sound’s fresh record corrects besides RESTAMP_FIELDS (restamped_license(remade=True)): who made it, from where.

foley.licensing.RESTAMP_FIELDS = ('license_id', 'rights_verified', 'license_url', 'license_name', 'rights_holder', 'attribution_text')#

The fields that say a stored licence and a fresh one differ besides their rights (wider_rights(), either way); verified_at does not.

foley.licensing.REVENUE_CAP = 'revenue_cap'#

The usage restrictions an export states beside its licence code, as lacing.Restriction kinds (lacing#106; a test pins them to lacing’s names).

foley.licensing.SHARE_ALIKE_FLAGS: dict[str, LicenseFlags] = {'CC-BY-NC-SA-2.0': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=False, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-NC-SA-2.5': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=False, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-NC-SA-3.0': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=False, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-NC-SA-4.0': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=False, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-SA-2.0': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=False, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-SA-2.5': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=False, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-SA-3.0': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=False, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None), 'CC-BY-SA-4.0': LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=False, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None)}#

The share-alike licence ids foley can name -> SHARE_ALIKE_LICENSE_FLAGS. Deliberately not LICENSE_FLAGS rows: they are never assertable on ingest, and every gate that needs a licence row (an edit, a mix) still refuses them, except the identical-licence mix. derive_license_flags() reads them after LICENSE_FLAGS, so a record under one is bounded by this row (and credited).

foley.licensing.SHARE_ALIKE_LICENSE_FLAGS = LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=True, modification_ok=False, ai_training_ok=False, requires_attribution=True, revenue_cap_usd=None)#

it may keep the bytes, and must credit them; nothing else. Every other use foley makes (publishing in a derivative, an edit, training) makes an adaptation that must carry the licence, which foley’s gates cannot express, so keep() and the edit gate refuse it. The licence itself travels as the record’s license_id (an export’s consumer code). The one work foley does make from it is a mix of sources all under the identical licence (shared_share_alike()), released under that licence.

Type:

What foley grants itself under a share-alike licence

foley.licensing.SOURCE_STATED_FIELDS: tuple[str, ...] = ('license_basis', 'license_basis_confidence', 'vendor_trains_on_output', 'terms_notes', 'vendor_watermark')#

The LicenseRecord fields a source states (in its config’s license block, or per clip): none is derived from a license_id row and none is a permission, so stamping them never widens a record.

foley.licensing.UNASSERTABLE_LICENSE_IDS = frozenset({'ElevenLabs-SFX', 'PDM-1.0', 'unknown'})#

Licence ids that can never be asserted as verified (on ingest, restamp or in a folder sidecar): unknown by definition, PDM-1.0 (a claim about the work, not a grant — verify it by building the LicenseRecord yourself), and the legacy ElevenLabs-SFX row (say the plan).

foley.licensing.UNKNOWN_LICENSE_FLAGS = LicenseFlags(commercial_ok=False, embed_in_derivative_ok=False, redistribute_standalone_ok=False, cache_bytes_ok=False, modification_ok=False, ai_training_ok=False, requires_attribution=False, revenue_cap_usd=None)#

Fail-closed fallback for unknown / Proprietary-* license ids (all False, cap None).

foley.licensing.UNKNOWN_LICENSE_META = LicenseMeta(display_name='Unknown / unverified license', url=None)#

Fail-closed display fallback for unknown / Proprietary-* license ids.

foley.licensing.VENDOR_WATERMARK_REPORTERS: tuple[str, ...] = ('config', 'response')#

Who stated a vendor’s watermark (LicenseRecord.vendor_watermark['reported_by']): the source’s config (its terms), or the vendor’s response for this clip.

foley.licensing.ai_scope_from_gen_ai_preference(preference)[source]#

Map a Freesound gen_ai_preference to (ai_training_ok override, scope).

All four published values are honoured (only no-gen-ai was before #69). A missing value means no stated preference; an unrecognised one fails closed.

Return type:

tuple[Optional[bool], Optional[str]]

foley.licensing.ai_use_permitted(record, *, open_source_model, commercial)[source]#

Whether AI use of the sound (CLAP-embedding it counts) is allowed here.

ai_training_ok must hold, and the record’s ai_training_scope must admit this use: open_source_only needs an open-source model, nc_open_source_only also needs a non-commercial purpose, none admits nothing.

Parameters:
  • record (LicenseRecord) – The rights record.

  • open_source_model (bool) – Whether the model using the audio is open source (the embedder’s open_source attribute; LAION-CLAP is).

  • commercial (bool) – Whether the purpose is commercial (foley’s default intent).

Return type:

bool

foley.licensing.apply_license_flags(record, *, overrides=None)[source]#

Populate record’s eight derived flags from its license_id (+ overrides), in place, and return it.

A derivative (an edit, #162) stays bounded by every licence it derives from (derived_license_ids()): each one’s row is ANDed in after the overrides, so re-deriving its flags (a restamp to the generator’s licence, a reload) never widens them back (#214). A record that derives from nothing is unaffected.

Does NOT touch rights_verified — verification is a separate concern.

Parameters:
Return type:

LicenseRecord

Returns:

The same (mutated) record.

>>> from foley.base import LicenseRecord
>>> edit = LicenseRecord(source="g", license_id="Stability-Community",
...                      derived_from_license_ids=["CC-BY-NC-4.0"])
>>> apply_license_flags(edit, overrides={"commercial_ok": True}).commercial_ok
False
foley.licensing.carries_own_restriction(license_id)[source]#

Whether license_id restricts beyond what its class says, so that no other licence’s code can stand in for it: a revenue cap, or a provider’s own terms (LICENSE_TERMS_PROVIDER, which a consumer attaches restrictions to).

>>> carries_own_restriction("Stability-Community"), carries_own_restriction("CC-BY-4.0")
(True, False)
Return type:

bool

foley.licensing.carries_share_alike(record, license_id)[source]#

Whether a work made from record may be released under the share-alike license_id.

It may when license_id is a share-alike licence foley can name (SHARE_ALIKE_FLAGS), record is under it, and every licence record derives from (derived_license_ids()) is that same one: its obligations are then exactly the licence’s. Another version, another family (BY-NC-SA is not BY-SA) or anything else in the lineage fails closed.

>>> sa = LicenseRecord(source="s", license_id="CC-BY-SA-4.0")
>>> carries_share_alike(sa, "CC-BY-SA-4.0"), carries_share_alike(sa, "CC-BY-SA-3.0")
(True, False)
>>> carries_share_alike(LicenseRecord(source="s", license_id="CC-BY-SA-4.0",
...     derived_from_license_ids=["CC0-1.0"]), "CC-BY-SA-4.0")
False
Return type:

bool

foley.licensing.carry_lineage(new, old)[source]#

Copy old’s lineage onto new, in place, and return new.

The lineage is what a re-stamped record must keep from the one it replaces: its transformations (the edits and fixes, so the credit still reads “(modified)”), its derived_from_license_ids (the licences bounding it, #214), its terms_notes (added to new’s: the source’s API obligations, #77) and the facts about its bytes (a vendor that reuses them, the vendor’s watermark, that they are AI-generated and to be disclosed, and how they were made: GENERATION_FIELDS, old’s where it states them). Fresh lists, so the two records never share one; a None reads as empty. new’s flags are then bounded by every licence it now derives from (never widened), so the copy is safe on its own; a later apply_license_flags() re-derives under the same bound.

>>> from foley.base import LicenseRecord
>>> old = LicenseRecord(source="g", transformations=["declick"],
...                     derived_from_license_ids=["CC-BY-NC-4.0"])
>>> new = carry_lineage(LicenseRecord(source="g"), old)
>>> new.transformations, new.derived_from_license_ids
(['declick'], ['CC-BY-NC-4.0'])
>>> new.transformations is old.transformations
False
>>> cc0 = apply_license_flags(LicenseRecord(source="g", license_id="CC0-1.0"))
>>> carry_lineage(cc0, old).commercial_ok
False
Return type:

LicenseRecord

foley.licensing.cc_refused_terms(url)[source]#

The NoDerivatives / ShareAlike terms of a CC licence URL or label.

license_id_from_cc_url() refuses these on purpose (foley has no licence row expressing them, so it maps them to 'unknown'); this says why a URL was refused, for a message that is not “cannot read a licence”.

>>> cc_refused_terms("https://creativecommons.org/licenses/by-nc-sa/4.0/")
('ShareAlike',)
>>> cc_refused_terms("CC BY-ND-SA"), cc_refused_terms("https://creativecommons.org/licenses/by/4.0/")
(('NoDerivatives', 'ShareAlike'), ())
>>> cc_refused_terms(None)
()
Return type:

tuple[str, ...]

foley.licensing.check_placed(records, intended_use, *, what)[source]#

The one rights gate for placed sounds (a plan’s, a weave’s): raise, warn, or pass.

With an explicit intended_use, fail-closed: raise LicenseRefusal naming every sound in records ({sound id: SoundRecord or None}) the intent does not keep. With None (the migration default, #208), nothing is refused, but if DEFAULT_INTENDED_USE would refuse anything, one FutureWarning names each such id and reason: a future release gates by default.

Parameters:
  • records (Mapping[str, object]) – The placed sounds, by id (None for one with no record).

  • intended_use (Optional[IntendedUse]) – The caller’s rights intent, or None (today’s behaviour).

  • what (str) – The façade’s name, for the warning ("foley.plan"); the warning points at the first caller outside foley.

Raises:

LicenseRefusal – If intended_use is given and refuses any sound.

Return type:

None

foley.licensing.checked_refusal_reason(record, intended_use)[source]#

refusal_reason(), fail-closed: an error while checking is itself a reason.

The one place a rights check is allowed to fail: whatever goes wrong reading record (a missing or malformed licence) refuses it, with the error as the reason, so no caller can keep a sound whose licence it could not read.

Parameters:
Return type:

Optional[str]

Returns:

None only when keep() keeps record; otherwise why not.

>>> lic = LicenseRecord(source="user", license_id="CC0-1.0", commercial_ok=True,
...                     rights_verified=True)
>>> checked_refusal_reason(lic, IntendedUse()) is None
True
>>> checked_refusal_reason(None, IntendedUse())
"its licence could not be checked (AttributeError: 'NoneType' object has no attribute 'rights_verified')"
foley.licensing.code_implies_at_most(code, record, *, restrictions=())[source]#

Whether exporting record under the licence code, with restrictions stated beside it (lacing.Restriction dicts, license_restrictions()), tells a consumer no more than record allows (None, UNKNOWN, implies nothing).

The export is judged as a consumer reads it: the code’s flags under the lowest stated revenue cap, and the code’s excluded territories plus the stated ones.

Every one must hold (_no_wider(): the permissions of _CODE_PERMISSIONS, attribution, the revenue cap):

  • the code’s row (what foley derives under it) is no wider than the record’s own flags, so a narrowing the record holds is never dropped;

  • what the code grants anyone (granted_flags()) is no wider than what each licence of the record’s chain grants, so a lineage restriction is never dropped (needed for share-alike, whose flags are foley’s self-limit and show none);

  • it excludes every territory the chain excludes (excluded_territories());

  • it is every share-alike licence of the chain: no other licence (another version, CC BY-NC-SA for CC BY-SA) satisfies a share-alike term.

AI use is not compared: a code says nothing a consumer reads about it, so the consumer reads it from the export’s provenance (see _CODE_PERMISSIONS).

>>> sa_nc = apply_license_flags(LicenseRecord(source="s", license_id="CC-BY-SA-4.0",
...     derived_from_license_ids=["CC-BY-NC-4.0"]))
>>> [code_implies_at_most(c, sa_nc) for c in ("CC-BY-SA-4.0", "CC-BY-NC-4.0",
...                                           "CC-BY-NC-SA-4.0", None)]
[False, False, False, True]
Return type:

bool

foley.licensing.consumer_license_class(license_id)[source]#

The CONSUMER_LICENSE_CLASSES entry of license_id, from its flag row.

>>> [consumer_license_class(i) for i in ("CC0-1.0", "CC-BY-4.0", "CC-BY-NC-4.0")]
['free', 'attribution', 'noncommercial']
>>> consumer_license_class("Tencent-Hunyuan-Community"), consumer_license_class("x")
('unknown', 'unknown')
Return type:

str

foley.licensing.consumer_license_code(license_id)[source]#

foley’s license_id as a consumer’s licence code: the SSOT consumers import.

CONSUMER_LICENSE_CODES first, else the id in lowercase (an SPDX-style code such as cc-by-4.0, or a provider’s own code such as stability-community, read with LICENSE_TERMS_PROVIDER).

>>> consumer_license_code("CC0-1.0"), consumer_license_code("unknown")
('cc0-1.0', None)
>>> consumer_license_code(None) is None
True
Return type:

Optional[str]

foley.licensing.derivative_refusal(source)[source]#

Why a sound with rights source may not be edited into a new sound, or None.

The fail-closed gate of an edit (#162), applied by the generation’s edit mode before anything is paid for. The first unmet requirement: its rights are verified; its bytes may be sent on (upload_refusal()); its licence is not share-alike (the edit’s own licence, the generator’s, cannot carry it); its licence has a LICENSE_FLAGS row (else the edit’s rights cannot be derived); it allows modification; it excludes no territory (which the edit’s record could not carry). Every other restriction carries over to the edit (narrow_to_source()).

>>> from foley.base import LicenseRecord
>>> ok = apply_license_flags(LicenseRecord(source="x", license_id="CC-BY-4.0",
...                                        rights_verified=True))
>>> derivative_refusal(ok) is None
True
>>> derivative_refusal(apply_license_flags(LicenseRecord(source="x",
...                                                      license_id="research-only",
...                                                      rights_verified=True)))
'its licence does not allow modification'
Return type:

Optional[str]

foley.licensing.derive_license_flags(license_id, *, overrides=None)[source]#

Look up the flag set for a license_id (fail-closed fallback), then apply per-source overrides.

Parameters:
  • license_id (str) – The normalized license id (SPDX or foley-specific token).

  • overrides (Optional[dict]) – Optional per-source flag overrides — e.g. Freesound forces cache_bytes_ok=False on CC0. Keys must be LicenseFlags fields.

Returns:

the LICENSE_FLAGS row, else the SHARE_ALIKE_FLAGS one, else the all-False UNKNOWN_LICENSE_FLAGS (fail closed).

Return type:

LicenseFlags

Raises:

ValueError – If overrides contains a key that is not a LicenseFlags field.

foley.licensing.derived_license_ids(record)[source]#

The licence ids of every sound record derives from ([]: not derived).

The merge of two records of it: its derived_from_license_ids field (#214), plus the source_license_id of each edit entry in its transformations (#162), so a record stored before the field existed is still bounded by its source. In order, without repeats.

That legacy fallback sees only the direct source: an edit entry names its parent’s licence, not the licences the parent itself derived from. So an edit of an edit stored before this release (no derived_from_license_ids) is bounded by its parent’s licence only, not its grandparent’s. Re-running the edit, or narrowing it again with narrow_to_source(), records the full chain.

>>> from foley.base import LicenseRecord
>>> derived_license_ids(LicenseRecord(source="g"))
[]
>>> derived_license_ids(LicenseRecord(source="g", derived_from_license_ids=["CC-BY-4.0"],
...     transformations=["declick", {"kind": "edit", "source_license_id": "CC-BY-NC-4.0"}]))
['CC-BY-4.0', 'CC-BY-NC-4.0']
Return type:

list[str]

foley.licensing.excluded_territories(record)[source]#

Where record’s licence, or any licence it derives from, grants nothing.

LICENSE_EXCLUDED_TERRITORIES is the SSOT (an exclusion is a term of the licence, not of one sound), read over the record’s whole lineage (derived_license_ids()), so a record restamped or narrowed by an excluding licence is gated too. Sorted codes; [] when nothing is excluded.

>>> excluded_territories(LicenseRecord(source="s", license_id="CC0-1.0"))
[]
>>> excluded_territories(LicenseRecord(source="s", license_id="CC0-1.0",
...     derived_from_license_ids=["Tencent-Hunyuan-Community"]))[:3]
['EU', 'GB', 'GG']
Return type:

list[str]

foley.licensing.export_refusal(source)[source]#

Why the bytes of a sound with rights source may not be exported, or None.

The gate of foley.export_sound(), fail-closed: an export hands the bytes to another store, which is keeping them, so it follows cache_bytes_ok exactly as storage does (foley.stores.store_sound()).

>>> from foley.base import LicenseRecord
>>> export_refusal(LicenseRecord(source="x", cache_bytes_ok=True)) is None
True
>>> export_refusal(LicenseRecord(source="freesound"))[-24:]
'fetch it from its source'
Return type:

Optional[str]

foley.licensing.exported_licence_wider(record, bound)[source]#

What the licence record is exported under allows that bound’s does not.

Read off rights_license_id() (the code a consumer classifies), for two verified records: a known code where bound reads as unknown, a commercial one where bound’s is non-commercial, one without share-alike where bound’s has it, or a less restrictive consumer class (CONSUMER_LICENSE_CLASSES).

>>> from foley.base import LicenseRecord
>>> ncsa = LicenseRecord(source="s", license_id="CC-BY-NC-SA-4.0", rights_verified=True)
>>> sa = LicenseRecord(source="s", license_id="CC-BY-SA-4.0", rights_verified=True)
>>> exported_licence_wider(sa, ncsa), exported_licence_wider(ncsa, sa)
(['commercial use (CC-BY-NC-SA-4.0 -> CC-BY-SA-4.0)'], [])
Return type:

list[str]

foley.licensing.granted_flags(license_id)[source]#

What license_id grants anyone, as a consumer reads its code (fail closed).

Its LICENSE_FLAGS row; for a share-alike licence foley can name, the row of its family without the share-alike term (CC BY-SA 4.0 grants what CC BY 4.0 does, under the obligation to share alike): SHARE_ALIKE_LICENSE_FLAGS is what foley grants itself under it, not what the licence grants. Else all False.

>>> granted_flags("CC-BY-SA-4.0") == LICENSE_FLAGS["CC-BY-4.0"]
True
>>> granted_flags("CC-BY-NC-SA-3.0") == LICENSE_FLAGS["CC-BY-NC-3.0"]
True
>>> granted_flags(None) == UNKNOWN_LICENSE_FLAGS
True
Return type:

LicenseFlags

foley.licensing.intended_use_for(intended_use=None, *, commercial_ok=None, territory=None)[source]#

The rights intent a verb runs under — every verb and surface resolves it here (#63).

An explicit intended_use wins; else DEFAULT_INTENDED_USE, with commercial overridden when commercial_ok is given (False is the explicit opt-in to non-commercial material) and territory when given (an ISO 3166-1 alpha-2 code, or "WORLD"; #175). Always a fresh copy, so callers may mutate it.

>>> intended_use_for(commercial_ok=False, territory="us").territory
'US'
Raises:

ValueError – If both are given and disagree on commercial or territory, or the territory is not a code.

Return type:

IntendedUse

foley.licensing.is_cc_license_token(token)[source]#

Whether token is a search constraint a CC-reading source understands.

None/'any' (no constraint), 'cc0', or a CC / public-domain licence id or family ('CC-BY-4.0', 'cc-by', 'PDM-1.0'). Not an ingest-time rights assertion such as 'user-owned'.

Return type:

bool

foley.licensing.is_share_alike(license_id)[source]#

Whether license_id (or a licence URL / label) is share-alike.

Read with the same tokens license_id_from_cc_url() refuses share-alike by: no LICENSE_FLAGS row is share-alike (the mapper sends every such licence to 'unknown'), so this catches an id stamped by hand or by a source.

>>> is_share_alike("CC-BY-SA-4.0"), is_share_alike("CC-BY-4.0"), is_share_alike(None)
(True, False, False)
Return type:

bool

foley.licensing.keep(record, intended_use)[source]#

Fail-closed candidate license gate (report 07 §8.2).

Run BEFORE ranking/verification in the agent’s decide(). Unknown or unverified rights => reject. Any single unmet requirement => reject.

Parameters:
  • record (LicenseRecord) – The candidate’s rights record.

  • intended_use (IntendedUse) – The caller’s declared intent.

Return type:

bool

Returns:

True only if every requirement in intended_use is satisfied by record; False otherwise (including unverified rights).

foley.licensing.keep_sound(sound_record, intended_use)[source]#

Convenience: apply keep() to a SoundRecord’s nested license.

Parameters:
  • sound_record – A SoundRecord (its .license is the SSOT consulted).

  • intended_use (IntendedUse) – The caller’s declared intent.

Return type:

bool

Returns:

The result of keep(sound_record.license, intended_use).

foley.licensing.license_id_from_cc_url(url)[source]#

Map a Creative-Commons license URL or label to (license_id, verified).

The single SSOT for turning an external source’s license string into a foley license_id (FSD50K, Clotho, the Freesound API, …). It never widens rights: the string is split into tokens, and

  • any NoDerivatives / ShareAlike sign (nd, sa, no derivatives, share alike, sharealike) → ('unknown', False): foley has no row expressing those restrictions, so the sound is refused everywhere;

  • the Public Domain Mark → ('PDM-1.0', False): a claim about the work, not a licence anyone granted, so never auto-verified (#56); a label that adds words to it (“not public domain”, “public domain in the US only”) → ('unknown', False);

  • CC0 (publicdomain/zero, cc0, creative commons 0) → CC0-1.0;

  • Sampling+ → CC-Sampling+-1.0;

  • by / attribution with any mention of commercial use (nc, noncommercial, non commercial, no commercial use) → CC-BY-NC-<v>, else CC-BY-<v>. The version is kept (/by/3.0/ → CC-BY-3.0); a versionless label gets DEFAULT_CC_VERSION; a version foley has no row for (a 2.1/jp port) fails closed;

  • anything else — including a string with a token this parser does not know — → ('unknown', False).

Parameters:

url (Optional[str]) – A CC license URL, a CC label string, or None.

Return type:

tuple[str, bool]

Returns:

(license_id, rights_verified).

foley.licensing.license_meta(license_id)[source]#

Return the display LicenseMeta for license_id (fail-closed fallback).

Parameters:

license_id (str) – The normalized license id.

Return type:

LicenseMeta

Returns:

The mapped LicenseMeta, or UNKNOWN_LICENSE_META for an unrecognized / Proprietary-* id.

foley.licensing.license_restrictions(record)[source]#

What record may not be used for that no licence code says, as lacing.Restriction dicts (the shape Restriction.model_dump() gives).

Read off the licences of the record’s chain, not its stored flags, so a record whose flags went stale still states every term:

  • revenue_cap: one per chain licence whose row caps revenue (terms its consumer code, usd its cap), plus one with terms=None when the record’s own cap is lower than all of them (a narrowing);

  • territory_excluded: one per chain licence that excludes territories (LICENSE_EXCLUDED_TERRITORIES), its codes sorted and verbatim (EU is a region code; lacing records it as given).

>>> license_restrictions(LicenseRecord(source="s", license_id="Stability-Community"))
({'kind': 'revenue_cap', 'terms': 'stability-community', 'usd': 1000000},)
>>> license_restrictions(LicenseRecord(source="s", license_id="CC0-1.0"))
()
Return type:

tuple[dict, ...]

foley.licensing.narrow_to_source(output, source)[source]#

Narrow output’s rights to what source allows, in place (never widening).

An edit is a derivative of its source: it may be used only where both the generator’s licence and the source’s allow. Each permission of _DERIVATIVE_SHARED_FLAGS is kept only when both hold it, attribution is required when either requires it, the revenue cap is the lower one, the AI-use scope is the stricter one, and the source’s required notice, terms notes, stated AI-use preference and safety flags carry over. cache_bytes_ok stays the output’s (it is about storing the new bytes). Routed through apply_license_flags(), so the flags still come from the policy layer, never set by hand.

>>> from foley.base import LicenseRecord
>>> out = apply_license_flags(LicenseRecord(source="g", license_id="Stability-Community"))
>>> src = apply_license_flags(LicenseRecord(source="s", license_id="CC-BY-NC-4.0"))
>>> narrowed = narrow_to_source(out, src)
>>> narrowed.commercial_ok, narrowed.requires_attribution, narrowed.revenue_cap_usd
(False, True, 1000000)
Return type:

LicenseRecord

foley.licensing.placed_record(library, sound_id, *, missing=None, unreadable=None)[source]#

library’s record for sound_id as a rights gate reads it, never raising.

The one lookup every placed-sound gate uses (a plan’s, a weave’s, the MCP verbs’), so they agree on what “no record” means (#208):

  • missing when there is no entry: library is None, or the lookup raises a LookupError (the id is genuinely absent);

  • unreadable (default None) when the lookup fails any other way (a corrupt stored record, a broken backend): an entry that is there but cannot be judged;

  • None when the value has no .license (a plain-mapping library of audio arrays holds sounds, not records).

None is what the fail-closed gate (refusals()) refuses under an explicit intent, and what the no-intent path only warns about, so a bad library can make a gated call refuse but never make an ungated one raise.

>>> from foley.base import SoundRecord
>>> rec = SoundRecord(id="a", license=LicenseRecord(source="user"))
>>> placed_record({"a": rec}, "a") is rec
True
>>> placed_record({"a": rec}, "b", missing="own"), placed_record(None, "a")
('own', None)
>>> placed_record({"a": [0.0, 0.1]}, "a") is None  # audio, not a record
True
>>> class Corrupt(dict):
...     def __getitem__(self, k):
...         raise ValueError("bad JSON")
>>> placed_record(Corrupt(), "a", missing="own") is None
True
foley.licensing.refusal_reason(record, intended_use)[source]#

Why keep() refuses record for intended_use, or None if it keeps it.

The one rule, read as text: the first requirement the record does not meet.

Return type:

Optional[str]

foley.licensing.refusals(sound_records, intended_use)[source]#

{sound id: reason} for each sound record keep() refuses for intended_use.

The re-check a placed sound gets where it is used (a plan, a weave), whatever intent it was found under (#191). Takes SoundRecord s (each judged by its .license through checked_refusal_reason(), so fail-closed: a record without a readable licence is refused), or a mapping {sound id: record} in which a None record (the sound has none) is refused too. Empty when every sound is kept.

>>> refusals({"a": None}, IntendedUse())
{'a': 'it has no record in the library, so its licence cannot be checked'}
Return type:

dict[str, str]

foley.licensing.restamped_license(stored, fresh, *, widen=True, remade=False)[source]#

What a stored sound’s licence becomes when its source now states fresh.

Returns (new_record, note): new_record is None when the stored licence stays as it is, and note is None when there is nothing to say. Pure: neither argument is changed. The stored lineage (edits, the licences bounding it) is always kept (carry_lineage()). terms_notes are not rights: fresh’s are added to the stored record whatever happens to its licence (then new_record is the stored licence with them, even when its rights stay).

  • widen=True: fresh replaces the stored licence. For a source that is the authority on its own clips (a corpus’s metadata, foley.bootstrap.bootstrap()).

  • widen=False: rights are never widened. fresh replaces an unverified stored licence (nobody asserted it) or one it is no wider than (wider_rights()). When fresh grants more than the stored licence and no less, the stored one is kept with a note naming the widening to apply by hand (foley.index.ingest.restamp_rights()). When each grants something the other does not, the stored licence is bounded by fresh (narrow_to_source()): the sound may be used only where both allow.

remade=True: the sound was made again (a byte-identical derivative re-rendered with corrected credits), so fresh is its whole record: its lineage and credits (REMADE_CREDIT_FIELDS) replace the stored ones wherever fresh is applied. A credit change is a correction, not a widening; dropping a licence the stored record derives from (derived_license_ids()) whose row would still narrow it is a widening, so widen=False keeps it. Default False: the source restates its terms and the stored lineage (the edits made since) is kept.

>>> from foley.base import LicenseRecord
>>> cc0 = apply_license_flags(LicenseRecord(source="s", license_id="CC0-1.0", rights_verified=True))
>>> nc = apply_license_flags(LicenseRecord(source="s", license_id="CC-BY-NC-4.0", rights_verified=True))
>>> restamped_license(cc0, nc, widen=False)[0].license_id
'CC-BY-NC-4.0'
>>> new, note = restamped_license(nc, cc0, widen=False)
>>> new is None, note.startswith("not widened")
(True, True)
Return type:

tuple[Optional[LicenseRecord], Optional[str]]

foley.licensing.rights_license_id(record, *, restrictions=())[source]#

The licence id a consumer should read record under, or None (UNKNOWN).

restrictions are what the export states beside the code (license_restrictions(); sound_rights states them, #282): the code is judged together with them (code_implies_at_most()), so a cap or excluded territories stated there need not be implied by the code. A Stable Audio edit of a CC BY sound still gives None: Stability’s licence also bars standalone redistribution, which CC BY grants and no restriction kind states.

None when the rights are unverified (a Public Domain Mark is a claim, not a grant). For a clip derived from others (an edit, derived_license_ids()), the most restrictive of its own licence and every source’s: an edit keeps its generator’s license_id and narrows only its flags, so exporting that id alone would read a Stable Audio edit of a CC BY-NC sound as free. A source licence that is not public (PUBLIC_LICENSE_IDS) counts as UNKNOWN, and a source that wins as UNKNOWN gives None. Ties go to the clip’s own licence.

A code is returned only when it alone carries every restriction of the chain: a source that wins over a clip whose own licence restricts beyond its class (carries_own_restriction(): a revenue cap, a provider’s terms) gives None, since a Rights record has one licence field and the source’s public code would drop the clip’s restriction (Stability’s revenue cap).

The final gate, whatever the path (an edit, a restamp, a broadcast, a plain record), is code_implies_at_most(): a code that would let a consumer do more than the record allows gives None (#274). No other code stands in: CC BY-NC-SA is not what a CC BY-SA record bounded by CC BY-NC may be released under (BY-SA requires adaptations under BY-SA or a compatible licence, and NC-SA is neither).

>>> def rec(lid, *lineage):
...     return apply_license_flags(LicenseRecord(source="s", license_id=lid,
...         rights_verified=True, derived_from_license_ids=list(lineage)))
>>> rights_license_id(rec("CC-BY-4.0"))
'CC-BY-4.0'
>>> rights_license_id(rec("elevenlabs-free-plan", "CC-BY-4.0"))
'elevenlabs-free-plan'
>>> rights_license_id(rec("procedural-free", "CC-BY-NC-4.0"))
'CC-BY-NC-4.0'
>>> rights_license_id(rec("Stability-Community", "CC-BY-4.0")) is None
True
>>> capped = apply_license_flags(LicenseRecord(source="s", license_id="CC-BY-4.0",
...     rights_verified=True), overrides={"revenue_cap_usd": 1000})
>>> rights_license_id(capped), rights_license_id(capped,
...     restrictions=license_restrictions(capped))
(None, 'CC-BY-4.0')
>>> rights_license_id(rec("Stability-Community", "Tencent-Hunyuan-Community")) is None
True
>>> rights_license_id(rec("CC-BY-SA-4.0", "CC-BY-NC-4.0")) is None
True
Return type:

Optional[str]

foley.licensing.shared_share_alike(*records)[source]#

The share-alike licence a work made of records may be released under, or None.

Every record must carry the same one (carries_share_alike()); a missing record (None: rights unknown), a source under another licence, or one that is not share-alike at all gives None, and the work cannot carry the licence.

>>> sa = LicenseRecord(source="s", license_id="CC-BY-SA-4.0")
>>> shared_share_alike(sa, sa), shared_share_alike(sa, None)
('CC-BY-SA-4.0', None)
>>> shared_share_alike(sa, LicenseRecord(source="s", license_id="CC-BY-NC-SA-4.0"))
Return type:

Optional[str]

foley.licensing.stamp_source_terms(record, stated)[source]#

Write what a source stated about its terms onto record, in place, and return it.

stated maps SOURCE_STATED_FIELDS names to values (a config’s, see foley.sources.base.source_stated_terms()). No permission flag is touched; terms_notes are added to the record’s own, once each.

>>> lic = stamp_source_terms(LicenseRecord(source="s"),
...     {"license_basis": "vendor-tos", "terms_notes": ["Pay the piper."]})
>>> lic.license_basis, lic.terms_notes, lic.commercial_ok
('vendor-tos', ['Pay the piper.'], False)
Raises:

ValueError – On a name that is not a stated field, or a value it does not take.

Return type:

LicenseRecord

foley.licensing.territory_excluded(excluded, territory)[source]#

Whether territory is in excluded ("EU" covers its member states).

An unstated territory (None) counts as excluded whenever anything is, and so does one that is not a country code: the gate fails closed.

>>> territory_excluded({"EU", "GB"}, "fr"), territory_excluded({"EU"}, "US")
(True, False)
>>> territory_excluded({"KR"}, None), territory_excluded({"GB"}, "uk")
(True, True)
>>> territory_excluded({"KR"}, "Korea"), territory_excluded(set(), None)
(True, False)
>>> territory_excluded({"KR"}, "WORLD"), territory_excluded(set(), "WORLD")
(True, False)
Return type:

bool

foley.licensing.upload_refusal(source)[source]#

Why the bytes of a sound with rights source may not be sent to an edit backend, or None.

cache_bytes_ok is the source’s terms on its bytes (a Freesound API pull is by-reference even under CC0): bytes foley may not keep, it does not upload either.

>>> from foley.base import LicenseRecord
>>> upload_refusal(LicenseRecord(source="x", cache_bytes_ok=True)) is None
True
>>> upload_refusal(LicenseRecord(source="freesound"))[:30]
'its bytes may not be kept or s'
Return type:

Optional[str]

foley.licensing.vendor_training_refusal(source, backend_config)[source]#

Why a sound with rights source may not be sent to the backend backend_config declares, because its vendor trains on what it is sent, or None.

A backend whose licence block says vendor_trains_on_input (Mirelo’s terms §7.4: a training licence on input as well as output) takes the source clip into a proprietary, commercial training set. Fail-closed: the source’s rights must allow that use (ai_use_permitted(), closed-source and commercial); an ai_training_ok that is off or a narrowed scope refuses it, before any upload.

>>> from foley.base import LicenseRecord
>>> trains = {"license": {"vendor_trains_on_input": True}}
>>> vendor_training_refusal(LicenseRecord(source="x"), trains)[:26]
"its backend's vendor train"
>>> vendor_training_refusal(LicenseRecord(source="x", ai_training_ok=True), trains) is None
True
>>> vendor_training_refusal(LicenseRecord(source="x"), {"license": {}}) is None
True
Return type:

Optional[str]

foley.licensing.wanted_license_ids(config, license)[source]#

The licence ids a license= request keeps, or None for every accepted one.

license is an explicit licence id (QUERY_AFFORDANCES['license']), matched case-insensitively against the source’s accepted_license_ids; 'cc0' is the historical alias for the source’s cc0_license_ids, and a family prefix with a dash, such as 'cc-by', keeps every accepted id of that family (CC-BY-3.0, CC-BY-4.0). None, 'any' and a value that is no licence id at all (e.g. 'public-domain') do not narrow, with a warning for the last (the historical “anything but 'cc0'” behaviour). A real licence id the source does not accept gives [], so nothing is returned: fail closed, never silently broader.

>>> cfg = {"license": {"accepted_license_ids": ["CC0-1.0", "CC-BY-4.0"],
...                    "cc0_license_ids": ["CC0-1.0"]}}
>>> wanted_license_ids(cfg, "cc0"), wanted_license_ids(cfg, "CC-BY-4.0")
(['CC0-1.0'], ['CC-BY-4.0'])
>>> wanted_license_ids(cfg, "cc-by"), wanted_license_ids(cfg, None), wanted_license_ids(cfg, "cc-by-sa-4.0")
(['CC-BY-4.0'], None, [])
Return type:

Optional[list[str]]

foley.licensing.wider_rights(record, bound)[source]#

What record allows that bound does not ([]: no wider than bound).

A permission of _DERIVATIVE_SHARED_FLAGS it holds and bound lacks, an attribution or a notice bound requires and it does not, a higher (or no) revenue cap, a looser AI-use scope, a voice or trademark flag bound raises and it does not, another stated AI-use preference. When the flags show nothing, the licence a consumer reads it under (exported_licence_wider()): every share-alike licence has the same flag row, so only the id tells CC BY-NC-SA from CC BY-SA. How an edit tells that a byte-identical sound already in the library is not the edit it made (see narrow_to_source()).

>>> from foley.base import LicenseRecord
>>> nc = apply_license_flags(LicenseRecord(source="s", license_id="CC-BY-NC-4.0"))
>>> by = apply_license_flags(LicenseRecord(source="s", license_id="CC-BY-4.0"))
>>> wider_rights(by, nc), wider_rights(nc, by)
(['commercial_ok', 'ai_training_ok'], [])
Return type:

list[str]