Add a minimum confidence level threshold to match after scan runs.

This commit is contained in:
Marke Hallowell 2025-11-07 23:28:21 -08:00
parent 0ab72d879e
commit 3a751f711a
7 changed files with 54 additions and 7 deletions

View file

@ -354,6 +354,19 @@ class LibraryController {
updatedSettings[key] = req.body.settings[key] === null ? null : Number(req.body.settings[key])
Logger.debug(`[LibraryController] Library "${req.library.name}" updating setting "${key}" to "${updatedSettings[key]}"`)
}
} else if (key === 'matchMinConfidence') {
if (req.body.settings[key] !== null && isNaN(req.body.settings[key])) {
Logger.error(`[LibraryController] Invalid request. Setting "${key}" must be a number`)
return res.status(400).send(`Invalid request. Setting "${key}" must be a number`)
} else if (req.body.settings[key] !== null && (Number(req.body.settings[key]) < 0 || Number(req.body.settings[key]) > 1)) {
Logger.error(`[LibraryController] Invalid request. Setting "${key}" must be between 0 and 1`)
return res.status(400).send(`Invalid request. Setting "${key}" must be between 0 and 1`)
}
if (req.body.settings[key] !== updatedSettings[key]) {
hasUpdates = true
updatedSettings[key] = req.body.settings[key] === null ? null : Number(req.body.settings[key])
Logger.debug(`[LibraryController] Library "${req.library.name}" updating setting "${key}" to "${updatedSettings[key]}"`)
}
} else if (key === 'matchAfterScan') {
if (typeof req.body.settings[key] !== 'boolean') {
return res.status(400).send('Invalid request. Setting "matchAfterScan" must be a boolean')

View file

@ -84,7 +84,9 @@ class CronManager {
checkRemoveEmptySeries,
checkRemoveAuthorsWithNoBooks
}
Scanner.matchLibraryItems(apiRouterCtx, library)
Scanner.matchLibraryItems(apiRouterCtx, library, {
minConfidence: library.settings.matchMinConfidence
})
}
}
})

View file

@ -69,6 +69,7 @@ class Library extends Model {
disableWatcher: false,
autoScanCronExpression: null,
matchAfterScan: false,
matchMinConfidence: 0,
skipMatchingMediaWithAsin: false,
skipMatchingMediaWithIsbn: false,
audiobooksOnly: false,

View file

@ -60,6 +60,12 @@ class Scanner {
}
const matchData = results[0]
if (options.minConfidence && matchData.matchConfidence < options.minConfidence) {
return {
warning: `Match confidence ${matchData.matchConfidence} is below the minimum of ${options.minConfidence}`
}
}
// Update cover if not set OR overrideCover flag
if (matchData.cover && (!libraryItem.media.coverPath || options.overrideCover)) {
Logger.debug(`[Scanner] Updating cover "${matchData.cover}"`)
@ -433,7 +439,7 @@ class Scanner {
* @param {LibraryScan} libraryScan
* @returns {Promise<boolean>} false if scan canceled
*/
async matchLibraryItemsChunk(apiRouterCtx, library, libraryItems, libraryScan) {
async matchLibraryItemsChunk(apiRouterCtx, library, libraryItems, libraryScan, options = {}) {
for (let i = 0; i < libraryItems.length; i++) {
const libraryItem = libraryItems[i]
@ -448,7 +454,7 @@ class Scanner {
}
Logger.debug(`[Scanner] matchLibraryItems: Quick matching "${libraryItem.media.title}" (${i + 1} of ${libraryItems.length})`)
const result = await this.quickMatchLibraryItem(apiRouterCtx, libraryItem, { provider: library.provider })
const result = await this.quickMatchLibraryItem(apiRouterCtx, libraryItem, { provider: library.provider, minConfidence: options.minConfidence })
if (result.warning) {
Logger.warn(`[Scanner] matchLibraryItems: Match warning ${result.warning} for library item "${libraryItem.media.title}"`)
} else if (result.updated) {
@ -470,7 +476,7 @@ class Scanner {
* @param {import('../routers/ApiRouter')} apiRouterCtx
* @param {import('../models/Library')} library
*/
async matchLibraryItems(apiRouterCtx, library) {
async matchLibraryItems(apiRouterCtx, library, options = {}) {
if (library.mediaType === 'podcast') {
Logger.error(`[Scanner] matchLibraryItems: Match all not supported for podcasts yet`)
return
@ -509,7 +515,7 @@ class Scanner {
offset += limit
hasMoreChunks = libraryItems.length === limit
const shouldContinue = await this.matchLibraryItemsChunk(apiRouterCtx, library, libraryItems, libraryScan)
const shouldContinue = await this.matchLibraryItemsChunk(apiRouterCtx, library, libraryItems, libraryScan, options)
if (!shouldContinue) {
isCanceled = true
break