File size: 1,285 Bytes
22a2b25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
  }
}