Use undocumented field release_date

Close client on Plugin.stop()
This commit is contained in:
GRIMSIM
2025-06-18 17:49:20 +02:00
parent ed95400d2d
commit 0e928f812a
4 changed files with 53 additions and 3 deletions
@@ -56,6 +56,11 @@ class SteamGridDbPlugin(wrapper: PluginWrapper) : ConfigurableGameyfinPlugin(wra
}
}
override fun stop() {
client?.close()
client = null
}
private suspend fun authenticate(apiKey: String? = null) {
log.debug("Authenticating on SteamGridDB API...")
@@ -83,6 +88,7 @@ class SteamGridDbPlugin(wrapper: PluginWrapper) : ConfigurableGameyfinPlugin(wra
GameMetadata(
originalId = game.id.toString(),
title = game.name,
release = game.releaseDate,
coverUrls = grids?.map { URI(it.url) },
headerUrls = heroes?.map { URI(it.url) }
)
@@ -101,6 +107,7 @@ class SteamGridDbPlugin(wrapper: PluginWrapper) : ConfigurableGameyfinPlugin(wra
return@runBlocking GameMetadata(
originalId = game.id.toString(),
title = game.name,
release = game.releaseDate,
coverUrls = grids?.map { URI(it.url) },
headerUrls = heroes?.map { URI(it.url) }
)
@@ -44,6 +44,10 @@ class SteamGridDbApiClient(private val apiKey: String) {
return get("search/autocomplete/${term.encodeURLPath(encodeSlash = true, encodeEncoded = false)}", block).body()
}
suspend fun game(gameId: Int, block: HttpRequestBuilder.() -> Unit = {}): SteamGridDbGameResult {
return get("games/id/$gameId", block).body()
}
suspend fun grids(gameId: Int, block: HttpRequestBuilder.() -> Unit = {}): SteamGridDbGridResult {
return get("grids/game/$gameId") {
url {
@@ -59,8 +63,8 @@ class SteamGridDbApiClient(private val apiKey: String) {
}.body()
}
suspend fun game(gameId: Int, block: HttpRequestBuilder.() -> Unit = {}): SteamGridDbGameResult {
return get("games/id/$gameId", block).body()
fun close() {
client.close()
}
private suspend fun get(endpoint: String, block: HttpRequestBuilder.() -> Unit = {}): HttpResponse {
@@ -1,10 +1,16 @@
package org.gameyfin.plugins.metadata.steamgriddb.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.gameyfin.plugins.metadata.steamgriddb.util.InstantEpochSecondsSerializer
import java.time.Instant
@Serializable
data class SteamGridDbGame(
val id: Int,
val name: String
val name: String,
@SerialName("release_date")
@Serializable(with = InstantEpochSecondsSerializer::class)
val releaseDate: Instant? = null
)
@@ -0,0 +1,33 @@
package org.gameyfin.plugins.metadata.steamgriddb.util
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import java.time.Instant
@OptIn(ExperimentalSerializationApi::class)
object InstantEpochSecondsSerializer : KSerializer<Instant?> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("InstantEpochSeconds", PrimitiveKind.LONG)
override fun serialize(encoder: Encoder, value: Instant?) {
if (value == null) {
encoder.encodeNull()
} else {
encoder.encodeLong(value.epochSecond)
}
}
override fun deserialize(decoder: Decoder): Instant? {
return if (decoder.decodeNotNullMark()) {
Instant.ofEpochSecond(decoder.decodeLong())
} else {
decoder.decodeNull()
null
}
}
}