mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-15 00:30:02 +00:00
Extend GameMetadataProvider with fetchById
This commit is contained in:
+23
-2
@@ -72,9 +72,9 @@ class SteamGridDbPlugin(wrapper: PluginWrapper) : ConfigurableGameyfinPlugin(wra
|
||||
@Extension
|
||||
class SteamGridDBGameCoverProvider : GameMetadataProvider {
|
||||
|
||||
override fun fetchMetadata(gameId: String, maxResults: Int): List<GameMetadata> {
|
||||
override fun fetchByTitle(gameTitle: String, maxResults: Int): List<GameMetadata> {
|
||||
return runBlocking {
|
||||
var searchResults = searchSteamGridDb(gameId)
|
||||
var searchResults = searchSteamGridDb(gameTitle)
|
||||
|
||||
if (searchResults.isEmpty()) return@runBlocking emptyList()
|
||||
if (searchResults.size > maxResults) searchResults = searchResults.slice(0 until maxResults)
|
||||
@@ -91,6 +91,19 @@ class SteamGridDbPlugin(wrapper: PluginWrapper) : ConfigurableGameyfinPlugin(wra
|
||||
}
|
||||
}
|
||||
|
||||
override fun fetchById(id: String): GameMetadata? {
|
||||
return runBlocking {
|
||||
val gameId = id.toIntOrNull() ?: return@runBlocking null
|
||||
val game = getGameById(gameId) ?: return@runBlocking null
|
||||
|
||||
return@runBlocking GameMetadata(
|
||||
originalId = game.id.toString(),
|
||||
title = game.name,
|
||||
coverUrl = getGridForGame(game.id)?.let { grid -> URI(grid.url) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun searchSteamGridDb(term: String): List<SteamGridDbGame> {
|
||||
val client = client ?: throw PluginConfigError("SteamGridDB API client not initialized")
|
||||
|
||||
@@ -110,5 +123,13 @@ class SteamGridDbPlugin(wrapper: PluginWrapper) : ConfigurableGameyfinPlugin(wra
|
||||
|
||||
return gameDetails.data?.firstOrNull()
|
||||
}
|
||||
|
||||
private suspend fun getGameById(gameId: Int): SteamGridDbGame? {
|
||||
val client = client ?: throw PluginConfigError("SteamGridDB API client not initialized")
|
||||
|
||||
val gameDetails = client.game(gameId)
|
||||
|
||||
return gameDetails.data?.firstOrNull()
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -51,6 +51,10 @@ class SteamGridDbApiClient(private val apiKey: String) {
|
||||
}.body()
|
||||
}
|
||||
|
||||
suspend fun game(gameId: Int, block: HttpRequestBuilder.() -> Unit = {}): SteamGridDbSearchResult {
|
||||
return get("games/id/$gameId", block).body()
|
||||
}
|
||||
|
||||
private suspend fun get(endpoint: String, block: HttpRequestBuilder.() -> Unit = {}): HttpResponse {
|
||||
return client.get("$BASE_URL/$endpoint".encodeURLPath(encodeEncoded = false)) {
|
||||
bearerAuth(apiKey)
|
||||
|
||||
Reference in New Issue
Block a user