Sending a catalog

Push a catalog

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

{
  "baseUrl": "https://0123456789abcdef.letsdj.io:8443",
  "mediaToken": "<secret you generate>",
  "capabilities": {
    "canTransposeKey": false,
    "canSeek": true,
    "allowsSharing": true,
    "allowsCommercialUse": false
  },
  "tracks": [
    {
      "externalId": "5ec27f0af401a3ab",
      "title": "Diễm Xưa",
      "artist": "Trịnh Công Sơn",
      "durationSeconds": 254,
      "thumbnailUrl": "https://...",
      "playable": true
    }
  ],
  "final": true
}
Field Required Meaning
baseUrl Yes Must be https, with a certificate browsers already trust. Only its origin is used, to build media addresses. See Serving media.
mediaToken Yes A secret you generate and enforce. Unguessable and safe in a query string: random hexadecimal or base64url, at least 128 bits. Rotating on restart is fine — see Serving media.
capabilities No What you will do. See Capabilities.
limits No Fetch and preview ceilings. See Answering on demand.
consoleUrl No An https link to your own interface, offered to the owner. See Answering on demand.
tracks Yes May be empty. At most 500 tracks per request; more is a 400.
final No Defaults to true. See Replace or add.

Every sync replaces capabilities, limits and consoleUrl whole. Send all of each every time. An omitted capability flag reverts to its default, and the defaults are not all false. An omitted consoleUrl removes the link to your console.

Track fields

Field Required Meaning
externalId Yes Yours. Any non-empty string, unique within your library. Also the last part of the media address, percent-encoded.
title Yes —
artist No —
durationSeconds No Seconds. Any finite number.
thumbnailUrl No See Artwork.
loopId No The id of a looping cover. See Looping covers.
kind No song, video or karaoke. See Media kinds.
playable No Only a literal false says anything. See Formats.

Keep externalId stable across re-scans. A queued song resolves through it, so an id derived from mutable state breaks songs mid-party. The bridge derives ids from a file’s size and the bytes at each end, never its path.

A track with no externalId or no title is skipped without failing the batch. Compare accepted against what you sent.

Replace or add

final Effect
false Adds and updates. Nothing is removed.
true (default) Closes a replacement. Every track that no batch in that replacement mentioned is removed.

Replace the catalog in batches of at most 500 with final: false, then close with final: true. Add or update with final: false alone; this is how a fetched track is reported.

Corrections survive removal, and return if the track does. A track waiting to be fetched is never removed this way — see Answering on demand.

Do not delete your catalog

final defaults to true, so a sync that leaves it out is a replacement. A single track sent that way removes the rest of the catalog. An empty batch sent that way removes all of it.

Never sync the results of a failed scan. When a drive is unplugged or a share is asleep, leave the last catalog in place and tell the person. That is what the bridge does.

Read the answer

{ "ok": true, "accepted": 312, "trackCount": 812 }

accepted is how many tracks of this request were kept; trackCount is how many the library holds after it. The library becomes ready the first time a sync lands.

Status Meaning
400 error says which part: body must be JSON, baseUrl is required, baseUrl must be https, consoleUrl must be https, tracks must be an array, at most 500 tracks per batch, or mediaToken is required.
401, 403 See Conventions.
503 The service could not store a secret just now. Ours. Retry later.

Push artwork

Optional. Two ways to supply it.

A URL. Set thumbnailUrl on the track. The browser on a guest’s phone must be able to fetch it. If it only resolves on your own network, or expires after a few hours, push bytes instead.

Bytes. The only route for a provider on a private network:

POST https://api.lets.dj/providers/art?externalId=<externalId>
Authorization: Bearer <sync token>
Content-Type: image/jpeg

<raw image bytes>
Constraint Rule
Size 1 MB, which is 1,048,576 bytes. We do not decode or resize, so an oversized image is a flat 400. Send a thumbnail-sized image.
Content-Type Must start with image/.
Body Must not be empty.
Format JPEG, PNG or WebP. Anything a browser cannot draw is stored and shown as a broken picture.
externalId Must match a track already sent through /providers/sync. An unknown one is a 404 with unknown track.

Push the catalog first, the art after. Pushing art again replaces the image. Art survives later syncs of the same track, and is deleted with the track when a replacement removes it.

Precedence, highest first: a correction made in the app, then pushed bytes, then thumbnailUrl.

Add a looping cover

Optional. A track can carry a short, silent video that loops where its artwork would be, the way an album cover animates in Apple Music. Set loopId on the track:

{
  "externalId": "5ec27f0af401a3ab",
  "title": "Diễm Xưa",
  "artist": "Trịnh Công Sơn",
  "durationSeconds": 254,
  "loopId": "b83d19c0e7a4f256",
  "playable": true
}
  • loopId is an id, never a URL. The Stage fetches it from the same media route as a song, so serve it like any other id. See Serving media.
  • Per track. Leave it out where there is no cover. A provider with no covers never sends one, and declares nothing in capabilities.
  • Audio-only tracks only — .mp3 and .m4a, the ones that would otherwise show a still picture. On a video it is ignored.
  • Video only, video/mp4 or video/webm. A GIF will not play.
  • The sound is the song’s. The Stage plays a cover muted.
  • Send it on every sync of the track. A sync that leaves loopId out removes the cover.
  • Do not also list the cover as a track. It would turn up in search as a song nobody can sing.

The owner can replace a cover from the app, and that wins over loopId. A host can also turn covers off for a party, which shows the artwork instead.

Declare a media kind

Optional. A karaoke video and a music video look identical to a machine, so say which each track is. The app marks each kind differently, offers a search filter on it, and shows it to the owner. Set kind on the track:

"tracks": [
  { "externalId": "5ec27f0af401a3ab", "title": "Africa", "artist": "Toto", "kind": "karaoke" },
  { "externalId": "b83d19c0e7a4f256", "title": "Africa", "artist": "Toto", "kind": "video" },
  { "externalId": "0c9e41d7a2b53f68", "title": "Diễm Xưa", "artist": "Trịnh Công Sơn", "kind": "song" },
  { "externalId": "7a1f4e0b93c2d856", "title": "Hotel California", "artist": "Eagles" }
]
  • One of song, video or karaoke. Anything else is treated as absent.
  • Per track. The last track above states nothing, and nothing is declared in capabilities. A provider that never sends a kind is a provider whose tracks are unstated, which is fully supported. A search filter never hides an unstated track.
  • Resolve it before you send it. We take your answer and do not work one out. Highest first:
    1. A filename marker, .karaoke or .video. See Mark karaoke and video.
    2. Your own default for videos, if you have one.
    3. The extension: .mp3 and .m4a are a song.
  • Strip the marker before you parse the title. Left in, Toto - Africa.karaoke.mp4 is a song called “Africa.karaoke”, and a catalog full of them is corrupt.
  • Send it on every sync of the track. A sync that leaves kind out makes the track unstated again.

The owner can correct a kind in the app, and that wins over whatever you sent.

What the owner can change

The owner can correct a track’s title, artist, picture, looping cover and kind in the app.

A track whose externalId changes is a different track, and starts again without its corrections.