Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: songTitle+artist match #1154

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions common/src/types/batch-manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]>>;

/**
Expand Down
1 change: 1 addition & 0 deletions server/example/conf.json5
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"maimai",
"maimaidx",
"itg",
"ongeki",
"ddr"
],
IMPORT_TYPES: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
29 changes: 21 additions & 8 deletions server/src/utils/queries/songs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
title: { $regex: regex },
},
$and: [
{
altTitles: { $regex: regex },
$or: [
{
title: { $regex: regexTitle },
},
{
altTitles: { $regex: regexTitle },
},
],
},
artist
? {
artist: { $regex: regexArtist },
}
: {},
],
},
{
Expand All @@ -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.`
);
}

Expand Down
Loading