improve qobuz functionality
This commit is contained in:
parent
d50f4f7223
commit
0213132606
6 changed files with 234 additions and 62 deletions
|
|
@ -173,4 +173,10 @@ export class MusicAPI {
|
||||||
get settings() {
|
get settings() {
|
||||||
return this._settings;
|
return this._settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract stream URL from manifest (Tidal only)
|
||||||
|
extractStreamUrlFromManifest(manifest) {
|
||||||
|
// This is only available for Tidal
|
||||||
|
return this.tidalAPI.extractStreamUrlFromManifest(manifest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
50
js/player.js
50
js/player.js
|
|
@ -486,27 +486,43 @@ export class Player {
|
||||||
}
|
}
|
||||||
await this.audio.play();
|
await this.audio.play();
|
||||||
} else {
|
} else {
|
||||||
// Get track data for ReplayGain (should be cached by API)
|
const isQobuz = String(track.id).startsWith('q:');
|
||||||
const trackData = await this.api.getTrack(track.id, this.quality);
|
|
||||||
|
|
||||||
if (trackData && trackData.info) {
|
if (isQobuz) {
|
||||||
this.currentRgValues = {
|
// Qobuz: skip getTrack call, directly fetch stream URL
|
||||||
trackReplayGain: trackData.info.trackReplayGain,
|
|
||||||
trackPeakAmplitude: trackData.info.trackPeakAmplitude,
|
|
||||||
albumReplayGain: trackData.info.albumReplayGain,
|
|
||||||
albumPeakAmplitude: trackData.info.albumPeakAmplitude,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
this.currentRgValues = null;
|
this.currentRgValues = null;
|
||||||
}
|
this.applyReplayGain();
|
||||||
this.applyReplayGain();
|
|
||||||
|
|
||||||
if (this.preloadCache.has(track.id)) {
|
if (this.preloadCache.has(track.id)) {
|
||||||
streamUrl = this.preloadCache.get(track.id);
|
streamUrl = this.preloadCache.get(track.id);
|
||||||
} else if (trackData.originalTrackUrl) {
|
} else {
|
||||||
streamUrl = trackData.originalTrackUrl;
|
streamUrl = await this.api.getStreamUrl(track.id, this.quality);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
streamUrl = this.api.extractStreamUrlFromManifest(trackData.info.manifest);
|
// Tidal: Get track data for ReplayGain (should be cached by API)
|
||||||
|
const trackData = await this.api.getTrack(track.id, this.quality);
|
||||||
|
|
||||||
|
if (trackData && trackData.info) {
|
||||||
|
this.currentRgValues = {
|
||||||
|
trackReplayGain: trackData.info.trackReplayGain,
|
||||||
|
trackPeakAmplitude: trackData.info.trackPeakAmplitude,
|
||||||
|
albumReplayGain: trackData.info.albumReplayGain,
|
||||||
|
albumPeakAmplitude: trackData.info.albumPeakAmplitude,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.currentRgValues = null;
|
||||||
|
}
|
||||||
|
this.applyReplayGain();
|
||||||
|
|
||||||
|
if (this.preloadCache.has(track.id)) {
|
||||||
|
streamUrl = this.preloadCache.get(track.id);
|
||||||
|
} else if (trackData.originalTrackUrl) {
|
||||||
|
streamUrl = trackData.originalTrackUrl;
|
||||||
|
} else if (trackData.info?.manifest) {
|
||||||
|
streamUrl = this.api.extractStreamUrlFromManifest(trackData.info.manifest);
|
||||||
|
} else {
|
||||||
|
streamUrl = await this.api.getStreamUrl(track.id, this.quality);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle playback
|
// Handle playback
|
||||||
|
|
|
||||||
216
js/qobuz-api.js
216
js/qobuz-api.js
|
|
@ -30,7 +30,11 @@ export class QobuzAPI {
|
||||||
// Search tracks
|
// Search tracks
|
||||||
async searchTracks(query, options = {}) {
|
async searchTracks(query, options = {}) {
|
||||||
try {
|
try {
|
||||||
const data = await this.fetchWithRetry(`/get-music?q=${encodeURIComponent(query)}`);
|
const offset = options.offset || 0;
|
||||||
|
const limit = options.limit || 10;
|
||||||
|
const data = await this.fetchWithRetry(
|
||||||
|
`/get-music?q=${encodeURIComponent(query)}&offset=${offset}&limit=${limit}`
|
||||||
|
);
|
||||||
|
|
||||||
if (!data.success || !data.data) {
|
if (!data.success || !data.data) {
|
||||||
return { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 };
|
return { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 };
|
||||||
|
|
@ -55,7 +59,11 @@ export class QobuzAPI {
|
||||||
// Search albums
|
// Search albums
|
||||||
async searchAlbums(query, options = {}) {
|
async searchAlbums(query, options = {}) {
|
||||||
try {
|
try {
|
||||||
const data = await this.fetchWithRetry(`/get-music?q=${encodeURIComponent(query)}`);
|
const offset = options.offset || 0;
|
||||||
|
const limit = options.limit || 10;
|
||||||
|
const data = await this.fetchWithRetry(
|
||||||
|
`/get-music?q=${encodeURIComponent(query)}&offset=${offset}&limit=${limit}`
|
||||||
|
);
|
||||||
|
|
||||||
if (!data.success || !data.data) {
|
if (!data.success || !data.data) {
|
||||||
return { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 };
|
return { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 };
|
||||||
|
|
@ -80,7 +88,11 @@ export class QobuzAPI {
|
||||||
// Search artists
|
// Search artists
|
||||||
async searchArtists(query, options = {}) {
|
async searchArtists(query, options = {}) {
|
||||||
try {
|
try {
|
||||||
const data = await this.fetchWithRetry(`/get-music?q=${encodeURIComponent(query)}`);
|
const offset = options.offset || 0;
|
||||||
|
const limit = options.limit || 10;
|
||||||
|
const data = await this.fetchWithRetry(
|
||||||
|
`/get-music?q=${encodeURIComponent(query)}&offset=${offset}&limit=${limit}`
|
||||||
|
);
|
||||||
|
|
||||||
if (!data.success || !data.data) {
|
if (!data.success || !data.data) {
|
||||||
return { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 };
|
return { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 };
|
||||||
|
|
@ -104,25 +116,10 @@ export class QobuzAPI {
|
||||||
|
|
||||||
// Get track details
|
// Get track details
|
||||||
async getTrack(id) {
|
async getTrack(id) {
|
||||||
try {
|
// Qobuz doesn't have a direct track endpoint
|
||||||
// For Qobuz, we'll need to search or get from album
|
// Track metadata comes from search/album endpoints
|
||||||
// Since the API might not have a direct track endpoint
|
// For playback, use getStreamUrl directly
|
||||||
const data = await this.fetchWithRetry(`/get-music?q=${encodeURIComponent(id)}`);
|
throw new Error('Qobuz getTrack not implemented - use getStreamUrl for playback');
|
||||||
|
|
||||||
if (!data.success || !data.data) {
|
|
||||||
throw new Error('Track not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
const track = data.data.tracks?.items?.find((t) => t.id === id || t.isrc === id);
|
|
||||||
if (!track) {
|
|
||||||
throw new Error('Track not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.transformTrack(track);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Qobuz getTrack failed:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get album details
|
// Get album details
|
||||||
|
|
@ -135,7 +132,7 @@ export class QobuzAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
const album = this.transformAlbum(data.data);
|
const album = this.transformAlbum(data.data);
|
||||||
const tracks = (data.data.tracks || []).map((track) => this.transformTrack(track, data.data));
|
const tracks = (data.data.tracks?.items || []).map((track) => this.transformTrack(track, data.data));
|
||||||
|
|
||||||
return { album, tracks };
|
return { album, tracks };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -147,16 +144,42 @@ export class QobuzAPI {
|
||||||
// Get artist details
|
// Get artist details
|
||||||
async getArtist(id) {
|
async getArtist(id) {
|
||||||
try {
|
try {
|
||||||
const data = await this.fetchWithRetry(`/get-artist?artist_id=${encodeURIComponent(id)}`);
|
const artistData = await this.fetchWithRetry(`/get-artist?artist_id=${encodeURIComponent(id)}`);
|
||||||
|
|
||||||
if (!data.success || !data.data) {
|
if (!artistData.success || !artistData.data) {
|
||||||
throw new Error('Artist not found');
|
throw new Error('Artist not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const artist = this.transformArtist(data.data);
|
// Qobuz get-artist returns { artist: {...} } nested structure
|
||||||
const albums = (data.data.albums || []).map((album) => this.transformAlbum(album));
|
const artistInfo = artistData.data.artist || artistData.data;
|
||||||
|
if (!artistInfo) {
|
||||||
|
throw new Error('Artist info not found in response');
|
||||||
|
}
|
||||||
|
const artist = this.transformArtist(artistInfo);
|
||||||
|
|
||||||
return { ...artist, albums, eps: [], tracks: [] };
|
// Get albums from the releases section
|
||||||
|
let albums = [];
|
||||||
|
let eps = [];
|
||||||
|
if (Array.isArray(artistData.data.releases)) {
|
||||||
|
// Find album releases
|
||||||
|
const albumReleases = artistData.data.releases.find((r) => r.type === 'album');
|
||||||
|
if (albumReleases?.items) {
|
||||||
|
albums = albumReleases.items.map((album) => this.transformAlbum(album));
|
||||||
|
}
|
||||||
|
// Find EP/single releases
|
||||||
|
const epReleases = artistData.data.releases.find((r) => r.type === 'epSingle');
|
||||||
|
if (epReleases?.items) {
|
||||||
|
eps = epReleases.items.map((album) => this.transformAlbum(album));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get top tracks
|
||||||
|
let tracks = [];
|
||||||
|
if (Array.isArray(artistData.data.top_tracks)) {
|
||||||
|
tracks = artistData.data.top_tracks.map((track) => this.transformTrack(track));
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...artist, albums, eps, tracks };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Qobuz getArtist failed:', error);
|
console.error('Qobuz getArtist failed:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|
@ -165,12 +188,16 @@ export class QobuzAPI {
|
||||||
|
|
||||||
// Transform Qobuz track to Tidal-like format
|
// Transform Qobuz track to Tidal-like format
|
||||||
transformTrack(track, albumData = null) {
|
transformTrack(track, albumData = null) {
|
||||||
|
// Qobuz uses 'performer' for the main artist, not 'artist'
|
||||||
|
const mainArtist = track.performer || track.artist;
|
||||||
|
const artistsList = track.artists || (mainArtist ? [mainArtist] : []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: `q:${track.id}`,
|
id: `q:${track.id}`,
|
||||||
title: track.title,
|
title: track.title,
|
||||||
duration: track.duration,
|
duration: track.duration,
|
||||||
artist: track.artist ? this.transformArtist(track.artist) : null,
|
artist: mainArtist ? this.transformArtist(mainArtist) : null,
|
||||||
artists: track.artists ? track.artists.map((a) => this.transformArtist(a)) : [],
|
artists: artistsList.map((a) => this.transformArtist(a)),
|
||||||
album: albumData ? this.transformAlbum(albumData) : track.album ? this.transformAlbum(track.album) : null,
|
album: albumData ? this.transformAlbum(albumData) : track.album ? this.transformAlbum(track.album) : null,
|
||||||
audioQuality: this.mapQuality(track.streaming_quality),
|
audioQuality: this.mapQuality(track.streaming_quality),
|
||||||
explicit: track.parental_warning || false,
|
explicit: track.parental_warning || false,
|
||||||
|
|
@ -184,11 +211,17 @@ export class QobuzAPI {
|
||||||
|
|
||||||
// Transform Qobuz album to Tidal-like format
|
// Transform Qobuz album to Tidal-like format
|
||||||
transformAlbum(album) {
|
transformAlbum(album) {
|
||||||
|
// Qobuz albums have artist (single) or artists (array)
|
||||||
|
const mainArtist = album.artist || album.artists?.[0];
|
||||||
return {
|
return {
|
||||||
id: `q:${album.id}`,
|
id: `q:${album.id}`,
|
||||||
title: album.title,
|
title: album.title,
|
||||||
artist: album.artist ? this.transformArtist(album.artist) : null,
|
artist: mainArtist ? this.transformArtist(mainArtist) : null,
|
||||||
artists: album.artists ? album.artists.map((a) => this.transformArtist(a)) : [],
|
artists: album.artists
|
||||||
|
? album.artists.map((a) => this.transformArtist(a))
|
||||||
|
: mainArtist
|
||||||
|
? [this.transformArtist(mainArtist)]
|
||||||
|
: [],
|
||||||
numberOfTracks: album.tracks_count || 0,
|
numberOfTracks: album.tracks_count || 0,
|
||||||
releaseDate: album.release_date_original || album.release_date,
|
releaseDate: album.release_date_original || album.release_date,
|
||||||
cover: album.image?.large || album.image?.medium || album.image?.small,
|
cover: album.image?.large || album.image?.medium || album.image?.small,
|
||||||
|
|
@ -201,10 +234,30 @@ export class QobuzAPI {
|
||||||
|
|
||||||
// Transform Qobuz artist to Tidal-like format
|
// Transform Qobuz artist to Tidal-like format
|
||||||
transformArtist(artist) {
|
transformArtist(artist) {
|
||||||
|
if (!artist) {
|
||||||
|
return {
|
||||||
|
id: 'q:unknown',
|
||||||
|
name: 'Unknown Artist',
|
||||||
|
picture: null,
|
||||||
|
provider: 'qobuz',
|
||||||
|
originalId: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Handle different name structures: string or { display: string }
|
||||||
|
const name = typeof artist.name === 'string' ? artist.name : artist.name?.display || 'Unknown Artist';
|
||||||
|
// Handle different image structures: image object or picture string or images.portrait
|
||||||
|
const picture =
|
||||||
|
artist.image?.large ||
|
||||||
|
artist.image?.medium ||
|
||||||
|
artist.image?.small ||
|
||||||
|
artist.picture ||
|
||||||
|
(artist.images?.portrait
|
||||||
|
? `https://static.qobuz.com/images/artists/covers/large/${artist.images.portrait.hash}.${artist.images.portrait.format}`
|
||||||
|
: null);
|
||||||
return {
|
return {
|
||||||
id: `q:${artist.id}`,
|
id: `q:${artist.id}`,
|
||||||
name: artist.name,
|
name: name,
|
||||||
picture: artist.image?.large || artist.image?.medium || artist.image?.small,
|
picture: picture,
|
||||||
provider: 'qobuz',
|
provider: 'qobuz',
|
||||||
originalId: artist.id,
|
originalId: artist.id,
|
||||||
};
|
};
|
||||||
|
|
@ -234,11 +287,37 @@ export class QobuzAPI {
|
||||||
return coverId;
|
return coverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get artist picture URL
|
||||||
|
getArtistPictureUrl(pictureUrl, size = '320') {
|
||||||
|
if (!pictureUrl) {
|
||||||
|
return `https://picsum.photos/seed/${Math.random()}/${size}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Qobuz picture URLs are usually full URLs
|
||||||
|
if (typeof pictureUrl === 'string' && pictureUrl.startsWith('http')) {
|
||||||
|
return pictureUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pictureUrl;
|
||||||
|
}
|
||||||
|
|
||||||
// Get stream URL for a track
|
// Get stream URL for a track
|
||||||
async getStreamUrl(trackId) {
|
async getStreamUrl(trackId, quality = '27') {
|
||||||
try {
|
try {
|
||||||
const cleanId = trackId.replace(/^q:/, '');
|
const cleanId = trackId.replace(/^q:/, '');
|
||||||
const data = await this.fetchWithRetry(`/download-music?track_id=${encodeURIComponent(cleanId)}`);
|
// Map Tidal quality format to Qobuz quality values
|
||||||
|
// Qobuz: 27=MP3 320kbps, 7=FLAC lossless, 6=HiRes 96/24, 5=HiRes 192/24
|
||||||
|
const qualityMap = {
|
||||||
|
LOW: '27',
|
||||||
|
HIGH: '27',
|
||||||
|
LOSSLESS: '7',
|
||||||
|
HI_RES: '6',
|
||||||
|
HI_RES_LOSSLESS: '5',
|
||||||
|
};
|
||||||
|
const qobuzQuality = qualityMap[quality] || quality || '27';
|
||||||
|
const data = await this.fetchWithRetry(
|
||||||
|
`/download-music?track_id=${encodeURIComponent(cleanId)}&quality=${qobuzQuality}`
|
||||||
|
);
|
||||||
|
|
||||||
if (!data.success || !data.data?.url) {
|
if (!data.success || !data.data?.url) {
|
||||||
throw new Error('Stream URL not available');
|
throw new Error('Stream URL not available');
|
||||||
|
|
@ -250,6 +329,71 @@ export class QobuzAPI {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unified search - search all types at once
|
||||||
|
async search(query, options = {}) {
|
||||||
|
const offset = options.offset || 0;
|
||||||
|
const limit = options.limit || 10;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await this.fetchWithRetry(
|
||||||
|
`/get-music?q=${encodeURIComponent(query)}&offset=${offset}&limit=${limit}`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!data.success || !data.data) {
|
||||||
|
return {
|
||||||
|
tracks: { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 },
|
||||||
|
albums: { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 },
|
||||||
|
artists: { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const tracks = (data.data.tracks?.items || []).map((track) => this.transformTrack(track));
|
||||||
|
const albums = (data.data.albums?.items || []).map((album) => this.transformAlbum(album));
|
||||||
|
const artists = (data.data.artists?.items || []).map((artist) => this.transformArtist(artist));
|
||||||
|
|
||||||
|
return {
|
||||||
|
tracks: {
|
||||||
|
items: tracks,
|
||||||
|
limit: data.data.tracks?.limit || tracks.length,
|
||||||
|
offset: data.data.tracks?.offset || 0,
|
||||||
|
totalNumberOfItems: data.data.tracks?.total || tracks.length,
|
||||||
|
},
|
||||||
|
albums: {
|
||||||
|
items: albums,
|
||||||
|
limit: data.data.albums?.limit || albums.length,
|
||||||
|
offset: data.data.albums?.offset || 0,
|
||||||
|
totalNumberOfItems: data.data.albums?.total || albums.length,
|
||||||
|
},
|
||||||
|
artists: {
|
||||||
|
items: artists,
|
||||||
|
limit: data.data.artists?.limit || artists.length,
|
||||||
|
offset: data.data.artists?.offset || 0,
|
||||||
|
totalNumberOfItems: data.data.artists?.total || artists.length,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
if (error.name === 'AbortError') throw error;
|
||||||
|
console.error('Qobuz search failed:', error);
|
||||||
|
return {
|
||||||
|
tracks: { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 },
|
||||||
|
albums: { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 },
|
||||||
|
artists: { items: [], limit: 0, offset: 0, totalNumberOfItems: 0 },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get next page helper
|
||||||
|
getNextPage(currentOffset, limit, total) {
|
||||||
|
const nextOffset = currentOffset + limit;
|
||||||
|
return nextOffset < total ? nextOffset : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get previous page helper
|
||||||
|
getPreviousPage(currentOffset, limit) {
|
||||||
|
const prevOffset = currentOffset - limit;
|
||||||
|
return prevOffset >= 0 ? prevOffset : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const qobuzAPI = new QobuzAPI();
|
export const qobuzAPI = new QobuzAPI();
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,7 @@ export async function renderTrackerArtistPage(sheetId, container) {
|
||||||
Object.values(era.data).forEach((songs) => {
|
Object.values(era.data).forEach((songs) => {
|
||||||
if (songs && songs.length) {
|
if (songs && songs.length) {
|
||||||
songs.forEach((song, index) => {
|
songs.forEach((song, index) => {
|
||||||
if (song.name.toLowerCase().includes(query)) {
|
if (song.name?.toLowerCase().includes(query)) {
|
||||||
matches.push({ song, era, index });
|
matches.push({ song, era, index });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -734,6 +734,8 @@ export async function renderUnreleasedPage(container) {
|
||||||
const sheetId = getSheetId(artist.url);
|
const sheetId = getSheetId(artist.url);
|
||||||
if (!sheetId) return;
|
if (!sheetId) return;
|
||||||
|
|
||||||
|
if (!artist.name) return;
|
||||||
|
|
||||||
const artistCard = document.createElement('div');
|
const artistCard = document.createElement('div');
|
||||||
artistCard.className = 'card';
|
artistCard.className = 'card';
|
||||||
artistCard.style.cursor = 'pointer';
|
artistCard.style.cursor = 'pointer';
|
||||||
|
|
@ -953,12 +955,15 @@ export async function initTracker(player) {
|
||||||
// Helper function to find a tracker artist by name (for use in normal artist pages)
|
// Helper function to find a tracker artist by name (for use in normal artist pages)
|
||||||
export function findTrackerArtistByName(artistName) {
|
export function findTrackerArtistByName(artistName) {
|
||||||
// First try exact match
|
// First try exact match
|
||||||
let match = artistsData.find((a) => a.name.toLowerCase() === artistName.toLowerCase());
|
if (!artistName) return null;
|
||||||
|
|
||||||
|
let match = artistsData.find((a) => a.name?.toLowerCase() === artistName.toLowerCase());
|
||||||
if (match) return match;
|
if (match) return match;
|
||||||
|
|
||||||
// Try fuzzy match (remove special chars and spaces)
|
// Try fuzzy match (remove special chars and spaces)
|
||||||
const normalized = artistName.toLowerCase().replace(/[^a-z0-9]/g, '');
|
const normalized = artistName.toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||||
match = artistsData.find((a) => {
|
match = artistsData.find((a) => {
|
||||||
|
if (!a.name) return false;
|
||||||
const aNormalized = a.name.toLowerCase().replace(/[^a-z0-9]/g, '');
|
const aNormalized = a.name.toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||||
return aNormalized === normalized || aNormalized.includes(normalized) || normalized.includes(aNormalized);
|
return aNormalized === normalized || aNormalized.includes(normalized) || normalized.includes(aNormalized);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,20 @@
|
||||||
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
import { getArtist } from '@/lib/qobuz-dl-server';
|
import { getArtist } from '@/lib/qobuz-dl-server';
|
||||||
import z from 'zod';
|
import z from 'zod';
|
||||||
|
|
||||||
const artistReleasesParamsSchema = z.object({
|
const artistParamsSchema = z.object({
|
||||||
artist_id: z.string().min(1, 'ID is required'),
|
artist_id: z.string().min(1, 'ID is required'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: NextRequest) {
|
||||||
const country = request.headers.get('Token-Country');
|
const country = request.headers.get('Token-Country');
|
||||||
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
||||||
try {
|
try {
|
||||||
const { artist_id } = artistReleasesParamsSchema.parse(params);
|
const { artist_id } = artistParamsSchema.parse(params);
|
||||||
const artist = await getArtist(artist_id, country ? { country } : {});
|
const data = await getArtist(artist_id, country ? { country } : {});
|
||||||
return new Response(JSON.stringify({ success: true, data: { artist } }), { status: 200 });
|
return new NextResponse(JSON.stringify({ success: true, data }), { status: 200 });
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return new Response(
|
return new NextResponse(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
success: false,
|
success: false,
|
||||||
error: error?.errors || error.message || 'An error occurred parsing the request.',
|
error: error?.errors || error.message || 'An error occurred parsing the request.',
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ const releasesParamsSchema = z.object({
|
||||||
artist_id: z.string().min(1, 'ID is required'),
|
artist_id: z.string().min(1, 'ID is required'),
|
||||||
release_type: z.enum(['album', 'live', 'compilation', 'epSingle', 'download']).default('album'),
|
release_type: z.enum(['album', 'live', 'compilation', 'epSingle', 'download']).default('album'),
|
||||||
track_size: z.number().positive().default(1000),
|
track_size: z.number().positive().default(1000),
|
||||||
offset: z.preprocess((a) => parseInt(a as string), z.number().positive().default(0)),
|
offset: z.preprocess((a) => parseInt(a as string), z.number().nonnegative().default(0)),
|
||||||
limit: z.preprocess((a) => parseInt(a as string), z.number().positive().default(10)),
|
limit: z.preprocess((a) => parseInt(a as string), z.number().positive().default(10)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue