feat(dl): online track search and add-to-queue utility

This commit is contained in:
2025-10-02 09:54:05 -04:00
parent 81ef5bac90
commit d1edc8b7f7
6 changed files with 115 additions and 94 deletions

View File

@@ -4,7 +4,8 @@
import SearchResultsTable from '$lib/components/SearchResultsTable.svelte';
import { searchLocalTracks } from '$lib/library/search';
import { searchDeezerTracks } from '$lib/services/deezer/search';
import { downloadTrack } from '$lib/services/deezer/downloader';
import { deezerAPI } from '$lib/services/deezer';
import { addDeezerTrackToQueue } from '$lib/services/deezer/addToQueue';
import { settings, loadSettings } from '$lib/stores/settings';
import { deezerAuth } from '$lib/stores/deezer';
import type { SearchResult, SearchType } from '$lib/types/search';
@@ -69,7 +70,7 @@
return;
}
if (!$deezerAuth.user) {
if (!$deezerAuth.arl || !$deezerAuth.user) {
error = 'Please log in to Deezer first (Services → Deezer)';
return;
}
@@ -80,11 +81,12 @@
}
try {
console.log('Downloading track:', result.trackId);
await downloadTrack(result.trackId);
// TODO: Show success notification
deezerAPI.setArl($deezerAuth.arl);
await addDeezerTrackToQueue(result.trackId);
error = null; // Clear any previous error
} catch (e) {
error = 'Error downloading track: ' + (e as Error).message;
console.error('Queue error:', e);
error = 'Error adding to download queue: ' + (e as Error).message;
}
}
</script>

View File

@@ -3,7 +3,7 @@
import { goto } from '$app/navigation';
import { deezerAuth, loadDeezerAuth, saveArl, saveUser, clearDeezerAuth } from '$lib/stores/deezer';
import { deezerAPI } from '$lib/services/deezer';
import { addToQueue } from '$lib/stores/downloadQueue';
import { addDeezerTrackToQueue } from '$lib/services/deezer/addToQueue';
import { settings } from '$lib/stores/settings';
let arlInput = $state('');
@@ -129,35 +129,8 @@
queueError = '';
try {
// Build track object
const track = {
id: trackInfo.SNG_ID,
title: trackInfo.SNG_TITLE,
artist: trackInfo.ART_NAME,
artistId: trackInfo.ART_ID,
artists: [trackInfo.ART_NAME],
album: trackInfo.ALB_TITLE,
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,
explicit: trackInfo.EXPLICIT_LYRICS === 1,
md5Origin: trackInfo.MD5_ORIGIN,
mediaVersion: trackInfo.MEDIA_VERSION,
trackToken: trackInfo.TRACK_TOKEN
};
// Add to queue
await addToQueue({
source: 'deezer',
type: 'track',
title: track.title,
artist: track.artist,
totalTracks: 1,
downloadObject: track
});
// Use shared utility to add track to queue
await addDeezerTrackToQueue(trackIdInput);
queueStatus = '✓ Added to download queue!';