From 1f72b0dffbfde8736da4459c744ffcf508118c31 Mon Sep 17 00:00:00 2001 From: Floze <88098863+floze-the-genius@users.noreply.github.com> Date: Sun, 19 Jul 2026 17:33:15 +0400 Subject: [PATCH] fix(Qobuz): restore missing GTIN check digits --- providers/Qobuz/mod.test.ts | 12 +++++++++++- providers/Qobuz/mod.ts | 12 ++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/providers/Qobuz/mod.test.ts b/providers/Qobuz/mod.test.ts index fef74344..568b90ad 100644 --- a/providers/Qobuz/mod.test.ts +++ b/providers/Qobuz/mod.test.ts @@ -6,7 +6,7 @@ import { assert } from 'std/assert/assert.ts'; import { afterAll, describe, it } from '@std/testing/bdd'; import { assertSnapshot } from '@std/testing/snapshot'; -import QobuzProvider from './mod.ts'; +import QobuzProvider, { normalizeQobuzGtin } from './mod.ts'; import { assertEquals } from 'std/assert/assert_equals.ts'; describe('Qobuz provider', () => { @@ -129,6 +129,16 @@ describe('Qobuz provider', () => { ); }); + describe('GTIN normalization', () => { + it('appends a missing check digit to legacy 13-digit UPC values', () => { + assertEquals(normalizeQobuzGtin('0001589171735'), '00015891717357'); + }); + + it('preserves UPC values which already have a valid check digit', () => { + assertEquals(normalizeQobuzGtin('0198884774947'), '0198884774947'); + }); + }); + afterAll(() => { lookupStub.restore(); }); diff --git a/providers/Qobuz/mod.ts b/providers/Qobuz/mod.ts index 1b662912..1bb6d59b 100644 --- a/providers/Qobuz/mod.ts +++ b/providers/Qobuz/mod.ts @@ -5,7 +5,7 @@ import { DurationPrecision, FeatureQuality, FeatureQualityMap } from '@/provider import { getFromEnv } from '@/utils/config.ts'; import { parseHyphenatedDate, PartialDate } from '@/utils/date.ts'; import { ResponseError } from '@/utils/errors.ts'; -import { isEqualGTIN } from '@/utils/gtin.ts'; +import { checkDigit, isEqualGTIN, isValidGTIN } from '@/utils/gtin.ts'; import type { ArtistCreditName, Artwork, @@ -29,6 +29,14 @@ import { ResponseError as SnapResponseError } from 'snap-storage'; const qobuzAppId = getFromEnv('HARMONY_QOBUZ_APP_ID') || ''; +export function normalizeQobuzGtin(upc: string): string { + if (isValidGTIN(upc) || !/^\d{13}$/.test(upc)) { + return upc; + } + + return `${upc}${checkDigit(`${upc}0`)}`; +} + export default class QobuzProvider extends MetadataApiProvider { readonly name = 'Qobuz'; @@ -245,7 +253,7 @@ export class QobuzReleaseLookup extends ReleaseApiLookup