Skip to content

Commit 11b3bbe

Browse files
committed
api/soundcloud: fix regex & check html for hydrated client_id
* hydratable regex courtesy of https://git.canine.tools/canine.tools/cobalt/commit/6d77edd0a0fb5ac6b4083b40e66cf675281e2fed, thanks!
1 parent eb5cf3b commit 11b3bbe

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

api/src/processing/services/soundcloud.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@ async function findClientID() {
1515
return cachedID.id;
1616
}
1717

18-
const scripts = sc.matchAll(/<script.+src="(.+)">/g);
18+
let clientid = sc.match(/"hydratable"\s*:\s*"apiClient"\s*,\s*"data"\s*:\s*\{\s*"id"\s*:\s*"([^"]+)"/)?.[1];
19+
if (!clientid) {
20+
const scripts = sc.matchAll(/<script.+src="(.+)">/g);
1921

20-
let clientid;
21-
for (let script of scripts) {
22-
const url = script[1];
22+
for (let script of scripts) {
23+
const url = script[1];
2324

24-
if (!url?.startsWith('https://a-v2.sndcdn.com/')) {
25-
return;
26-
}
25+
if (!url?.startsWith('https://a-v2.sndcdn.com/')) {
26+
return;
27+
}
2728

28-
const scrf = await fetch(url).then(r => r.text()).catch(() => {});
29-
const id = scrf.match(/\("client_id=[A-Za-z0-9]{32}"\)/);
29+
const scrf = await fetch(url).then(r => r.text()).catch(() => {});
30+
const id = scrf.match(/,client_id:"([A-Za-z0-9]{32})",/);
3031

31-
if (id && typeof id[0] === 'string') {
32-
clientid = id[0].match(/[A-Za-z0-9]{32}/)[0];
33-
break;
32+
if (id && id.length >= 2) {
33+
clientid = id[1];
34+
break;
35+
}
3436
}
3537
}
38+
3639
cachedID.version = scVersion;
3740
cachedID.id = clientid;
3841

0 commit comments

Comments
 (0)