Skip to content

Commit

Permalink
Improve metacritic search
Browse files Browse the repository at this point in the history
  • Loading branch information
Agreon committed Sep 21, 2023
1 parent 12598ba commit 84cd0b0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion searcher/src/searchers/metacritic-searcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { AxiosInstance } from 'axios';
import * as t from 'io-ts';

import { InfoSearcher, InfoSearcherContext } from '../search-service';
import { findBestMatch } from '../util/find-best-match';
import { matchingName } from '../util/matching-name';

const MetacriticApiGameComponentResponseDataStructure = t.type({
data: t.type({
totalResults: t.number,
items: t.array(t.type({
type: t.string,
title: t.string,
slug: t.string,
criticScoreSummary: t.type({
Expand Down Expand Up @@ -43,8 +45,10 @@ export class MetacriticSearcher implements InfoSearcher {
}

const parsedDate = parseStructure(MetacriticApiGameComponentResponseDataStructure, unknownData.components[0]);
const { title, slug, criticScoreSummary: { score } } = parsedDate.data.items[0];

const games = parsedDate.data.items.filter(({ type }) => type === 'game-title');

const { title, slug, criticScoreSummary: { score } } = findBestMatch(search, games, 'title');
if (!matchingName(title, search)) {
logger.debug(`Found name '${title}' does not include search '${search}'. Skipping`);

Expand Down

0 comments on commit 84cd0b0

Please sign in to comment.