fix: regex accessToken directly from embed HTML instead of brittle JSON path

This commit is contained in:
Honey committed 2026-05-09 20:17:37 +02:00
1 parent 60c74a60a2
commit 6c4caebc69
1 file changed
+5 -7
+5 -7
View File
@@ -83,13 +83,11 @@ async function fetchSpotifyToken() {
}); });
if (!r.ok) throw new Error(`Spotify-Embed nicht erreichbar (${r.status})`); if (!r.ok) throw new Error(`Spotify-Embed nicht erreichbar (${r.status})`);
const html = await r.text(); const html = await r.text();
const m = html.match(/<script id="__NEXT_DATA__" type="application\/json">(.+?)<\/script>/s); const tokenMatch = html.match(/"accessToken"\s*:\s*"([^"]+)"/);
if (!m) throw new Error('Spotify-Seite nicht parsebar'); if (!tokenMatch) throw new Error('Kein Token in Spotify-Embed gefunden');
const nd = JSON.parse(m[1]); const expiryMatch = html.match(/"accessTokenExpirationTimestampMs"\s*:\s*(\d+)/);
const token = nd?.props?.pageProps?.accessToken; _spTokenCache = tokenMatch[1];
if (!token) throw new Error('Kein Token in Spotify-Embed gefunden'); _spTokenExpiry = (expiryMatch ? parseInt(expiryMatch[1]) : (Date.now() + 55 * 60 * 1000)) - 30000;
_spTokenCache = token;
_spTokenExpiry = (nd?.props?.pageProps?.accessTokenExpirationTimestampMs || (Date.now() + 55 * 60 * 1000)) - 30000;
return _spTokenCache; return _spTokenCache;
} }