tilie_server.routers.lookup#

MusicBrainz through a Reconciliation Service API 0.2 endpoint.

The editor looks values up in MusicBrainz through this server, which keeps MusicBrainz’s rules of use for all its requests (see tilie_server.musicbrainz). The endpoint speaks the W3C Entity Reconciliation Community Group’s Reconciliation Service API, version 0.2, so the editor reaches it with the same generic client as any conforming service:

  • GET /api/reconcile/musicbrainz, the service manifest;

  • queries=<JSON> (GET or a POST form), reconciliation queries;

  • extend=<JSON> (POST form, or GET), data extension with the properties name and sameAs;

  • GET …/suggest/entity, entity suggestions;

  • GET …/properties, the properties a type can be extended with.

An identifier is <type>/<mbid>, so the identifier space http://musicbrainz.org/ followed by it is the entity’s IRI (http://musicbrainz.org/work/<mbid>). sameAs lists the IRIs that timetoshare’s catalogue recognises in an entity’s URL relationships; the catalogue is imported when a request needs it, so a server whose timetoshare lacks it answers every other request.

Form bodies are read with the standard library, and refusals are answered 422 with {"detail": <message>}; a failure of MusicBrainz itself 502.

tilie_server.routers.lookup.ENDPOINT = '/api/reconcile/musicbrainz'#

The service’s endpoint, root-relative.

tilie_server.routers.lookup.TYPE_NAMES: Mapping[str, str] = {'artist': 'artist', 'recording': 'recording', 'release-group': 'release group', 'work': 'work'}#

The service’s types, in the manifest’s order, with their names.

tilie_server.routers.lookup.DEFAULT_TYPE = 'work'#

The type of a query, a suggestion or a property proposal naming none.

tilie_server.routers.lookup.PROPERTIES: Mapping[str, str] = {'name': 'name', 'sameAs': 'same as'}#

The properties of data extension, with their names.

tilie_server.routers.lookup.QUERY_LIMIT = 5#

Candidates per query when it names no limit.

tilie_server.routers.lookup.MAX_LIMIT = 25#

The largest limit of a query.

tilie_server.routers.lookup.SUGGEST_LIMIT = 10#

Suggestions per request.

tilie_server.routers.lookup.SEPARATOR = ' · '#

Joins the parts of a candidate’s description.

tilie_server.routers.lookup.MBID = re.compile('[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')#

A MusicBrainz identifier as MusicBrainz writes it.

tilie_server.routers.lookup.MANIFEST: dict[str, Any] = {'defaultTypes': [{'id': 'work', 'name': 'work'}, {'id': 'artist', 'name': 'artist'}, {'id': 'recording', 'name': 'recording'}, {'id': 'release-group', 'name': 'release group'}], 'extend': {'property_settings': [], 'propose_properties': {'service_path': '/properties', 'service_url': '/api/reconcile/musicbrainz'}}, 'identifierSpace': 'http://musicbrainz.org/', 'name': 'MusicBrainz through tilie-server', 'schemaSpace': 'http://schema.org/', 'suggest': {'entity': {'service_path': '/suggest/entity', 'service_url': '/api/reconcile/musicbrainz'}}, 'versions': ['0.2'], 'view': {'url': 'https://musicbrainz.org/{{id}}'}}#

The service manifest.

exception tilie_server.routers.lookup.Refusal(message, status_code=422)[source]#

Bases: Exception

A request the service cannot answer, with the status and the detail.

Parameters:
  • message (str)

  • status_code (int)

Return type:

None

async tilie_server.routers.lookup.parameters(request)[source]#

The request’s parameters: its query string, then a form body’s.

A parameter given twice takes its first value; one in the body takes the place of the same parameter in the query string.

Parameters:

request (Request)

Return type:

dict[str, str]

tilie_server.routers.lookup.json_text(value)[source]#

A value as the JSON text a refusal quotes it with, a string bare.

Parameters:

value (Any)

Return type:

str

tilie_server.routers.lookup.entity_type(value)[source]#

Read a type of this service.

Raises:

Refusal – If value is none of the service’s types.

Parameters:

value (Any)

Return type:

str

tilie_server.routers.lookup.read_queries(text)[source]#

Read queries into (type, text, limit) per key, all or none.

