From 03aa44d23228247fd5ade8475d070acb69c05d28 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Tue, 11 Jun 2024 07:43:04 +0200 Subject: [PATCH 1/2] fix(providers): warn if GTIN lookup found multiple results for Spotify / Tidal Adapt the existing logic already implemented in iTunes and generalize it. --- providers/Spotify/mod.ts | 8 ++++++-- providers/Tidal/mod.ts | 3 +++ providers/base.ts | 14 ++++++++++++++ providers/iTunes/mod.ts | 8 +------- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/providers/Spotify/mod.ts b/providers/Spotify/mod.ts index ba6578e4..dc38491b 100644 --- a/providers/Spotify/mod.ts +++ b/providers/Spotify/mod.ts @@ -173,8 +173,12 @@ export class SpotifyReleaseLookup extends ReleaseApiLookup 1) { + this.warnMultipleResults(releases.slice(1).map((release) => release.external_urls?.spotify)); + } + return releases[0].id; } } } diff --git a/providers/Tidal/mod.ts b/providers/Tidal/mod.ts index 628edc66..6c43c098 100644 --- a/providers/Tidal/mod.ts +++ b/providers/Tidal/mod.ts @@ -157,6 +157,9 @@ export class TidalReleaseLookup extends ReleaseApiLookup { return Boolean(data?.data?.length); }; const result = await this.queryAllRegions>(isValidData); + if (result.data.length > 1) { + this.warnMultipleResults(result.data.slice(1).map((release) => release.resource.tidalUrl)); + } return result.data[0].resource; } else { const isValidData = (data: Resource) => { diff --git a/providers/base.ts b/providers/base.ts index cc1f8924..7672aa7b 100644 --- a/providers/base.ts +++ b/providers/base.ts @@ -21,6 +21,7 @@ import type { PartialDate } from '@/utils/date.ts'; import type { CacheOptions, Snapshot, SnapStorage } from 'snap-storage'; import type { MaybePromise } from 'utils/types.d.ts'; import type { Logger } from 'std/log/logger.ts'; +import { pluralWithCount } from '@/utils/plural.ts'; export type ProviderOptions = Partial<{ /** Duration of one rate-limiting interval for requests (in ms). */ @@ -335,6 +336,19 @@ export abstract class ReleaseLookup this.cleanViewUrl(skippedResults.find((result) => result.collectionId === id)!.collectionViewUrl) ); - this.addMessage( - `The API also returned ${ - pluralWithCount(skippedUrls.length, 'other result, which was skipped', 'other results, which were skipped') - }:\n- ${skippedUrls.join('\n- ')}`, - 'warning', - ); + this.warnMultipleResults(skippedUrls); } const linkTypes: LinkType[] = []; From 3ac4077484b13f0eb440cb27e41dc3edf0e6be72 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Tue, 11 Jun 2024 08:18:29 +0200 Subject: [PATCH 2/2] feat: show a "lookup" link in multiple results warning --- providers/base.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/providers/base.ts b/providers/base.ts index 7672aa7b..ea217ba8 100644 --- a/providers/base.ts +++ b/providers/base.ts @@ -341,10 +341,11 @@ export abstract class ReleaseLookup `${url} ([lookup](?url=${encodeURIComponent(String(url))}))`); this.addMessage( `The API also returned ${ pluralWithCount(urls.length, 'other result, which was skipped', 'other results, which were skipped') - }:\n- ${urls.join('\n- ')}`, + }:\n- ${lines.join('\n- ')}`, 'warning', ); }