mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 08:15:48 +00:00
* Implement #636 * Fix potential bug in Regex parsing Add validation in UI Adjust log entries
This commit is contained in:
@@ -45,8 +45,11 @@ function LibraryManagementLayout({getConfig, formik}: any) {
|
|||||||
<ConfigFormField configElement={getConfig("library.scan.enable-filesystem-watcher")} isDisabled/>
|
<ConfigFormField configElement={getConfig("library.scan.enable-filesystem-watcher")} isDisabled/>
|
||||||
<ConfigFormField configElement={getConfig("library.scan.scan-empty-directories")}/>
|
<ConfigFormField configElement={getConfig("library.scan.scan-empty-directories")}/>
|
||||||
<div className="flex flex-row gap-4 items-baseline">
|
<div className="flex flex-row gap-4 items-baseline">
|
||||||
<ConfigFormField configElement={getConfig("library.scan.title-match-min-ratio")}/>
|
<ConfigFormField configElement={getConfig("library.scan.extract-title-using-regex")}/>
|
||||||
|
<ConfigFormField configElement={getConfig("library.scan.title-extraction-regex")}
|
||||||
|
isDisabled={!formik.values.library.scan["extract-title-using-regex"]}/>
|
||||||
</div>
|
</div>
|
||||||
|
<ConfigFormField configElement={getConfig("library.scan.title-match-min-ratio")}/>
|
||||||
<ConfigFormField configElement={getConfig("library.scan.game-file-extensions")}/>
|
<ConfigFormField configElement={getConfig("library.scan.game-file-extensions")}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -95,6 +98,14 @@ const validationSchema = Yup.object({
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
schedule: Yup.string().cron()
|
schedule: Yup.string().cron()
|
||||||
})
|
})
|
||||||
|
}),
|
||||||
|
scan: Yup.object({
|
||||||
|
"extract-title-using-regex": Yup.boolean(),
|
||||||
|
"title-extraction-regex": Yup.string().when("extract-title-using-regex", {
|
||||||
|
is: true,
|
||||||
|
then: (schema) => schema.trim().required("Title extraction regex is required when enabled")
|
||||||
|
}),
|
||||||
|
"title-match-min-ratio": Yup.number().min(1, "Must be between 1-100").max(100, "Must be between 1-100")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,6 +36,20 @@ sealed class ConfigProperties<T : Serializable>(
|
|||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data object ExtractTitleUsingRegex : ConfigProperties<Boolean>(
|
||||||
|
Boolean::class,
|
||||||
|
"library.scan.extract-title-using-regex",
|
||||||
|
"Extract title from file names using regex",
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
|
data object TitleExtractionRegex : ConfigProperties<String>(
|
||||||
|
String::class,
|
||||||
|
"library.scan.title-extraction-regex",
|
||||||
|
"Regex to extract title from file names",
|
||||||
|
"^[^\\[]+"
|
||||||
|
)
|
||||||
|
|
||||||
data object TitleMatchMinRatio : ConfigProperties<Int>(
|
data object TitleMatchMinRatio : ConfigProperties<Int>(
|
||||||
Int::class,
|
Int::class,
|
||||||
"library.scan.title-match-min-ratio",
|
"library.scan.title-match-min-ratio",
|
||||||
|
|||||||
@@ -603,7 +603,26 @@ class GameService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun matchFromFile(path: Path, library: Library): Game? {
|
fun matchFromFile(path: Path, library: Library): Game? {
|
||||||
val query = FilenameUtils.removeExtension(path.fileName.toString())
|
var query = FilenameUtils.removeExtension(path.fileName.toString())
|
||||||
|
|
||||||
|
// (Optional) Step -1: Extract title from filename using regex
|
||||||
|
if (config.get(ConfigProperties.Libraries.Scan.ExtractTitleUsingRegex) == true) {
|
||||||
|
val regexString = config.get(ConfigProperties.Libraries.Scan.TitleExtractionRegex)
|
||||||
|
if (regexString != null && regexString.isNotEmpty()) {
|
||||||
|
try {
|
||||||
|
val regex = Regex(regexString)
|
||||||
|
val originalQuery = query
|
||||||
|
query = regex.find(query)?.value?.trim() ?: query.also {
|
||||||
|
log.warn { "No match found for regex '$regexString' in filename '$query'. Using full filename." }
|
||||||
|
}
|
||||||
|
log.debug { "Extracted title '$query' from filename '$originalQuery'" }
|
||||||
|
} catch (_: Exception) {
|
||||||
|
log.error { "Title extraction regex ($regexString) is invalid, using fill filename." }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn { "No regex configured for title extraction, using full filename '$query'" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Step 0: Query all metadata plugins for metadata on the provided game title
|
// Step 0: Query all metadata plugins for metadata on the provided game title
|
||||||
val metadataResults = queryPlugins(query)
|
val metadataResults = queryPlugins(query)
|
||||||
|
|||||||
Reference in New Issue
Block a user