subsonic-kotlin

Subsonic API client offering full OpenSubsonic coverage, token/API-key authentication, library browsing, search, playlists, streaming and cover-art URLs, scrobbling, rating, and robust error handling.

JVMKotlin/NativeWasmJS
GitHub stars3
Authorszt64
Open issues1
LicenseMIT License
Creation dateabout 2 months ago

Last activity19 days ago
Latest release1.0.0-beta01 (12 days ago)

subsonic-kotlin

Maven Central License

badge-platform-jvm badge-platform-android badge-platform-linux badge-platform-windows badge-platform-macos badge-platform-ios badge-platform-tvos badge-platform-watchos badge-platform-js badge-platform-wasm

A Kotlin Multiplatform client library for the Subsonic API.

Features

  • Full OpenSubsonic API coverage (based on API version 1.16.1)
  • Kotlin Multiplatform support (JVM, Android, Linux, Windows, macOS, iOS, tvOS, watchOS, JS, Wasm)
  • Token-based and API key authentication
  • Built on Ktor with kotlinx.serialization

Setup

Add the following to your gradle/libs.versions.toml:

[versions]
subsonicKotlin = "x.y.z"  # Replace with latest version

[libraries]
subsonicClient = { module = "dev.zt64.subsonic:subsonic-client", version.ref = "subsonicKotlin" }

Then add the dependency to your module's build.gradle.kts:

dependencies {
    implementation(libs.subsonicClient)
}

[!NOTE] A Ktor engine implementation must be included in your dependencies for the client to function.

Quick Start

Creating a Client

// Using a username and password
val client = SubsonicClient(
    baseUrl = "https://your-server.com",
    auth = SubsonicAuth.Token(
        username = "your-username",
        password = "your-password"
    )
)

// Using an API key (not universally supported, check your servers compatible authentication)
val client = SubsonicClient(
    baseUrl = "https://your-server.com",
    auth = SubsonicAuth.Key(apiKey = "your-api-key")
)

Basic Usage

// Test connectivity
client.ping()

// Browse library
val artists = client.getArtists()
val artist = client.getArtist(id = "123")
val album = client.getAlbum(id = "456")

// Search
val results = client.searchID3(query = "Beatles")

// Playlists
val playlists = client.getPlaylists()
val newPlaylist = client.createPlaylist(name = "My Mix", songIds = listOf("1", "2", "3"))

// Streaming
val streamUrl = client.getStreamUrl(id = "song-123", maxBitRate = 320)
val coverArtUrl = client.getCoverArtUrl(id = album.coverArt, size = "500")

// Star/Rate
client.star("song-123")
client.setRating(id = "song-123", rating = 5)

// Scrobble
client.scrobble(id = "song-123")

Error Handling

try {
    val album = client.getAlbum(id = "invalid-id")
} catch (e: SubsonicException) {
    println("${e.code}: ${e.message}")
}

Advanced Configuration

// Use a specific Ktor engine
val client = SubsonicClient(
    baseUrl = "https://your-server.com",
    auth = SubsonicAuth.Token(username = "user", password = "pass")
) {
    // Additional Ktor client configuration
    install(HttpTimeout) {
        requestTimeoutMillis = 30000
    }
}

API Compatibility

This library targets Subsonic API version 1.16.1 and supports the Open Subsonic specification. It has been tested with:

Most endpoints should work with any Subsonic-compatible server, though some features may vary by implementation.

Contributing

Contributions are welcome and encouraged! Please feel free to submit issues or pull requests.

License

This project is licensed under the MIT License.

JVMKotlin/NativeWasmJS
GitHub stars3
Authorszt64
Open issues1
LicenseMIT License
Creation dateabout 2 months ago

Last activity19 days ago
Latest release1.0.0-beta01 (12 days ago)

subsonic-kotlin

Maven Central License

badge-platform-jvm badge-platform-android badge-platform-linux badge-platform-windows badge-platform-macos badge-platform-ios badge-platform-tvos badge-platform-watchos badge-platform-js badge-platform-wasm

A Kotlin Multiplatform client library for the Subsonic API.

Features

  • Full OpenSubsonic API coverage (based on API version 1.16.1)
  • Kotlin Multiplatform support (JVM, Android, Linux, Windows, macOS, iOS, tvOS, watchOS, JS, Wasm)
  • Token-based and API key authentication
  • Built on Ktor with kotlinx.serialization

Setup

Add the following to your gradle/libs.versions.toml:

[versions]
subsonicKotlin = "x.y.z"  # Replace with latest version

[libraries]
subsonicClient = { module = "dev.zt64.subsonic:subsonic-client", version.ref = "subsonicKotlin" }

Then add the dependency to your module's build.gradle.kts:

dependencies {
    implementation(libs.subsonicClient)
}

[!NOTE] A Ktor engine implementation must be included in your dependencies for the client to function.

Quick Start

Creating a Client

// Using a username and password
val client = SubsonicClient(
    baseUrl = "https://your-server.com",
    auth = SubsonicAuth.Token(
        username = "your-username",
        password = "your-password"
    )
)

// Using an API key (not universally supported, check your servers compatible authentication)
val client = SubsonicClient(
    baseUrl = "https://your-server.com",
    auth = SubsonicAuth.Key(apiKey = "your-api-key")
)

Basic Usage

// Test connectivity
client.ping()

// Browse library
val artists = client.getArtists()
val artist = client.getArtist(id = "123")
val album = client.getAlbum(id = "456")

// Search
val results = client.searchID3(query = "Beatles")

// Playlists
val playlists = client.getPlaylists()
val newPlaylist = client.createPlaylist(name = "My Mix", songIds = listOf("1", "2", "3"))

// Streaming
val streamUrl = client.getStreamUrl(id = "song-123", maxBitRate = 320)
val coverArtUrl = client.getCoverArtUrl(id = album.coverArt, size = "500")

// Star/Rate
client.star("song-123")
client.setRating(id = "song-123", rating = 5)

// Scrobble
client.scrobble(id = "song-123")

Error Handling

try {
    val album = client.getAlbum(id = "invalid-id")
} catch (e: SubsonicException) {
    println("${e.code}: ${e.message}")
}

Advanced Configuration

// Use a specific Ktor engine
val client = SubsonicClient(
    baseUrl = "https://your-server.com",
    auth = SubsonicAuth.Token(username = "user", password = "pass")
) {
    // Additional Ktor client configuration
    install(HttpTimeout) {
        requestTimeoutMillis = 30000
    }
}

API Compatibility

This library targets Subsonic API version 1.16.1 and supports the Open Subsonic specification. It has been tested with:

Most endpoints should work with any Subsonic-compatible server, though some features may vary by implementation.

Contributing

Contributions are welcome and encouraged! Please feel free to submit issues or pull requests.

License

This project is licensed under the MIT License.