mirror of
https://github.com/markuryy/shark.git
synced 2025-12-15 04:41:01 +00:00
feat(dl): online track search and add-to-queue utility
This commit is contained in:
51
src/lib/services/deezer/addToQueue.ts
Normal file
51
src/lib/services/deezer/addToQueue.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Utility to add a Deezer track to the download queue
|
||||
* Used by both search results and services/deezer pages
|
||||
*/
|
||||
|
||||
import { deezerAPI } from '$lib/services/deezer';
|
||||
import { addToQueue } from '$lib/stores/downloadQueue';
|
||||
|
||||
/**
|
||||
* Fetch track metadata and add to download queue
|
||||
* @param trackId - Deezer track ID
|
||||
* @returns Promise that resolves when track is added to queue
|
||||
*/
|
||||
export async function addDeezerTrackToQueue(trackId: string): Promise<void> {
|
||||
// Fetch full track data from GW API
|
||||
const trackInfo = await deezerAPI.getTrack(trackId);
|
||||
|
||||
if (!trackInfo || !trackInfo.SNG_ID) {
|
||||
throw new Error('Track not found or invalid track ID');
|
||||
}
|
||||
|
||||
// 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
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user