Kotlin SDK for Jellyfin, supporting Android and JVM targets
Go to file
Niels van Velzen 4b3e640175 Rename recommendedVersion to minimumVersion
The recommended version should always be the latest server version (which is stored in apiVersion). The minimumVersion should be the latest server version without significant API changes and is manually updated.
2021-04-28 21:51:24 +02:00
.github Merge pull request #229 from jellyfin/ci-lint-detekt-sarif 2021-04-17 16:15:14 +02:00
buildSrc Add linting in CI using Detekt with SARIF output 2021-04-17 10:20:10 +02:00
gradle Use centralized dependency versions for all project dependencies 2021-04-10 11:29:35 +02:00
jellyfin-api Fix, suppress or modify all Detekt linter issues (#231) 2021-04-18 17:47:03 +02:00
jellyfin-core Rename recommendedVersion to minimumVersion 2021-04-28 21:51:24 +02:00
jellyfin-model Add deviceInfo and clientInfo getters in Jellyfin class (#232) 2021-04-26 17:51:04 +02:00
jellyfin-platform-android Fix, suppress or modify all Detekt linter issues (#231) 2021-04-18 17:47:03 +02:00
openapi-generator Fix, suppress or modify all Detekt linter issues (#231) 2021-04-18 17:47:03 +02:00
samples/kotlin-cli Fix, suppress or modify all Detekt linter issues (#231) 2021-04-18 17:47:03 +02:00
.editorconfig Fix, suppress or modify all Detekt linter issues (#231) 2021-04-18 17:47:03 +02:00
.gitattributes Add .api files 2021-04-03 10:59:54 +02:00
.gitignore Update gitignore 2020-09-13 13:05:34 +02:00
build.gradle.kts Add linting in CI using Detekt with SARIF output 2021-04-17 10:20:10 +02:00
CODEOWNERS Add CODEOWNERS file 2021-03-18 22:08:46 +01:00
detekt.yml Fix, suppress or modify all Detekt linter issues (#231) 2021-04-18 17:47:03 +02:00
gradle.properties Increase memory for Dokka 2021-03-23 20:21:53 +01:00
gradlew Update Gradle Wrapper from 6.7 to 6.8.2. 2021-02-22 04:19:49 +00:00
gradlew.bat Update Gradle Wrapper from 6.7 to 6.8.2. 2021-02-22 04:19:49 +00:00
LICENSE Update license to LGPL 3.0 2020-09-13 17:08:50 +02:00
openapi.json Update generated sources to 10.7.2 2021-04-12 19:53:20 +00:00
README.md Fix broken badge in README (#202) 2021-03-24 19:24:43 +01:00
settings.gradle.kts Use centralized dependency versions for all project dependencies 2021-04-10 11:29:35 +02:00

Jellyfin Kotlin SDK

Part of the Jellyfin Project


Logo Banner

LGPL 3.0 license Current Release Maven Central Release
Donate Chat on Matrix Join our Subreddit Release RSS Feed Master Commits RSS Feed


The Jellyfin Kotlin SDK is a library implementing the Jellyfin API to easily access servers. It is currently available for the JVM and Android.

Setup

Releases are published to mavenCentral(). Make sure to use the correct library depending on your platform.

Latest version on Maven Central

Gradle with Kotlin DSL

implementation("org.jellyfin.sdk:jellyfin-core:$sdkVersion")

// Or when using Android
implementation("org.jellyfin.sdk:jellyfin-platform-android:$sdkVersion")
Gradle with Groovy
implementation "org.jellyfin.sdk:jellyfin-core:$sdkVersion"

// Or when using Android
implementation "org.jellyfin.sdk:jellyfin-platform-android:$sdkVersion"
Maven
<dependency>
    <groupId>org.jellyfin.sdk</groupId>
    <artifactId>jellyfin-core</artifactId>
    <version>$sdkVersion</version>
</dependency>

<!-- Or when using Android -->
<dependency>
    <groupId>org.jellyfin.sdk</groupId>
    <artifactId>jellyfin-platform-android</artifactId>
    <version>$sdkVersion</version>
</dependency>

Usage

Creating a Jellyfin instance

Most functionality of the SDK requires an instance of the Jellyfin class. This class holds the configuration required to make API calls and platform specific options. The Jellyfin class can be instantiated using a custom Kotlin DSL:

val jellyfin = Jellyfin {
    clientInfo = ClientInfo(name = "My awesome client!", version = "1.33.7",)
    
    // Uncomment if not using jellyfin-platform-android:
    // deviceInfo = DeviceInfo(id = UUID.randomUUID().toString(), name = "Awesome device",)

    // Uncomment when using jellyfin-platform-android:
    // android()
}

Make sure to supply the client and device information if you want to make API calls. Use the android() helper function when targeting Android to enable server discovery and set the device information automatically.

Creating an API instance

API calls require an API instance. This can be done with the createApi function. It requires a server address. The client and device information are set automatically but can be changed. All properties can be changed later in the API instance.

val api = jellyfin.createApi(
    baseUrl = "https://demo.jellyfin.org/stable/",
    // Optional options:
    // accessToken = "access token or api key"
    // clientInfo = ClientInfo(), // defaults to parent info
    // deviceInfo = DeviceInfo(), // defaults to parent info
)

Authenticating a user

All API operations are grouped. To make use of an operation you need to construct an instance of the group and give it your API instance.

val userApi = UserApi(api)

val authenticationResult by userApi.authenticateUserByName(
    username = "demo", 
    password = "",
)

// Use access token in api instance
api.accessToken = authenticationResult.accessToken

// Print session information
println(authenticationResult.sessionInfo)

WebSockets

Jellyfin uses WebSockets to communicate events like library changes and activities. This API can be used with the special WebSocketApi class.

val webSocketApi = WebSocketApi(api)

// Publish messages
webSocketApi.publish(ActivityLogEntryStartMessage())
webSocketApi.publish(SessionsStartMessage())
webSocketApi.publish(ScheduledTasksInfoStartMessage())

// Listen for messages
webSocketApi.subscribe().collect { message ->
    println(message)
}

Server discovery

The server discovery feature can be used to find servers on the local network, normalize inputted server addresses and to determine the best server to use from a list of adresses.

// Discover servers on the local network
jellyfin.discovery.discoverLocalServers().collect {
    println("Server ${it.name} was found at address ${it.address}")
}

// Get all candidates for a given input
val candidates = jellyfin.discovery.getAddressCandidates("demo.jellyfin.org/stable")

// Get best option from the candidates
val recommended = jellyfin.discovery.getRecommendedServer(candidates)

More examples

We provide a few small projects in the samples folder. The samples are used for testing new features and can be used as a basis for your own application.

Projects using the SDK

Official Jellyfin clients

Third party clients

  • Gelli is a music-focused Android client.

Want to add your project? Please create a pull request!