Spaces:
Running
Running
Download services/spotifyLyricsService.js from veltrixcode/jsondb: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/veltrixcode/jsondb/resolve/main/services/spotifyLyricsService.js
- Command line
-
hf download hf://spaces/veltrixcode/jsondb/services/spotifyLyricsService.js
-
curl -L -o spotifyLyricsService.js https://huggingface.co/spaces/veltrixcode/jsondb/resolve/main/services/spotifyLyricsService.js
1.29 kB
| import axios from 'axios'; | |
| import { getBrowserCredentials } from './browserAuthService.js'; | |
| export async function getLyrics(trackId, imageUri = '') { | |
| try { | |
| const { authorization, clientToken } = await getBrowserCredentials(); | |
| // Construct the endpoint path depending on whether imageUri is provided | |
| let url = `https://spclient.wg.spotify.com/color-lyrics/v2/track/${trackId}`; | |
| if (imageUri) { | |
| url += `/image/${encodeURIComponent(imageUri)}`; | |
| } | |
| url += '?format=json&vocalRemoval=false&market=from_token'; | |
| const response = await axios.get(url, { | |
| headers: { | |
| 'Accept': 'application/json', | |
| 'Accept-Language': 'en-GB', | |
| 'App-Platform': 'WebPlayer', | |
| 'Authorization': `Bearer ${authorization}`, | |
| 'Client-Token': clientToken, | |
| 'Origin': 'https://open.spotify.com', | |
| 'Referer': 'https://open.spotify.com/', | |
| 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36', | |
| 'Spotify-App-Version': '1.2.95.154.g2abc6fb9' | |
| } | |
| }); | |
| return response.data; | |
| } catch (error) { | |
| console.error(`Lyrics request error for track ${trackId}:`, error.response?.data || error.message); | |
| return null; | |
| } | |
| } | |