fix(downloads): update downloadTrackWithMetadata function
- Fix reference to enrichTrack - Added detailed JSDoc comments for better documentation - Updated API reference to use MusicAPI.instance for consistency - Improved error handling and metadata enrichment process
This commit is contained in:
parent
a282b37d88
commit
ddc986bc52
1 changed files with 26 additions and 2 deletions
|
|
@ -1013,10 +1013,31 @@ function completeBulkDownload(notifEl, success = true, message = null) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads a track with metadata and optionally lyrics.
|
||||||
|
* @async
|
||||||
|
* @param {Object} track - The track object to download
|
||||||
|
* @param {string} quality - The desired audio quality for download
|
||||||
|
* @param {MusicAPI | LosslessAPI} [api=MusicAPI.instance] - The API instance to use for downloading
|
||||||
|
* @param {Object} [lyricsManager=null] - Optional manager for fetching and processing lyrics
|
||||||
|
* @param {AbortController} [abortController=null] - Optional abort controller for cancelling the download
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
* @throws {Error} If the download fails (except for AbortError)
|
||||||
|
* @description
|
||||||
|
* This function:
|
||||||
|
* - Validates that a track is provided
|
||||||
|
* - Prevents duplicate downloads of the same track
|
||||||
|
* - Enriches track metadata via the API
|
||||||
|
* - Downloads the audio blob with progress tracking
|
||||||
|
* - Organizes the file into subfolders based on the folder template
|
||||||
|
* - Optionally downloads and saves lyrics in LRC format
|
||||||
|
* - Updates the local media folder cache if using LocalMedia download method
|
||||||
|
* - Handles errors gracefully and updates download task status
|
||||||
|
*/
|
||||||
export async function downloadTrackWithMetadata(
|
export async function downloadTrackWithMetadata(
|
||||||
track,
|
track,
|
||||||
quality,
|
quality,
|
||||||
api = MusicAPI.instance.tidalAPI,
|
api = MusicAPI.instance,
|
||||||
lyricsManager = null,
|
lyricsManager = null,
|
||||||
abortController = null
|
abortController = null
|
||||||
) {
|
) {
|
||||||
|
|
@ -1025,13 +1046,16 @@ export async function downloadTrackWithMetadata(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {LosslessAPI} */
|
||||||
|
const tidalAPI = api.tidalAPI || api;
|
||||||
|
|
||||||
const downloadKey = `track-${track.id}`;
|
const downloadKey = `track-${track.id}`;
|
||||||
if (ongoingDownloads.has(downloadKey)) {
|
if (ongoingDownloads.has(downloadKey)) {
|
||||||
showNotification('This track is already being downloaded');
|
showNotification('This track is already being downloaded');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { enrichedTrack } = await api.enrichTrack(track, { downloadQuality: quality });
|
const { enrichedTrack } = await tidalAPI.enrichTrack(track, { downloadQuality: quality });
|
||||||
const filename = buildTrackFilename(enrichedTrack, quality);
|
const filename = buildTrackFilename(enrichedTrack, quality);
|
||||||
|
|
||||||
const controller = abortController || new AbortController();
|
const controller = abortController || new AbortController();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue