From 5ec899c9cb88c154663e97fcf10b09daefe3f4cd Mon Sep 17 00:00:00 2001 From: Jos Vooges | STH Date: Sun, 13 Sep 2026 13:49:26 +0200 Subject: [PATCH] Fix OpenSubtitles.org search by zero-padding IMDb IDs. Unpadded IDs triggered a broken redirect and silent empty subtitle results. --- apps/master-api/src/opensubtitles/org-client.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/master-api/src/opensubtitles/org-client.ts b/apps/master-api/src/opensubtitles/org-client.ts index 9d402fe..7c63883 100644 --- a/apps/master-api/src/opensubtitles/org-client.ts +++ b/apps/master-api/src/opensubtitles/org-client.ts @@ -150,8 +150,11 @@ function mapRow(row: OrgRow, fallbackLang: string): SubtitleHit | null { function normalizeImdb(id?: string | null): string | null { if (!id) return null; - const digits = String(id).trim().replace(/^tt/i, "").replace(/^0+(?=\d)/, ""); - return /^\d+$/.test(digits) ? digits : null; + const digits = String(id).trim().replace(/^tt/i, "").replace(/\D/g, ""); + if (!digits) return null; + // OS.org URLs expect ≥7-digit zero-padded IDs; stripping zeros causes a + // broken 302 to host "_" and silent empty search results. + return digits.padStart(7, "0"); } /** Legacy REST uses OpenSubtitles language ids (`dut` = Dutch). */