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 bytitles_by_library()for thislibrary’s names). Each title is a candidate whose licence is
track_license()’s; nothing is fetched.download: the mirror chainacquire()uses (fetch_verified(): the library’s server, then the Internet Archive’s raw copy), through the resilient transport, each file checked byverify(probe_verify()).
The library is looked up by name on each call, so the adapter follows
register_music_library() (replace=True).
Module Attributes
one title or a credits description, or the titles. |
|
Registry convention (arioso): the loader imports |
Functions
|
The titles |
Classes
Registry convention (arioso): the loader imports |
|
|
One free music library as a retrieve source (a |
- 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:
objectOne free music library as a retrieve source (a
SourceAdapter).- Parameters:
config (
Optional[dict]) – The library’sSOURCE_CONFIG(the registry passes it); itsapi['library']names the library.http (
Optional[Transport]) – TheTransportfiles 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 (defaultprobe_verify()).mirrors (
Sequence[Callable[[str],str]]) – Where a title’s file is asked for, in order.library (
Optional[MusicLibrary]) – TheMusicLibraryitself, instead of the one registered underconfig['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
verifycannot run here.MusicLibraryError – If no mirror serves a file
verifyaccepts.
- Return type:
- get(source_id)[source]#
The record of one title (
incompetech:Sneaky Snitchor the bare title).- Return type:
- 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
querynames, as candidates (at mostk; nothing fetched).licenseis 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_paramsis refused).
- foley.sources.music_library.adapter.Query#
one title or a credits description, or the titles.
- Type:
What
querymay be
- foley.sources.music_library.adapter.query_titles(query, library)[source]#
The titles
querynames forlibrary, 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
queryis empty.- Return type: