Extend GameMetadataProvider with fetchById

This commit is contained in:
grimsi
2025-06-12 19:53:09 +02:00
parent ddfaeed34a
commit 0633bb14e7
6 changed files with 72 additions and 25 deletions
@@ -48,16 +48,21 @@ class SteamPlugin(wrapper: PluginWrapper) : GameyfinPlugin(wrapper) {
* The Steam Store API I am using provides far less info than IGDB for example
* See it more as a proof of concept than a fully functional plugin
**/
override fun fetchMetadata(gameId: String, maxResults: Int): List<GameMetadata> {
val searchResult: List<SteamGame> = runBlocking { searchStore(gameId) }
override fun fetchByTitle(gameTitle: String, maxResults: Int): List<GameMetadata> {
val searchResult: List<SteamGame> = runBlocking { searchStore(gameTitle) }
if (searchResult.isEmpty()) return emptyList()
val bestMatchingTitles = FuzzySearch.extractTop(gameId, searchResult.map { it.name }, maxResults)
val bestMatchingTitles = FuzzySearch.extractTop(gameTitle, searchResult.map { it.name }, maxResults)
val bestMatches = bestMatchingTitles.mapNotNull { title -> searchResult.find { it.name == title.string } }
return runBlocking { bestMatches.map { getGameDetails(it.id) } }.filterNotNull()
}
override fun fetchById(id: String): GameMetadata? {
val id = id.toIntOrNull() ?: return null
return runBlocking { getGameDetails(id) }
}
private suspend fun searchStore(title: String): List<SteamGame> {
val encodedTitle = URLEncoder.encode(title, StandardCharsets.UTF_8.toString())
return try {