tilie_server.musicbrainz#
A client of the MusicBrainz web service, within its rules of use.
MusicBrainz asks every client of https://musicbrainz.org/ws/2/ for at
most one request per second and a User-Agent naming the application
and where to learn about it. This client keeps both for the whole server:
one MusicBrainz per application sends its requests one after the
other, each at least MusicBrainz.MIN_INTERVAL seconds after the
previous one, and answers a URL it has fetched before from its cache
without asking again. The User-Agent names the server and its repository,
never a person.
The fetch, the clock and the sleep are injected, so the rules can be proved without the network and without waiting.
- tilie_server.musicbrainz.Fetch#
Fetch a URL with the given headers; answer the status and the body.
A fetch that gets no answer raises
OSError(urllib’sURLErrorandTimeoutErrorare both).alias of
Callable[[str,Mapping[str,str]],tuple[int,bytes]]
- tilie_server.musicbrainz.BASE_URL = 'https://musicbrainz.org/ws/2/'#
The MusicBrainz web service.
- tilie_server.musicbrainz.USER_AGENT = 'tilie-server/0.3.0 ( https://github.com/TimeToAlign/TimeLineEditor )'#
The application and where to learn about it; no personal contact data.
- tilie_server.musicbrainz.TIMEOUT = 10.0#
Seconds a request may wait for an answer.
- tilie_server.musicbrainz.ENTITY_TYPES: Mapping[str, str] = {'artist': 'artists', 'recording': 'recordings', 'release-group': 'release-groups', 'work': 'works'}#
The entity types searched, each with the member listing its search results.
- tilie_server.musicbrainz.LUCENE_SPECIAL = frozenset({'!', '"', '&', '(', ')', '*', '+', '-', '/', ':', '?', '[', '\\', ']', '^', '{', '|', '}', '~'})#
The characters the search syntax gives a meaning, each escaped with
\.
- exception tilie_server.musicbrainz.UpstreamError[source]#
Bases:
ExceptionMusicBrainz could not answer a request; the message says why.
- tilie_server.musicbrainz.lucene_escaped(text)[source]#
Escape every character the search syntax gives a meaning.
The text is then searched for as written, never read as a query.
- tilie_server.musicbrainz.search_url(entity_type, text, limit, offset)[source]#
The URL that searches
entity_typefortext.
- tilie_server.musicbrainz.lookup_url(entity_type, mbid)[source]#
The URL of one entity with its URL relationships.
- tilie_server.musicbrainz.urllib_fetch(url, headers)[source]#
Fetch
urlwithurllib, waiting at mostTIMEOUTseconds.An answer of any status is returned; no answer raises
OSError.
- class tilie_server.musicbrainz.MusicBrainz(fetch=<function urllib_fetch>, *, clock=<built-in function monotonic>, sleep=<function sleep>, user_agent='tilie-server/0.3.0 ( https://github.com/TimeToAlign/TimeLineEditor )')[source]#
Bases:
objectThe server’s one way to MusicBrainz: paced, identified and cached.
- Variables:
- Parameters:
- async get(url)[source]#
Answer the JSON at
url, from the cache or from MusicBrainz.- Raises:
UpstreamError – If MusicBrainz answers another status than 200, answers no JSON, or cannot be reached. Failures are not cached.
- Parameters:
url (str)
- Return type: