From 4702fcb33183131823dd5620ca9925cf7990e319 Mon Sep 17 00:00:00 2001 From: David Kellner <52860029+kellnerd@users.noreply.github.com> Date: Mon, 8 Jul 2024 22:31:48 +0200 Subject: [PATCH] feat(Deezer): Fail lookups for which the API returns a wrong ID or GTIN Deezer recently changed the behavior of their API to return only releases which are available in the client's region (as it seems). --- providers/Deezer/mod.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/providers/Deezer/mod.ts b/providers/Deezer/mod.ts index 1a2f4a1..16ed26d 100644 --- a/providers/Deezer/mod.ts +++ b/providers/Deezer/mod.ts @@ -4,8 +4,8 @@ import { DurationPrecision, FeatureQuality, FeatureQualityMap } from '@/provider import { capitalizeReleaseType } from '@/harmonizer/release_types.ts'; import { parseHyphenatedDate, PartialDate } from '@/utils/date.ts'; import { splitLabels } from '@/utils/label.ts'; -import { ResponseError } from '@/utils/errors.ts'; -import { formatGtin } from '@/utils/gtin.ts'; +import { ProviderError, ResponseError } from '@/utils/errors.ts'; +import { formatGtin, isEqualGTIN } from '@/utils/gtin.ts'; import type { ApiError, MinimalArtist, Release, ReleaseTrack, Result, Track, TracklistItem } from './api_types.ts'; import type { @@ -134,6 +134,20 @@ export class DeezerReleaseLookup extends ReleaseApiLookup { this.id = rawRelease.id.toString(); + if (this.lookup.method === 'id' && this.id !== this.lookup.value) { + throw new ProviderError( + this.provider.name, + `API returned ${this.constructReleaseUrl(this.id, this.lookup)} instead of the requested ${ + this.constructReleaseUrl(this.lookup.value, this.lookup) + }`, + ); + } else if (this.lookup.method === 'gtin' && !isEqualGTIN(rawRelease.upc, this.lookup.value)) { + throw new ProviderError( + this.provider.name, + `API returned a release with GTIN ${rawRelease.upc} instead of the requested ${this.lookup.value}`, + ); + } + const incompleteTracklist = rawRelease.nb_tracks > rawRelease.tracks.data.length; const needToFetchIndividualTracks = this.options.withAllTrackArtists || this.options.withAvailability || false; const needToFetchDetailedTracklist = incompleteTracklist ||