fix: regex accessToken directly from embed HTML instead of brittle JSON path
This commit is contained in:
1 parent
60c74a60a2
commit
6c4caebc69
1 file changed
+5
-7
@@ -83,13 +83,11 @@ async function fetchSpotifyToken() {
|
||||
});
|
||||
if (!r.ok) throw new Error(`Spotify-Embed nicht erreichbar (${r.status})`);
|
||||
const html = await r.text();
|
||||
const m = html.match(/<script id="__NEXT_DATA__" type="application\/json">(.+?)<\/script>/s);
|
||||
if (!m) throw new Error('Spotify-Seite nicht parsebar');
|
||||
const nd = JSON.parse(m[1]);
|
||||
const token = nd?.props?.pageProps?.accessToken;
|
||||
if (!token) throw new Error('Kein Token in Spotify-Embed gefunden');
|
||||
_spTokenCache = token;
|
||||
_spTokenExpiry = (nd?.props?.pageProps?.accessTokenExpirationTimestampMs || (Date.now() + 55 * 60 * 1000)) - 30000;
|
||||
const tokenMatch = html.match(/"accessToken"\s*:\s*"([^"]+)"/);
|
||||
if (!tokenMatch) throw new Error('Kein Token in Spotify-Embed gefunden');
|
||||
const expiryMatch = html.match(/"accessTokenExpirationTimestampMs"\s*:\s*(\d+)/);
|
||||
_spTokenCache = tokenMatch[1];
|
||||
_spTokenExpiry = (expiryMatch ? parseInt(expiryMatch[1]) : (Date.now() + 55 * 60 * 1000)) - 30000;
|
||||
return _spTokenCache;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user