From 07bb16dfe757d25b068cbb593714e7a6196f44fd Mon Sep 17 00:00:00 2001 From: patrick Date: Fri, 9 Jan 2026 10:38:29 +0100 Subject: [PATCH] api/soundcloud: fix extraction of client_id (#1497) fixes #1495 --- api/src/processing/services/soundcloud.js | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/api/src/processing/services/soundcloud.js b/api/src/processing/services/soundcloud.js index a73e6474..9692a519 100644 --- a/api/src/processing/services/soundcloud.js +++ b/api/src/processing/services/soundcloud.js @@ -15,24 +15,27 @@ async function findClientID() { return cachedID.id; } - const scripts = sc.matchAll(//g); + let clientid = sc.match(/"hydratable"\s*:\s*"apiClient"\s*,\s*"data"\s*:\s*\{\s*"id"\s*:\s*"([^"]+)"/)?.[1]; + if (!clientid) { + const scripts = sc.matchAll(//g); - let clientid; - for (let script of scripts) { - const url = script[1]; + for (let script of scripts) { + const url = script[1]; - if (!url?.startsWith('https://a-v2.sndcdn.com/')) { - return; - } + if (!url?.startsWith('https://a-v2.sndcdn.com/')) { + return; + } - const scrf = await fetch(url).then(r => r.text()).catch(() => {}); - const id = scrf.match(/\("client_id=[A-Za-z0-9]{32}"\)/); + const scrf = await fetch(url).then(r => r.text()).catch(() => {}); + const id = scrf.match(/,client_id:"([A-Za-z0-9]{32})",/); - if (id && typeof id[0] === 'string') { - clientid = id[0].match(/[A-Za-z0-9]{32}/)[0]; - break; + if (id && id.length >= 2) { + clientid = id[1]; + break; + } } } + cachedID.version = scVersion; cachedID.id = clientid;