mirror of
https://github.com/markuryy/shark.git
synced 2025-12-15 04:41:01 +00:00
feat(dz): add playlist download, existence check, and improved queue handling
Add ability to download entire playlists as M3U8 files, with UI integration and per-track download actions. Implement track existence checking to avoid duplicate downloads, respecting the overwrite setting. Improve queue manager to sync downloaded tracks to the library incrementally. Refactor playlist parsing and metadata reading to use the Rust backend for better performance and accuracy. Update UI to reflect track existence and download status in playlist views. BREAKING CHANGE: Deezer playlist and track download logic now relies on Rust backend for metadata and new existence checking; some APIs and internal behaviors have changed.
This commit is contained in:
@@ -5,13 +5,24 @@
|
||||
|
||||
import { deezerAPI } from '$lib/services/deezer';
|
||||
import { addToQueue } from '$lib/stores/downloadQueue';
|
||||
import { settings } from '$lib/stores/settings';
|
||||
import { deezerAuth } from '$lib/stores/deezer';
|
||||
import { trackExists } from './downloader';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
/**
|
||||
* Fetch track metadata and add to download queue
|
||||
* Respects the overwrite setting - skips tracks that already exist if overwrite is false
|
||||
* @param trackId - Deezer track ID
|
||||
* @returns Promise that resolves when track is added to queue
|
||||
* @returns Promise that resolves when track is added to queue (or skipped message)
|
||||
*/
|
||||
export async function addDeezerTrackToQueue(trackId: string): Promise<void> {
|
||||
export async function addDeezerTrackToQueue(trackId: string): Promise<{ added: boolean; reason?: string }> {
|
||||
// Ensure ARL is set for authentication
|
||||
const authState = get(deezerAuth);
|
||||
if (authState.arl) {
|
||||
deezerAPI.setArl(authState.arl);
|
||||
}
|
||||
|
||||
// Fetch full track data from GW API
|
||||
const trackInfo = await deezerAPI.getTrack(trackId);
|
||||
|
||||
@@ -66,9 +77,9 @@ export async function addDeezerTrackToQueue(trackId: string): Promise<void> {
|
||||
albumId: trackInfo.ALB_ID,
|
||||
albumArtist: trackInfo.ART_NAME,
|
||||
albumArtistId: trackInfo.ART_ID,
|
||||
trackNumber: trackInfo.TRACK_NUMBER || 1,
|
||||
discNumber: trackInfo.DISK_NUMBER || 1,
|
||||
duration: trackInfo.DURATION,
|
||||
trackNumber: typeof trackInfo.TRACK_NUMBER === 'number' ? trackInfo.TRACK_NUMBER : parseInt(trackInfo.TRACK_NUMBER, 10),
|
||||
discNumber: typeof trackInfo.DISK_NUMBER === 'number' ? trackInfo.DISK_NUMBER : parseInt(trackInfo.DISK_NUMBER, 10),
|
||||
duration: typeof trackInfo.DURATION === 'number' ? trackInfo.DURATION : parseInt(trackInfo.DURATION, 10),
|
||||
explicit: trackInfo.EXPLICIT_LYRICS === 1,
|
||||
md5Origin: trackInfo.MD5_ORIGIN,
|
||||
mediaVersion: trackInfo.MEDIA_VERSION,
|
||||
@@ -84,6 +95,18 @@ export async function addDeezerTrackToQueue(trackId: string): Promise<void> {
|
||||
copyright: trackInfo.COPYRIGHT
|
||||
};
|
||||
|
||||
// Check if we should skip this track (if it exists and overwrite is false)
|
||||
const appSettings = get(settings);
|
||||
|
||||
if (!appSettings.deezerOverwrite && appSettings.musicFolder) {
|
||||
const exists = await trackExists(track, appSettings.musicFolder, appSettings.deezerFormat);
|
||||
|
||||
if (exists) {
|
||||
console.log(`[AddToQueue] Skipping "${track.title}" - already exists`);
|
||||
return { added: false, reason: 'already_exists' };
|
||||
}
|
||||
}
|
||||
|
||||
// Add to queue (queue manager runs continuously in background)
|
||||
await addToQueue({
|
||||
source: 'deezer',
|
||||
@@ -93,4 +116,6 @@ export async function addDeezerTrackToQueue(trackId: string): Promise<void> {
|
||||
totalTracks: 1,
|
||||
downloadObject: track
|
||||
});
|
||||
|
||||
return { added: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user