Raises:

Refusal – At the first query the service cannot answer.

Parameters:

text (str)

Return type:

dict[str, tuple[str, str, int]]

tilie_server.routers.lookup.read_extend(text)[source]#

Read extend into its identifiers and properties.

Raises:

Refusal – If it is no object with a list of identifier strings and a list of property objects, or names an unknown property or an identifier outside the service.

Parameters:

text (str)

Return type:

tuple[list[str], list[str]]

tilie_server.routers.lookup.split_identifier(identifier)[source]#

Split <type>/<mbid>.

Raises:

Refusal – If identifier is not of that form.

Parameters:

identifier (str)

Return type:

tuple[str, str]

tilie_server.routers.lookup.cursor_of(value)[source]#

Read a suggestion’s cursor, 0 when absent.

Raises:

Refusal – If it is not written as an integer of 0 or more.

Parameters:

value (str | None)

Return type:

int

tilie_server.routers.lookup.credited(entity)[source]#

The artist credit of a recording or a release group, as displayed.

Parameters:

entity (Mapping[str, Any])

Return type:

str

tilie_server.routers.lookup.DESCRIPTIONS: Mapping[str, Callable[[Mapping[str, Any]], list[Any]]] = {'artist': <function <lambda>>, 'recording': <function <lambda>>, 'release-group': <function <lambda>>, 'work': <function <lambda>>}#

The parts of a candidate’s description, per type, before the empty go.

tilie_server.routers.lookup.named(kind, entity)[source]#

An entity’s identifier, name and, where it has one, description.

Parameters:
Return type:

dict[str, Any]

tilie_server.routers.lookup.candidates(kind, answer)[source]#

The reconciliation candidates of one MusicBrainz search.

A candidate is a match when it scores 100 and no other candidate does: MusicBrainz lists them by score, so it is the first, and the next one scores below 100.

Parameters:
Return type:

list[dict[str, Any]]

tilie_server.routers.lookup.catalogue_recognizer()[source]#

Answer the IRI timetoshare’s catalogue recognises in a URL, if any.

Raises:

Refusal – 501, if the installed timetoshare has no catalogue.

Return type:

Callable[[str], str | None]

tilie_server.routers.lookup.same_as(entity, recognized)[source]#

The IRIs recognised in an entity’s URL relationships, in order, once.

Parameters:
Return type:

list[dict[str, str]]

async tilie_server.routers.lookup.reconciled(musicbrainz, text)[source]#

Answer reconciliation queries, one search per query.

Parameters:
Return type:

dict[str, Any]

async tilie_server.routers.lookup.extended(musicbrainz, text)[source]#

Answer a data extension request, one lookup per identifier.

Parameters:
Return type:

dict[str, Any]

async tilie_server.routers.lookup.answered(request, answer)[source]#

Run answer and turn a refusal or an upstream failure into JSON.

Parameters:
Return type:

JSONResponse

async tilie_server.routers.lookup.service(musicbrainz, given)[source]#

Answer queries, else extend, else return the service manifest.

Parameters:
Return type:

Any

async tilie_server.routers.lookup.suggestions(musicbrainz, given)[source]#

Suggest the entities of a type whose name prefix finds, ten from cursor.

Raises:

Refusal – If prefix is blank, type is none of the service’s types, or cursor is no integer of 0 or more.

Parameters:
Return type:

Any

async tilie_server.routers.lookup.proposed(musicbrainz, given)[source]#

Propose the properties of data extension for a type.

Raises:

Refusal – If type is none of the service’s types.

Parameters:
Return type:

Any

async tilie_server.routers.lookup.service_get(request)[source]#

The manifest, or the answer to queries or extend.

Parameters:

request (Request)

Return type:

JSONResponse

async tilie_server.routers.lookup.service_post(request)[source]#

The answer to a form’s queries or extend.

Parameters:

request (Request)

Return type:

JSONResponse

async tilie_server.routers.lookup.suggest(request)[source]#

Entities whose name the prefix finds, ten from cursor.

Parameters:

request (Request)

Return type:

JSONResponse

async tilie_server.routers.lookup.properties(request)[source]#

The properties of data extension for a type.

Parameters:

request (Request)

Return type:

JSONResponse