UNPKG

@manhgdev/spotifyweb

Version:

Spotify library in typescript without using the Spotify Web API. No authentication required with automatic internal token generation.

27 lines (26 loc) 985 B
import { spCurlToken } from './spCurlToken.js'; import { spClientToken } from './spClientToken.js'; export async function spTokenManager(cookie = "") { try { // Thử sử dụng spCurlToken trước const curlData = await spCurlToken(cookie); if (!curlData) { throw new Error('spCurlToken returned null or undefined'); } return curlData; } catch (curlError) { console.warn('spCurlToken failed:', curlError.message); try { // Nếu spCurlToken lỗi, fallback sang spClientToken const clientData = await spClientToken(); return clientData; } catch (clientError) { // Nếu cả 2 đều lỗi, throw error throw new Error(`Both Spotify token methods failed. spCurlToken: ${curlError.message}, spClientToken: ${clientError.message}`); } } } // Example usage // spTokenManager().then(console.log).catch(console.error);