OpenSubsonic API

repository·main·Indexed 42 days ago

https://github.com/opensubsonic/open-subsonic-api

An open, secure, and backwards-compatible evolution of the Subsonic API for music streaming. It provides a common specification for interoperability between music servers (such as Navidrome, Gonic, and Ampache) and clients (such as Symfonium and Feishin), supporting REST-style JSON and XML with enhanced authentication and capability discovery.

Tokens
114.9K
Snippets
307
Records
387
Agent score
51%

What's inside OpenSubsonic

  1. Overview of the OpenSubsonic API

    main

    The OpenSubsonic API is an evolution of the existing Subsonic API, designed to be open, secure, and backwards-compatible. It provides a framework for enhancing music streaming experiences through collaborative extensions.

    Core Principles

    • Backwards-Compatibility: Clients and servers using OpenSubsonic can interoperate with standard Subsonic implementations.
    • Optional Implementation: Features are modular. Servers and clients can choose to implement or consume only specific parts of the API.
    • Security: All extensions must undergo verification to ensure a safe environment for users and developers.
  2. What is the OpenSubsonic API?

    main

    The OpenSubsonic API is a common, expandable specification used by both music servers and clients to enable interoperability across web, desktop, and mobile platforms. It is built upon the original Subsonic API and aims to provide a consistent, secure, and collaborative ecosystem for media management.

    Key characteristics:

    • Protocol: Supports REST-style XML or JSON. While XML is supported, this documentation focuses on JSON as it is the primary format used by modern clients.
    • Compatibility: Maintains complete backwards compatibility with the existing Subsonic API.
    • Implementation: Offers piecewise optional implementation, allowing servers and clients to adopt features incrementally.
  3. OpenSubsonic Ecosystem Participants

    main

    The OpenSubsonic ecosystem consists of various servers and clients that implement the specification.

    Servers

    Commonly used OpenSubsonic-compatible servers include:

    • Ampache
    • Astiga
    • EdgeSonic
    • gonic
    • LMS (Lightweight Music Server)
    • Navidrome
    • Nextcloud Music
    • Qm-Music
    • Radiccio Server
    • Supysonic

    Clients

    Commonly used OpenSubsonic-compatible clients include:

    • Airdrome
    • Airsonic Refix
    • Amperfy
    • Feishin (ex Sonixd)
    • Radiccio
    • Supersonic
    • Symfonium
    • Tempus
    • tinysub
  4. Understand the songLyrics Version 2 data model

    main

    Version 2 introduces a structured way to handle multiple lyric layers and precise timing.

    Agent Attribution Rules

    When multiple vocal agents or layers are present, the response must include an agents array.

    • Every attributed entry using agents must define exactly one agent with role: "main".
    • To avoid redundancy, reusable agent metadata is stored once in structuredLyrics.agents, and individual cueLine objects reference them using agentId.

    Timing and Cues

    Timing is handled via cueLine objects and cue objects:

    • cueLine.value: The renderable text for that specific agent/layer. If multiple agent cueLines share a parent line index, each value represents only that layer's text, not the combined text of the parent line.
    • cue.byteStart / cue.byteEnd: 0-based inclusive offsets into the UTF-8 encoding of the cueLine.value.
    • Important: There is no normalization step for these offsets. Each cueLine containing cues must include the value field.
  5. Understand the AlbumID3WithSongs response format

    main

    The AlbumID3WithSongs response is an extension of the standard AlbumID3 object that includes an array of song entries (of type Child). This format allows a client to retrieve full album metadata along with the complete list of tracks contained within that album in a single response.

    There are two primary variations of this response structure:

    1. OpenSubsonic: Includes extended metadata fields (like version, userRating, musicBrainzId, etc.) and uses the song key to provide the tracklist.
    2. Subsonic (Legacy): A more limited version used for backward compatibility, primarily focusing on core album and song identity.

    When consuming this data, note that OpenSubsonic servers may provide additional optional fields that are not present in standard Subsonic responses.

    {
      "id": "ad0f112b6dcf83de5e9cae85d07f0d35",
      "name": "8-bit lagerfeuer",
      "song": [
        {
          "id": "300000116",
          "title": "Can I Help U?",
          "duration": 103
        }
      ]
    }
  6. Use the transcoding extension

    main

    The transcoding extension allows clients to determine if a media file requires transcoding and to retrieve the resulting transcoded media stream.

    To use this extension, identify it via the getOpenSubsonicExtensions endpoint using the name transcoding.

    Note on implementation: Unlike standard endpoints that use URL parameters, the decision-making process for transcoding requires a POST request to accommodate the complex JSON payload describing client playback capabilities.

  7. Understand the transcodeDecision response

    main

    The transcodeDecision object is the response returned by the getTranscodeDecision endpoint. It informs the client whether a media file can be played directly or if the server must transcode it to a different format to satisfy the client's capabilities.

    Key logic for clients:

    • If canDirectPlay is true, the client can request the source stream directly.
    • If canDirectPlay is false and canTranscode is true, the client must use the transcodeParams provided to call the getTranscodeStream endpoint.
    • transcodeParams is an internal server value that must be properly escaped when used as a URL parameter.
    {
      "subsonic-response": {
        "status": "ok",
        "version": "1.16.1",
        "type": "AwesomeServerName",
        "serverVersion": "0.1.3 (tag)",
        "openSubsonic": true,
        "transcodeDecision": {
          "canDirectPlay": false,
          "canTranscode": true,
          "transcodeReason": ["AudioCodecNotSupported"],
          "errorReason": "",
          "transcodeParams": "0001-0005-004",
          "sourceStream": {
            "protocol": "http",
            "container": "flac",
            "codec": "flac",
            "audioChannels": 6,
            "audioBitrate": 3000000,
            "audioProfile": "",
            "audioSamplerate": 96000,
            "audioBitdepth": 24
          },
          "transcodeStream": {
            "protocol": "hls",
            "container": "mp4",
            "codec": "aac",
            "audioChannels": 2,
            "audioBitrate": 256000,
            "audioProfile": "xHE-AAC",
            "audioSamplerate": 48000,
            "audioBitdepth": 16
          }
        }
      }
    }
  8. Understand the Contributor response type

    main

    The Contributor response type represents an artist contributing to a song or an album (e.g., a performer or a specific musician). This is a new OpenSubsonic-specific response type and is not supported by the standard Subsonic API.

    Fields

    FieldTypeRequiredDescription
    rolestringYesThe contributor role (e.g., performer).
    subRolestringNoA sub-role for specific roles, such as an instrument for a performer role. Note: For consistency across tag formats, TIPL sub-roles should be exposed directly in the role field when applicable.
    artistArtistID3YesThe ArtistID3 object representing the artist taking on the role. Only the required fields of ArtistID3 are returned by default.
  9. Structure of the ClientInfo payload

    main

    The ClientInfo payload is an extension used to communicate a client device's capabilities to the server. This allows the server to make informed decisions regarding direct playback, transcoding, and codec selection.

    Key capabilities communicated include:

    • Bitrate limits: maxAudioBitrate (for direct play) and maxTranscodingAudioBitrate (for transcoded streams).
    • Direct Play Profiles: A list of directPlayProfiles defining supported containers, codecs, protocols, and channel limits.
    • Transcoding Profiles: A prioritized list of transcodingProfiles that the server should evaluate in order to determine the best transcoding strategy.
    • Codec Profiles: Detailed codecProfiles that specify specific limitations (e.g., bitrate or samplerate constraints) for individual codecs.
    {
      "name": "Play:1",
      "platform": "Sonos",
      "maxAudioBitrate": 512000,
      "maxTranscodingAudioBitrate": 256000,
      "directPlayProfiles": [
        {
          "containers": [ "mp3" ],
          "audioCodecs": [ "mp3" ],
          "protocols": [ "http" ],
          "maxAudioChannels": 2
        }
      ],
      "transcodingProfiles": [
        {
          "container": "mp3",
          "audioCodec": "mp3",
          "protocol": "http",
          "maxAudioChannels": 2
        }
      ],
      "codecProfiles": [
        {
          "type": "AudioCodec",
          "name": "mp3",
          "limitations": [
            { "name": "audioBitrate", "comparison": "LessThanEqual", "values": [ "320000" ], "required": true }
          ]
        }
      ]
    }
  10. Understand the ArtistWithAlbumsID3 response format

    main

    The ArtistWithAlbumsID3 response is an extension of the ArtistID3 format that includes an array of AlbumID3 objects. This format is used to provide detailed information about an artist along with their associated albums.

    OpenSubsonic vs. Subsonic Differences

    When implementing or consuming this response, note that OpenSubsonic adds several specific fields. If a server supports these fields, it must return them (even with empty or default values) so clients can detect support. These additional fields are optional from a schema perspective but required for feature detection.

    OpenSubsonic specific fields:

    • musicBrainzId: The artist's MusicBrainzID.
    • sortName: The artist's sort name.
    • roles: A list of all roles this artist has in the library (e.g., artist, albumartist, composer).
    {
      "id": "37ec820ca7193e17040c98f7da7c4b51",
      "name": "2 Mello",
      "coverArt": "ar-37ec820ca7193e17040c98f7da7c4b51_0",
      "albumCount": 1,
      "userRating": 5,
      "artistImageUrl": "https://demo.org/image.jpg",
      "starred": "2017-04-11T10:42:50.842Z",
      "musicBrainzId": "189002e7-3285-4e2e-92a3-7f6c30d407a2",
      "sortName": "Mello (2)",
      "roles": [
        "artist",
        "albumartist",
        "composer"
      ],
      "album": [
        {
          "id": "200000002",
          "parent": "100000002",
          "album": "Colorsmoke EP",
          "title": "Colorsmoke EP",
          "name": "Colorsmoke EP",
          "isDir": true,
          "coverArt": "al-200000002",
          "songCount": 12,
          "created": "2021-02-23T04:24:48+00:00",
          "duration": 4568,
          "playCount": 1,
          "artistId": "100000002",
          "artist": "Synthetic",
          "year": 2007,
          "genre": "Electronic",
          "userRating": 5,
          "averageRating": 3,
          "starred": "2021-02-22T05:51:53Z"
        }
      ]
    }
  11. Handling multiple vocal agents and layers

    main

    For sources that distinguish between lead and background vocals, the API uses an agents array and cueLine indexing:

    1. agents array: Scoped to a single structuredLyrics entry. Each agent has a unique id and a role (e.g., main, bg, voice, group).
    2. agentId: Each cueLine must include an agentId that matches an ID in the agents array.
    3. Ordering: When multiple cueLines share the same index, the one referencing the agent with role: "main" must come first.
    4. Fallback: Use structuredLyrics.line[index].value as the combined fallback text for the entire lyric passage, as cueLine.value is specific to that agent/layer.