mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-17 08:15:44 +00:00
Improve metadata matching algorithms
This commit is contained in:
@@ -142,7 +142,16 @@ class IgdbPlugin(wrapper: PluginWrapper) : ConfigurableGameyfinPlugin(wrapper) {
|
|||||||
|
|
||||||
// Use fuzzy search to find the best matching game name
|
// Use fuzzy search to find the best matching game name
|
||||||
val bestMatchingTitles = FuzzySearch.extractTop(gameTitle, games.map { it.name }, maxResults)
|
val bestMatchingTitles = FuzzySearch.extractTop(gameTitle, games.map { it.name }, maxResults)
|
||||||
games = bestMatchingTitles.mapNotNull { title -> games.find { it.name == title.string } }
|
val bestMatchingTitleStrings = bestMatchingTitles.map { it.string }
|
||||||
|
val bestMatchesMap = bestMatchingTitles.associateBy({ it.string }, { it.score })
|
||||||
|
|
||||||
|
// Filter the games to only include those that match the best matching titles
|
||||||
|
games = games.filter { it.name in bestMatchingTitleStrings }
|
||||||
|
|
||||||
|
// If we have more than maxResults, sort by the best match score and take the top results
|
||||||
|
games = games.filter { it.name in bestMatchesMap.keys }
|
||||||
|
.sortedByDescending { bestMatchesMap[it.name] }
|
||||||
|
.take(maxResults)
|
||||||
|
|
||||||
return games.map { toGameMetadata(it) }
|
return games.map { toGameMetadata(it) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Plugin-Version: 1.0.0-alpha8
|
Plugin-Version: 1.0.0-alpha9
|
||||||
Plugin-Class: de.grimsi.gameyfinplugins.igdb.IgdbPlugin
|
Plugin-Class: de.grimsi.gameyfinplugins.igdb.IgdbPlugin
|
||||||
Plugin-Id: de.grimsi.gameyfin.igdb
|
Plugin-Id: de.grimsi.gameyfin.igdb
|
||||||
Plugin-Name: IGDB Metadata
|
Plugin-Name: IGDB Metadata
|
||||||
|
|||||||
@@ -54,10 +54,21 @@ class SteamPlugin(wrapper: PluginWrapper) : GameyfinPlugin(wrapper) {
|
|||||||
val searchResult: List<SteamGame> = runBlocking { searchStore(gameTitle) }
|
val searchResult: List<SteamGame> = runBlocking { searchStore(gameTitle) }
|
||||||
if (searchResult.isEmpty()) return emptyList()
|
if (searchResult.isEmpty()) return emptyList()
|
||||||
|
|
||||||
|
// Use fuzzy search to find the best matching game name
|
||||||
val bestMatchingTitles = FuzzySearch.extractTop(gameTitle, 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 } }
|
val bestMatchingTitleStrings = bestMatchingTitles.map { it.string }
|
||||||
|
val bestMatchesMap = bestMatchingTitles.associateBy({ it.string }, { it.score })
|
||||||
|
|
||||||
return runBlocking { bestMatches.map { getGameDetails(it.id) } }.filterNotNull()
|
// Filter the games to only include those that match the best matching titles
|
||||||
|
var bestMatches = searchResult.filter { it.name in bestMatchingTitleStrings }
|
||||||
|
|
||||||
|
// If we have more than maxResults, sort by the best match score and take the top results
|
||||||
|
bestMatches = bestMatches.filter { it.name in bestMatchesMap.keys }
|
||||||
|
.sortedByDescending { bestMatchesMap[it.name] }
|
||||||
|
|
||||||
|
return runBlocking { bestMatches.map { getGameDetails(it.id) } }
|
||||||
|
.filterNotNull()
|
||||||
|
.take(maxResults)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchById(id: String): GameMetadata? {
|
override fun fetchById(id: String): GameMetadata? {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Plugin-Version: 1.0.0-alpha8
|
Plugin-Version: 1.0.0-alpha9
|
||||||
Plugin-Class: de.grimsi.gameyfinplugins.steam.SteamPlugin
|
Plugin-Class: de.grimsi.gameyfinplugins.steam.SteamPlugin
|
||||||
Plugin-Id: de.grimsi.gameyfin.steam
|
Plugin-Id: de.grimsi.gameyfin.steam
|
||||||
Plugin-Name: Steam Metadata
|
Plugin-Name: Steam Metadata
|
||||||
|
|||||||
+16
-11
@@ -74,20 +74,25 @@ class SteamGridDbPlugin(wrapper: PluginWrapper) : ConfigurableGameyfinPlugin(wra
|
|||||||
|
|
||||||
override fun fetchByTitle(gameTitle: String, maxResults: Int): List<GameMetadata> {
|
override fun fetchByTitle(gameTitle: String, maxResults: Int): List<GameMetadata> {
|
||||||
return runBlocking {
|
return runBlocking {
|
||||||
var searchResults = searchSteamGridDb(gameTitle)
|
val covers = mutableListOf<GameMetadata>()
|
||||||
|
val games = searchSteamGridDb(gameTitle)
|
||||||
|
|
||||||
if (searchResults.isEmpty()) return@runBlocking emptyList()
|
for (game in games) {
|
||||||
if (searchResults.size > maxResults) searchResults = searchResults.slice(0 until maxResults)
|
val gameDetails = client?.grids(game.id)
|
||||||
|
val grids = gameDetails?.data.orEmpty()
|
||||||
return@runBlocking searchResults
|
for (grid in grids) {
|
||||||
.map { game ->
|
covers.add(
|
||||||
GameMetadata(
|
GameMetadata(
|
||||||
originalId = game.id.toString(),
|
originalId = game.id.toString(),
|
||||||
title = game.name,
|
title = game.name,
|
||||||
coverUrl = getGridForGame(game.id)?.let { grid -> URI(grid.url) }
|
coverUrl = URI(grid.url)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
if (covers.size >= maxResults) break
|
||||||
}
|
}
|
||||||
.filter { it.coverUrl != null }
|
if (covers.size >= maxResults) break
|
||||||
|
}
|
||||||
|
covers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Plugin-Version: 1.0.0-alpha5
|
Plugin-Version: 1.0.0-alpha6
|
||||||
Plugin-Class: de.grimsi.gameyfinplugins.steamgriddb.SteamGridDbPlugin
|
Plugin-Class: de.grimsi.gameyfinplugins.steamgriddb.SteamGridDbPlugin
|
||||||
Plugin-Id: de.grimsi.gameyfin.steamgriddb
|
Plugin-Id: de.grimsi.gameyfin.steamgriddb
|
||||||
Plugin-Name: SteamGridDB Covers
|
Plugin-Name: SteamGridDB Covers
|
||||||
|
|||||||
Reference in New Issue
Block a user