Skip to Content
Documentation

Providers

Add sources beside Songstress's own, for search, links, lyrics, metadata, artwork, scrobbling, recommendations and audio.

A provider is a source your extension adds beside Songstress's own. Declare it under contributes.providers.<kind>, then register it in the server entry, under the same id, with songstress.providers.<kind>.register(id, provider). It needs the permission providers. A scrobble provider, which is handed members' plays, needs listening.read too, and hears only the members who granted it.

The kinds

Each kind is a list of up to five sources.

Prop

Type

What your code answers for each kind is under What your code answers.

Every source

Every source has an id, and may have a name as people read it (left out, your extension's name). The same id under several kinds is one source, with one name and one group (PROVIDER_MISMATCH). Lyrics, scrobble and play sources take only these:

Prop

Type

Search sources say what a search finds:

Prop

Type

Lookup sources, what they open by id:

Prop

Type

Link sources, the links they read:

Prop

Type

A link pattern is a host with an optional path that a link must begin with (soundcloud.com, example.com/album/), or an app link's scheme (spotify:). A host also takes links to the hosts under it, and the longest pattern that fits a link wins. http: and https: alone are refused (LINK_PATTERN_TOO_BROAD).

Metadata, artwork, artist info and recommendation sources say what they support:

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Download sources list their qualities, best first:

Prop

Type

Prop

Type

What your code answers

Each kind's provider, as the SDK declares it. Every method is also handed the context it is asked in:

Prop

Type

Prop

Type

Lookup

Prop

Type

Prop

Type

Lyrics

Prop

Type

Metadata

Prop

Type

Artwork

Prop

Type

ArtistInfo

Prop

Type

Scrobble

Prop

Type

Recommend

Prop

Type

Play

Prop

Type

Download

Prop

Type

A search is asked with a query, and answers results of each type asked for:

Prop

Type

Prop

Type

A scrobble is handed the play:

Prop

Type

A search source

songstress.json
"permissions": {
  "providers": { "reason": "Search Tunelog's catalogue beside your library." },
  "network": { "reason": "Ask Tunelog what it has.", "hosts": ["api.tunelog.example"] }
},
"contributes": {
  "providers": { "search": [{ "id": "tunelog", "name": "Tunelog", "types": ["track"] }] }
}
src/server.ts
import { ProviderFailure, songstress } from 'songstress/server'

interface Found {
  id: string
  title: string
  artist: string
  seconds: number
}

songstress.providers.search.register('tunelog', {
  async search(query) {
    const url = `https://api.tunelog.example/v1/search?q=${encodeURIComponent(query.text)}&limit=${query.limit}`
    const answer = await songstress.net.fetch(url)
    if (answer.status === 429) throw new ProviderFailure('rate-limited', { retryAfterS: 60 })
    if (answer.status !== 200) throw new ProviderFailure('unavailable')
    const found = JSON.parse(answer.body) as Found[]
    return {
      tracks: found.map((track) => ({ id: track.id, title: track.title, artists: [track.artist], durationS: track.seconds })),
    }
  },
})

The rules

  • group names the catalogue of Songstress's own that the source reads too: musicbrainz, spotify, deezer, tidal, itunes or ytmusic. Its results are then merged with that catalogue's, and it speaks that catalogue's ids. Left out, the source is a group of its own.
  • lookup and metadata. A lookup source's artists and albums give their discographies too. Declare metadata with discography for a source that answers discographies without pages of its own, and with enrich for one that fills a track's missing facts.
  • artistInfo is what an artist's page says about them. A biography is plain text, its paragraphs apart by a line break; the first 4000 characters are kept. It may carry its page (url) and its language (language, a BCP 47 tag). Similar artists come most alike first, 50 at most. Both are asked by the server for itself and kept: null is the answer of a source that can't tell the artist from a namesake. It came with API 0.1.6.
  • Beside, never instead. A source joins switched off or last, the admin's order decides, and one that fails never fails the rest. Lyrics from a provider never replace the lyrics a song's own file carries. Results carry your extension's mark.
  • play and download are switched off on a server until its admin turns each on. A play provider plays what the search provider of the same id found (PROVIDER_PLAY_NEEDS_SEARCH). Both answer where the audio is, as addresses; Songstress fetches it, under your network permission on every hop, and joins segments itself. Nothing is decrypted. From API 0.1.8 an extension with either may be listed like any other.

Failure

"Nothing found" is an empty list or null. A failure Songstress knows what to do about is thrown as a ProviderFailure with one of four codes:

  • rate-limited: the service asks to wait. Give retryAfterS, the seconds to wait.
  • sign-in-required: the account is missing or signed out.
  • not-configured: something it needs isn't set up yet.
  • unavailable: the service can't answer now.

Anything else thrown counts as the provider being broken for now.

On this page