在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jellyfin/jellyfin-sdk-kotlin开源软件地址(OpenSource Url):https://github.com/jellyfin/jellyfin-sdk-kotlin开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):Jellyfin Kotlin SDKJellyfin ProjectPart of theThe Jellyfin Kotlin SDK is a library implementing the Jellyfin API to easily access servers. It is currently available for the JVM and Android 4.4 and up. Java 8 or higher is required. Android versions below Android 8 should use library desugaring. SetupReleases are published to Gradle with Kotlin DSL implementation("org.jellyfin.sdk:jellyfin-core:$sdkVersion") Gradle with Groovyimplementation "org.jellyfin.sdk:jellyfin-core:$sdkVersion" Maven<dependency>
<groupId>org.jellyfin.sdk</groupId>
<artifactId>jellyfin-core</artifactId>
<version>$sdkVersion</version>
</dependency> Using SNAPSHOT versionsWhen working on new features in your application you might need a build of the SDK targeting the next server version.
For this use case we publish two SNAPSHOT releases: An example using Gradle with Kotlin DSL that only allows the repositories {
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
content {
// Only allow SDK snapshots
includeVersionByRegex("org\\.jellyfin\\.sdk", ".*", "master-SNAPSHOT")
}
}
} UsageCreating a Jellyfin instanceMost 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 = createJellyfin {
clientInfo = ClientInfo(name = "My awesome client!", version = "1.33.7",)
// Uncomment when using android:
// context = /* Android Context */
} Make sure to supply the client information if you want to make API calls. The context is required for Android applications. Creating an API instanceAPI 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
// httpClientOptions = HttpClientOptions() // allows setting additional options
) Authenticating a userAll API operations are grouped. To make use of an operation you need to first get the group from your ApiClient instance. All groups are defined as extension functions, and you can alternatively construct the API instances manually. val userApi = api.userApi
try {
val authenticationResult by userApi.authenticateUserByName(
username = "demo",
password = "",
)
// Use access token in api instance
api.accessToken = authenticationResult.accessToken
// Print session information
println(authenticationResult.sessionInfo)
} catch(err: ApiClientException) {
// Catch exceptions
println("Something went wrong! ${err.message}")
} WebSocketsJellyfin uses WebSockets to communicate events like library changes and activities. This API can be used with the SocketApi. Documentation is available in the docs folder. val instance = api.ws()
instance.addGlobalListener { message ->
println(message)
} Server discoveryThe 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 addresses. // 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 a flow of potential servers to connect to
val recommended = jellyfin.discovery.getRecommendedServers(candidates, RecommendedServerInfoScore.GOOD) More examplesWe 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 SDKOfficial Jellyfin clients
Third party clients
Want to add your project? We'd love to know about it, open an issue or create pull request! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论