feat: songTitle+artist match (#1154)

* feat: optional artist match

* fix: validation

* fix: also add ongeki to the example conf

* style: lint
This commit is contained in:
nairobi
2024-08-23 11:39:56 +01:00
committed by GitHub
parent de29177583
commit b4e863c015
5 changed files with 25 additions and 9 deletions
+1
View File
@@ -880,6 +880,7 @@ const PR_BATCH_MANUAL_SCORE = (game: Game, playtype: Playtype): PrudenceSchema =
identifier: "string",
comment: optNull(p.isBoundedString(3, 240)),
difficulty: "*?string",
artist: "*?string",
// this is checked in converting instead
// the lowest acceptable time is september 9th 2001 - this check saves people who dont
+1
View File
@@ -34,6 +34,7 @@ export type BatchManualScore<GPT extends GPTString = GPTString> = ExtractMetrics
comment?: string | null;
judgements?: Record<Judgements[GPT], integer>;
timeAchieved?: number | null;
artist?: string | null;
optional?: AllFieldsNullableOptional<ExtractMetrics<ConfOptionalMetrics[GPT]>>;
/**
+1
View File
@@ -50,6 +50,7 @@
"maimai",
"maimaidx",
"itg",
"ongeki",
"ddr"
],
IMPORT_TYPES: [
@@ -233,7 +233,7 @@ export async function ResolveMatchTypeToTachiData(
}
case "songTitle": {
const song = await FindSongOnTitleInsensitive(game, data.identifier);
const song = await FindSongOnTitleInsensitive(game, data.identifier, data.artist);
if (!song) {
throw new SongOrChartNotFoundFailure(
+21 -8
View File
@@ -50,21 +50,32 @@ export async function FindSongOnTitle(game: Game, title: string): Promise<SongDo
*/
export async function FindSongOnTitleInsensitive(
game: Game,
title: string
title: string,
artist?: string | null
): Promise<SongDocument | null> {
// @optimisable: Performance should be tested here by having a utility field for all-titles.
const regex = new RegExp(`^${EscapeStringRegexp(title)}$`, "iu");
const regexTitle = new RegExp(`^${EscapeStringRegexp(title)}$`, "iu");
const regexArtist = new RegExp(`^${EscapeStringRegexp(artist ?? "")}$`, "iu");
const res = await db.anySongs[game].find(
{
$or: [
$and: [
{
title: { $regex: regex },
},
{
altTitles: { $regex: regex },
$or: [
{
title: { $regex: regexTitle },
},
{
altTitles: { $regex: regexTitle },
},
],
},
artist
? {
artist: { $regex: regexArtist },
}
: {},
],
},
{
@@ -75,7 +86,9 @@ export async function FindSongOnTitleInsensitive(
if (res.length === 2) {
throw new AmbiguousTitleFailure(
title,
`Multiple songs exist with the case-insensitive title ${title}. We cannot resolve this. Please try and use a different song resolution method.`
artist
? `Multiple songs exist with the case-insensitive title ${title} by artist ${artist}. We cannot resolve this. Please try and use a different song resolution method.`
: `Multiple songs exist with the case-insensitive title ${title}. We cannot resolve this. Please try adding an artist field.`
);
}