Module wikipedia

Source
Expand description

Wikipedia, reached through Wikidata: the prose MusicBrainz does not hold.

MusicBrainz answers with identifiers, dates and relationships. It never answers with a sentence about the artist, because that is not what it is for. The sentence exists on Wikipedia — and the way from one to the other is the wikidata relationship MusicBrainz already returns.

Two requests, not one. A Wikidata entity is the hub: it holds a sitelink per language, and a sitelink is a page title rather than a summary. So reaching a paragraph is

MusicBrainz artist  →  wikidata: .../wiki/Q11649
                       Special:EntityData/Q11649.json   →  sitelinks.enwiki.title
                       en.wikipedia.org/…/summary/<title>  →  extract

That is why this is opt-in rather than part of every fetch: it doubles a run that already takes ten minutes over a large library, and the summary is the one fact here nobody needs in order to file their music.

Everything in this module is a decision, and none of it is a request. The two URL builders and the two extractors below are pure functions over text and JSON, so what the program concludes from an answer is proven by the tests beside them, and only the handing of a URL to a client library is left unproven — the same split crate::musicbrainz follows.

§The licence is not optional

Wikipedia text is CC BY-SA. Reusing it obliges attribution, so the extract is only ever produced as a Prose, which cannot hold the words without the page they came from and the terms they came under. There is deliberately no function here that returns a bare String of article text.

Structs§

Article
An article on one language’s Wikipedia.

Constants§

FALLBACK_LANGS
Languages to look for an article in, best first.
LICENCE
The licence Wikipedia article text is under.
PORTRAIT_SOURCE
The name a portrait reached through Wikidata is stored under.
REQUEST_INTERVAL
How long to leave between requests.
SOURCE
The name this source is stored under in sources.json.

Functions§

article
The article to read, from a Special:EntityData document.
commons_file_url
Where to download a Commons file, at a given width.
entity_data_url
Where to ask Wikidata about an entity.
entity_id
The Wikidata entity id inside a URL MusicBrainz returned.
portrait_file
The Commons filename in a Wikidata entity’s image claim (P18), if it states one.
prose
The paragraph, credited, from a REST summary document.
summary_url
Where to ask for an article’s opening paragraph.
validate_entity
Checks the entity response before a fetch records a completed absence.
validate_portrait
Checks portrait tables before a fetch records a completed absence.
validate_summary
Distinguishes a readable summary or genuine absence from an invalid body.