# Writing a Melo add-on An add-on is an ordinary HTTPS server that answers three JSON endpoints. Melo asks it for tracks, then plays or downloads the audio it points to. Nothing an add-on sends is ever run on the phone: it can only answer with data. People add an add-on in **Settings → Add-ons** by pasting its address. Add-ons are tried in the order the listener sets there. ## What Melo does with an add-on - **Search.** The Add-ons search lists the add-on's tracks, and a picked track plays from the add-on. - **Direct Source Stream.** When the listener turns this on and sets streaming quality to **Lossless** for the connection in use, Melo asks the add-ons for each YouTube Music or Spotify track it is about to play. If an add-on holds the same recording, Melo plays that instead. If none does, or none answers within 12 seconds, the track plays from YouTube Music at the same position. - **Downloads.** When download quality is **Lossless** and Direct Source Stream is on, a download is kept as the add-on's file if an add-on that allows downloads holds the recording as a plain file. Otherwise the YouTube Music file is kept. A track picked from an add-on's search is always downloaded from that add-on. Downloaded files play from the device, with no request to the add-on. ## The address The base address must use `https://`. It may carry a path, such as a personal token: `https://example.com/u/abc123`. An address ending in `/manifest.json` is accepted too, and Melo strips the file name. Every request appends a path to the base: | Request | Path | | --- | --- | | Manifest | `{base}/manifest.json` | | Search | `{base}/search?q={query}` | | Stream | `{base}/stream/{id}` | The track id is sent as one path segment, URL-encoded. An id that holds `/` or `?` arrives encoded, so it cannot reach another endpoint. Each request has `Accept: application/json` and `User-Agent: Melo/`. ## `GET /manifest.json` ```json { "id": "com.example.music", "name": "Example Music", "version": "1.0.0", "description": "Lossless copies of the Example catalogue.", "resources": ["search", "stream"], "settings": [ { "key": "quality", "default": "lossless", "options": [ { "value": "hires", "label": "Hi-Res" }, { "value": "lossless", "label": "CD quality" }, { "value": "high", "label": "320 kbps" } ] }, { "key": "region", "default": "US" } ], "allowDownloads": 1, "checkValidLossless": 0 } ``` | Field | Meaning | | --- | --- | | `id` | Required. A stable identifier. | | `name` | Shown in Settings. Defaults to `id`. | | `version`, `description` | Shown in Settings. | | `resources` | Must include `"search"`, or be empty. Empty means Melo checks the endpoints instead. | | `settings` | Settings with a `key` and a `default`. Every default is sent as a query parameter on every request. A setting with the key `quality` and two or more `options` appears as a quality picker in Melo. | | `allowDownloads` | `0` keeps the add-on to playback. Melo then never keeps its files as downloads: they come from the next add-on, or YouTube Music, and Settings shows the add-on as playback only. Defaults to allowed. | | `checkValidLossless` | `1` limits the add-on to times when a wired, USB or HDMI output is connected. Otherwise it is skipped for playback and downloads. | | `bitchordAuth` | `1` means the add-on only serves an app that can prove its identity. Melo cannot, so it refuses such an add-on when it is added. | Switches can be written as `1`/`0`, `true`/`false`, or `"on"`/`"off"`. Unknown fields are ignored. If there is no manifest (404), Melo still accepts the address when `/search?q=music` answers. The add-on is then named after its host. ## Query parameters Each request carries: - Every `default` from the manifest's `settings`. - `quality`: the option the listener picked, or else the add-on's first option. With no `quality` setting declared, Melo sends `LOSSLESS`. - On search, `title` and `artist` as well, when Melo is matching a known track. They let the add-on tell which words of `q` name the singer. ## `GET /search?q=` ```json { "tracks": [ { "id": "12345", "title": "Song Title", "artist": "Artist Name", "album": "Album Name", "duration": 241, "artworkURL": "https://example.com/art/12345.jpg", "format": "FLAC", "audioQuality": "LOSSLESS" } ] } ``` | Field | Meaning | | --- | --- | | `id`, `title` | Required. Rows without them are dropped. | | `artist`, `album` | Used for matching and display. | | `duration` | Seconds. Decimals are accepted. Needed for matching. | | `artworkURL`, `albumArtworkURL` | Cover art. The first one present is used. | | `format`, `audioQuality` | Hints such as `FLAC`, `LOSSLESS`, `HI_RES` or `24-bit`. Lossless and hi-res rows are tried first. | | `audioMode`, `audioModes`, `atmos` | A row marked Dolby Atmos is skipped, so the stereo mix is chosen. | | `streamURL` | Optional. A direct URL, tried when `/stream` has nothing. | Any other arrays in the answer are ignored. ### How Melo matches a track For Direct Source Stream and downloads, Melo searches with `title artist`, then the title alone, then the title in another script. It reads up to 15 rows per query. A row matches only when: - The core words of the title agree, along with version marks such as *Live*, *Remix* or *Acoustic*. - At least one artist is shared. - The length is within the listener's tolerance (1–15 seconds, 5 by default). Melo opens up to three matching rows per add-on, preferring lossless ones. ## `GET /stream/{id}` ```json { "url": "https://cdn.example.com/12345.flac", "format": "FLAC", "codec": "flac", "sampleRate": 44100, "bitDepth": 16, "manifest": "none", "encrypted": false } ``` | Field | Meaning | | --- | --- | | `url` | Required. An `http(s)` address of the audio. | | `manifest` / `mediaType` | `none` for a plain file, `hls` or `dash` for a playlist or manifest. A URL ending in `.m3u8` or `.mpd` is recognised too. | | `format`, `quality`, `streamQuality`, `audioQuality` | Labels such as `FLAC 24-bit 96 kHz`. Melo reads the bit depth, sample rate and bitrate from them when the numeric fields are missing. | | `codec`/`fileCodec`, `container`/`containerFormat`, `mimeType` | Optional details. | | `sampleRate` | In Hz, or in kHz when it is under 1000. | | `bitDepth`, `bitrate` | Bitrate in kbit/s or bit/s: any value over 3000 is read as bit/s. | | `encrypted` | Anything other than `false`, `0`, `none` or absent is refused. Melo never plays protected audio. | | `error` | A reason when there is no `url`. Some add-ons answer 200 with only this. | Melo checks a plain file's length with a `Range: bytes=0-0` request. A file too small to hold the whole track is refused as a preview. The floor is about 200 kbit/s for lossless and 64 kbit/s for lossy audio. **Downloads need a plain file.** An HLS or DASH answer can be played, but not downloaded: the download then comes from the next source. The URL must stay valid long enough to fetch the whole file. ## Status codes | Code | What Melo does | | --- | --- | | 200 | Reads the JSON. An empty body is an error. | | 401 | Treats the add-on as needing app attestation. | | 404 | The add-on does not hold this track (or, for the manifest, there is no add-on here). | | 429 | Waits for `Retry-After`, or backs off from 0.5 to 8 seconds, and retries up to twice. | | 5xx | The add-on is unavailable for now. The next source is tried. | | Other | Refused. | Melo caches manifests and searches for 10 minutes, and stream answers for 5 minutes. ## Privacy An add-on receives search text, a track's title, artist, album and length, and whatever its own address carries. Melo never sends account details, cookies or listening history. Melo's logs show only an add-on's scheme and host, never its path, so a token in the address stays out of them. Publish a privacy policy for your add-on: it applies to what your server receives. ## Testing 1. Serve the endpoints over HTTPS. A tunnel to a local server works. 2. In Melo, open **Settings → Add-ons** and add your address. Melo reads the manifest, and shows an error if something is wrong. 3. Search for a track in the Add-ons search, and play it. 4. Turn on **Direct Source Stream**, set streaming quality to **Lossless**, and play a YouTube Music track your add-on holds. The player's quality badge shows the format it played. 5. To test downloads, set download quality to **Lossless** and download that track.