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 1/2] 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 Date: Sun, 9 Aug 2026 21:59:20 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: David Kellner <52860029+kellnerd@users.noreply.github.com> --- providers/Qobuz/mod.test.ts | 4 ++-- providers/Qobuz/mod.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/providers/Qobuz/mod.test.ts b/providers/Qobuz/mod.test.ts index 568b90ad..ed688475 100644 --- a/providers/Qobuz/mod.test.ts +++ b/providers/Qobuz/mod.test.ts @@ -130,11 +130,11 @@ describe('Qobuz provider', () => { }); describe('GTIN normalization', () => { - it('appends a missing check digit to legacy 13-digit UPC values', () => { + it('appends a missing check digit to invalid 13-digit barcodes, turning them into valid GTIN-14', () => { assertEquals(normalizeQobuzGtin('0001589171735'), '00015891717357'); }); - it('preserves UPC values which already have a valid check digit', () => { + it('preserves GTIN-13 values which already have a valid check digit', () => { assertEquals(normalizeQobuzGtin('0198884774947'), '0198884774947'); }); }); diff --git a/providers/Qobuz/mod.ts b/providers/Qobuz/mod.ts index 1bb6d59b..432934ce 100644 --- a/providers/Qobuz/mod.ts +++ b/providers/Qobuz/mod.ts @@ -29,6 +29,7 @@ import { ResponseError as SnapResponseError } from 'snap-storage'; const qobuzAppId = getFromEnv('HARMONY_QOBUZ_APP_ID') || ''; +/** Appends the missing check digit to invalid 13 digit barcodes from older Qobuz releases. */ export function normalizeQobuzGtin(upc: string): string { if (isValidGTIN(upc) || !/^\d{13}$/.test(upc)) { return upc;