foley.sources.music_library.adapter#

A free music library as a live retrieve source: titles in, licensed tracks out (#212).

MusicLibraryAdapter is the SourceAdapter of one free library (incompetech), built by the registry from the library’s config (foley.sources.music_library.config). Through foley.sources.pull.add_from() a library’s tracks get what every source’s sounds get: the fail-closed licence gate (foley.keep()) under the call’s intent, a by-value SoundRecord from ingest_one() (decode, QC, embed, store) with the library’s attribution on its licence (credits), and the run manifest.

  • search: a library has no search API, so the query is the titles: one title, a list of titles, or a credits description (a video’s, read by titles_by_library() for this

    library’s names). Each title is a candidate whose licence is

    track_license()’s; nothing is fetched.

  • download: the mirror chain acquire() uses (fetch_verified(): the library’s server, then the Internet Archive’s raw copy), through the resilient transport, each file checked by verify (probe_verify()).

The library is looked up by name on each call, so the adapter follows register_music_library() (replace=True).

Module Attributes

Query

one title or a credits description, or the titles.

Adapter

Registry convention (arioso): the loader imports adapter.Adapter.

Functions

query_titles(query, library)

The titles query names for library, in order, each once.

Classes

Adapter

Registry convention (arioso): the loader imports adapter.Adapter.

MusicLibraryAdapter([config, http, verify, ...])

One free music library as a retrieve source (a SourceAdapter).

foley.sources.music_library.adapter.Adapter#

Registry convention (arioso): the loader imports adapter.Adapter.

class foley.sources.music_library.adapter.MusicLibraryAdapter(config=None, *, http=None, verify=<function probe_verify>, mirrors=(<function direct>, <function wayback>), library=None, libraries=None, clock=<built-in function monotonic>, sleep=<built-in function sleep>)[source]#

Bases: object

One free music library as a retrieve source (a SourceAdapter).

Parameters:
  • config (Optional[dict]) – The library’s SOURCE_CONFIG (the registry passes it); its api['library'] names the library.

  • http (Optional[Transport]) – The Transport files are asked through, used as given (the registry passes a resilient one, per host). Default: the library’s polite transport (requests, paced and retried per host), with the call’s egress checked.

  • verify (Callable[[bytes], float]) – bytes -> seconds: how a file is checked to be a track (default probe_verify()).

  • mirrors (Sequence[Callable[[str], str]]) – Where a title’s file is asked for, in order.

  • library (Optional[MusicLibrary]) – The MusicLibrary itself, instead of the one registered under config['api']['library'].

  • libraries (Optional[Mapping[str, MusicLibrary]]) – Where a library name is looked up (default: the registered ones).

  • clock (Callable[[], float]) – The monotonic clock the default transport paces by.

  • sleep (Callable[[float], None]) – How the default transport waits.

download(source_id)[source]#

The verified bytes of one title, from the first mirror that serves them.

Raises:
  • LookupError – If the title’s licence is not one foley verified or lets it keep (checked here too, so a direct call cannot fetch what the gate would refuse).

  • SourceConfigurationError – If the default verify cannot run here.

  • MusicLibraryError – If no mirror serves a file verify accepts.

Return type:

bytes

get(source_id)[source]#

The record of one title (incompetech:Sneaky Snitch or the bare title).

Return type:

SoundRecord

property library: MusicLibrary#

The library this source serves (looked up on each call).

Raises:

SourceConfigurationError – If it is not registered, or is paid.

search(query, *, license=None, k=50, provider_params=None, **_affordances)[source]#

The titles query names, as candidates (at most k; nothing fetched).

license is a licence id ('cc0', 'CC-BY-4.0', 'cc-by'): a library has one licence, so its titles are all kept or none are (fail closed). There are no native params (provider_params is refused).

Return type:

list[Candidate]

foley.sources.music_library.adapter.Query#

one title or a credits description, or the titles.

Type:

What query may be

alias of str | Iterable[str] | Mapping[str, Any]

foley.sources.music_library.adapter.query_titles(query, library)[source]#

The titles query names for library, in order, each once.

A string is read as a credits description first (titles_by_library(), over this library’s names only); one that credits nothing is one title when it is a single line, and no title when it is several. A list (or a titles file’s {title: metadata}) is the titles.

>>> lib = music_library("incompetech")
>>> query_titles("Sneaky Snitch", lib)
['Sneaky Snitch']
>>> query_titles('"Sneaky Snitch" Kevin MacLeod (incompetech.com)', lib)
['Sneaky Snitch']
>>> query_titles(["A", "B", "A"], lib)
['A', 'B']
Raises:

SearchArgumentError – If a title is not a non-empty string, or query is empty.

Return type:

list[str]