feat(crypto): track download handling

This commit is contained in:
2025-09-30 22:50:59 -04:00
parent 4ebb77f341
commit b57164a4f7
3 changed files with 55 additions and 21 deletions

View File

@@ -273,12 +273,17 @@ export class DeezerAPI {
// Get track download URL
async getTrackDownloadUrl(trackToken: string, format: string, licenseToken: string): Promise<string | null> {
console.log('[DEBUG] Getting track download URL...', { trackToken, format, licenseToken });
try {
const cookieHeader = this.getCookieHeader();
console.log('[DEBUG] Sending request to media.deezer.com with cookies:', cookieHeader);
const response = await fetch('https://media.deezer.com/v1/get_url', {
method: 'POST',
headers: {
...this.httpHeaders,
'Cookie': this.arl ? `arl=${this.arl}` : ''
'Cookie': cookieHeader
},
body: JSON.stringify({
license_token: licenseToken,
@@ -287,22 +292,33 @@ export class DeezerAPI {
formats: [{ cipher: 'BF_CBC_STRIPE', format }]
}],
track_tokens: [trackToken]
})
}),
connectTimeout: 30000
});
console.log('[DEBUG] Download URL response status:', response.status);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
console.log('[DEBUG] Download URL response:', result);
if (result.data && result.data.length > 0) {
const trackData = result.data[0];
if (trackData.media && trackData.media.length > 0) {
return trackData.media[0].sources[0].url;
const url = trackData.media[0].sources[0].url;
console.log('[DEBUG] Got download URL:', url);
return url;
}
}
console.error('[ERROR] No download URL in response:', result);
return null;
} catch (error) {
console.error('Error getting track URL:', error);
return null;
console.error('[ERROR] Failed to get track download URL:', error);
throw error; // Re-throw to let caller handle it
}
}
}