Answering on demand

Some sources have no catalog to mirror. A provider for one answers jobs instead: it finds songs on request, and fetches what somebody picks.

Kind Job carries You produce
search term Up to 50 candidates
fetch externalId, position The media, synced as a track
preview externalId Preview bytes on your media route

You collect jobs. We never dial you. A provider that is asleep is given nothing, and the party gets no answers.

Declare canSearchRemotely to be given search and fetch jobs, and canPreview as well to be given preview jobs. Both default to false — see Capabilities. A provider declaring neither is never given a job.

Poll for jobs

GET https://api.lets.dj/providers/jobs?max=4
Authorization: Bearer <sync token>

Response:

{
  "jobs": [
    { "id": "j97…", "kind": "search", "term": "diem xua" },
    { "id": "j57…", "kind": "fetch", "externalId": "abc123", "position": 3 },
    { "id": "j21…", "kind": "preview", "externalId": "def456" }
  ],
  "cancelled": ["j91…"]
}

Poll about once a second. Returning a job claims it for you.

Field Meaning
max How many jobs you will take. 1 to 20. Default 4. A larger number is cut to 20.
id Opaque. Use it only to report back.
kind search, fetch or preview.
position Where that song sits in the queue it was raised for. Fetches only.
cancelled Jobs you hold that nobody is waiting for any more. Stop work on them. Reported once, so act on them when you see them.

Keep the order they arrive in. Fetches first, lowest position first. Then searches, oldest first. Then previews, oldest first.

Job states

State Meaning
pending Raised, not yet claimed. Handed out to the next poll that takes it.
working Claimed by you. Report progress while you hold it.
done Finished. For a fetch, sync the track before reporting this.
failed You could not do it. error is shown to the person who asked.
cancelled Abandoned. Stop work on it.

A working job untouched for a minute is handed back out. Every report you send resets the minute. Finish or fail your work rather than dropping it.

Report progress

POST https://api.lets.dj/providers/jobs/<id>
Authorization: Bearer <sync token>
Content-Type: application/json

{ "state": "working", "phase": "downloading", "percent": 42 }

Send one no more than every couple of seconds. percent is optional, is a number from 0 to 100, and what is shown is clamped to that. Omit it rather than inventing one.

The phases are an ordered set. Never go backwards through it. Skip any you do not do, or send no phase at all.

starting → downloading → converting → verifying → finalizing

retrying sits outside the sequence: an attempt failed and is being made again. It may appear at any point, and downloading may follow it from zero.

Sidecar work. Artwork or metadata fetched before the media must report starting or stay silent. Do not label it with a later phase, and do not report its percentage as the media’s.

Nothing on our side checks the ordering; phase is stored as the text you sent. While somebody waits on a preview, we show:

phase Shown
starting Finding…
downloading Loading…
retrying Retrying…
converting, verifying, finalizing Almost…
anything else Loading…

Hand back at most 50 candidates. Any more are dropped.

{
  "state": "done",
  "results": [
    {
      "externalId": "abc123",
      "title": "Diễm Xưa",
      "artist": "Trịnh Công Sơn",
      "durationSeconds": 254,
      "thumbnailUrl": "https://…"
    }
  ]
}
  • externalId and title are required. A candidate missing either is dropped.
  • externalId must be the same id you would report for that track in a sync — the fetch that follows asks you for it.
  • artist, durationSeconds and thumbnailUrl are optional.
  • A candidate already in the library as an ordinary track is hidden from the person who asked.
  • Nothing is stored as a track until somebody chooses one.

Finish a fetch

Two steps, in this order.

  1. Sync the new track, with final: false. A sync that leaves final out is a replacement, and a replacement of one track removes the rest of your library. See Replace or add.
  2. Report the job done.
{ "state": "done" }

Reporting first leaves a queue entry pointing at a track that does not exist yet.

While the fetch runs, the queued song is held as pending: it shows its progress, and is never handed to the Stage as a URL. The sync reporting its externalId makes it ordinary. By default a party plays the first song that is ready rather than the first in the queue; the host can turn that off and wait in strict order.

Finish a preview

{ "state": "done" }

Do not follow it with a sync. A preview is not a catalog entry and must never appear as one. Done means only that the preview bytes can now be served.

Fail a job

{ "state": "failed", "error": "video is unavailable in this region" }

Say what actually happened. The person who queued the song is shown error. A failed fetch takes the song out of the queue everywhere it was waiting.

What a report answers

{ "ok": true, "cancelled": false }
Answer Meaning
"cancelled": true The job was abandoned while you were working on it. Stop.
404 The job is not yours, or not there.
400 state was something other than working, done or failed.

Previewing

A preview lets somebody hear a moment of a song before committing the party to it. Opt in with canPreview alongside canSearchRemotely, then serve preview bytes at the media route you already have:

GET <baseUrl>/media/<externalId>?t=<mediaToken>&preview=1

Same token, same range and CORS requirements, same 403 on a wrong token — see Serving media.

  • A preview may be a cheaper rendition than the real thing. Lower resolution, a shorter excerpt, whatever is quick.
  • It is never served to the Stage. It reaches one person’s phone, on request. Playback always waits for a real fetch.
  • Caching it is optional. Reusing a preview to finish a later fetch is fine; throwing it away and re-fetching is equally correct.
  • Give previews their own disk ceiling and eviction, apart from fetched media.

Declare your limits

Send limits alongside capabilities in any sync, and we enforce them. All are optional. A refusal names the limit it hit.

"limits": {
  "pendingFetchesPerRoom": 5,
  "pendingFetchesPerPerson": 2,
  "pendingPreviewsPerRoom": 3,
  "guestRequests": true,
  "fetchTimeoutSeconds": 600,
  "previewTimeoutSeconds": 120
}
Field Default when absent Effect
pendingFetchesPerRoom no ceiling Most fetches one room may have pending.
pendingFetchesPerPerson no ceiling Most fetches one person may have pending.
pendingPreviewsPerRoom no ceiling Most previews one room may have pending.
guestRequests true false limits asking to hosts. Only a literal false turns it off.
fetchTimeoutSeconds 600 When we give up on a fetch and tell the singer.
previewTimeoutSeconds 120 When we give up on a preview.

A count or a number of seconds must be a positive number, and is rounded down. Anything else is taken as not sent.

Offer a console

Report consoleUrl in the sync payload, on the same terms as baseUrl: HTTPS, and a certificate a browser trusts. The library’s owner, and nobody else, is offered a link to it.

Secure it yourself, and not with anything we hold. Do not put a secret in the address.