mirror of
https://github.com/markuryy/shark.git
synced 2025-12-12 11:41:02 +00:00
feat(dl): add download progress tracking and reporting
This commit is contained in:
@@ -77,9 +77,37 @@ export async function downloadTrack(
|
||||
const totalSize = parseInt(response.headers.get('content-length') || '0');
|
||||
const isCrypted = downloadURL.includes('/mobile/') || downloadURL.includes('/media/');
|
||||
|
||||
// Get the response as array buffer
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
const encryptedData = new Uint8Array(arrayBuffer);
|
||||
// Stream the response with progress tracking
|
||||
const reader = response.body!.getReader();
|
||||
const chunks: Uint8Array[] = [];
|
||||
let downloadedBytes = 0;
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
chunks.push(value);
|
||||
downloadedBytes += value.length;
|
||||
|
||||
// Call progress callback
|
||||
if (onProgress && totalSize > 0) {
|
||||
const percentage = (downloadedBytes / totalSize) * 100;
|
||||
console.log(`[Download Progress] ${downloadedBytes}/${totalSize} bytes (${percentage.toFixed(1)}%)`);
|
||||
onProgress({
|
||||
downloaded: downloadedBytes,
|
||||
total: totalSize,
|
||||
percentage
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Combine chunks into single Uint8Array
|
||||
const encryptedData = new Uint8Array(downloadedBytes);
|
||||
let offset = 0;
|
||||
for (const chunk of chunks) {
|
||||
encryptedData.set(chunk, offset);
|
||||
offset += chunk.length;
|
||||
}
|
||||
|
||||
console.log(`Downloaded ${encryptedData.length} bytes, encrypted: ${isCrypted}`);
|
||||
|
||||
|
||||
@@ -338,7 +338,17 @@ export class DeezerQueueManager {
|
||||
downloadURL,
|
||||
appSettings.musicFolder!,
|
||||
appSettings.deezerFormat,
|
||||
undefined,
|
||||
(progress) => {
|
||||
// Update progress in queue
|
||||
updateQueueItem(item.id, {
|
||||
progress: progress.percentage,
|
||||
currentTrack: {
|
||||
title: track.title,
|
||||
artist: track.artist,
|
||||
progress: progress.percentage
|
||||
}
|
||||
});
|
||||
},
|
||||
0,
|
||||
trackData.SNG_ID
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user