fix: Robust Deezer URL generation with direct track links and sanitized search paths to prevent HTTP_NOT_FOUND

This commit is contained in:
Jannik committed 2026-09-13 12:29:50 +02:00
1 parent fc1adda97d
commit 867cc191cd
5 files changed
+59 -9

No files matched your search

+13
View File
@@ -122,6 +122,8 @@ router.get('/', async (req, res) => {
is_corrected: !!local.is_corrected,
cover_url: local.cover_url || null,
preview_url: local.preview_url || null,
deezer_id: local.deezer_id || null,
deezer_link: local.deezer_link || (local.deezer_id ? `https://www.deezer.com/track/${local.deezer_id}` : null),
duration_sec: local.duration_sec || 210,
energy: local.energy || est.energy,
danceability: local.danceability || est.danceability,
@@ -193,6 +195,8 @@ router.get('/', async (req, res) => {
// 4. Query Deezer for cover, duration, preview, and genre fallback
let durationSec = 210;
let previewUrl = null;
let deezerLink = null;
let deezerId = null;
try {
const deezerRes = await axios.get(`https://api.deezer.com/search?q=${encodeURIComponent(artist + ' ' + track)}&limit=1`, {
timeout: 3000
@@ -208,6 +212,13 @@ router.get('/', async (req, res) => {
if (dTrack.preview) {
previewUrl = dTrack.preview;
}
if (dTrack.link) {
deezerLink = dTrack.link;
}
if (dTrack.id) {
deezerId = dTrack.id;
if (!deezerLink) deezerLink = `https://www.deezer.com/track/${dTrack.id}`;
}
}
} catch (e) {
// ignore
@@ -250,6 +261,8 @@ router.get('/', async (req, res) => {
cover_url: coverUrl,
preview_url: previewUrl,
duration_sec: durationSec,
deezer_id: deezerId,
deezer_link: deezerLink,
energy: audioAttrs.energy,
danceability: audioAttrs.danceability,
happiness: audioAttrs.happiness,
+6 -1
View File
@@ -35,7 +35,8 @@ router.get('/', async (req, res) => {
cover_url: item.album && item.album.cover_medium ? item.album.cover_medium : (item.album ? item.album.cover : null),
preview_url: item.preview || null,
duration_sec: item.duration || 210,
deezer_id: item.id
deezer_id: item.id,
deezer_link: item.link || (item.id ? `https://www.deezer.com/track/${item.id}` : null)
}));
}
} catch (e) {
@@ -63,6 +64,8 @@ router.get('/', async (req, res) => {
energy: lt.energy,
danceability: lt.danceability,
happiness: lt.happiness,
deezer_id: lt.deezer_id || null,
deezer_link: lt.deezer_link || (lt.deezer_id ? `https://www.deezer.com/track/${lt.deezer_id}` : null),
is_local: true,
is_corrected: lt.is_corrected
});
@@ -81,6 +84,8 @@ router.get('/', async (req, res) => {
cover_url: ot.cover_url,
preview_url: ot.preview_url,
duration_sec: ot.duration_sec,
deezer_id: ot.deezer_id,
deezer_link: ot.deezer_link,
camelot_key: existingLocal ? existingLocal.camelot_key : null,
bpm: existingLocal ? existingLocal.bpm : null,
music_key: existingLocal ? existingLocal.music_key : null,
+1
View File
@@ -80,6 +80,7 @@ router.get('/', async (req, res) => {
compatLabel: compatLabel,
cover_url: t.cover_url || null,
preview_url: t.preview_url || null,
deezer_link: t.deezer_link || (t.deezer_id ? `https://www.deezer.com/track/${t.deezer_id}` : null),
duration_sec: t.duration_sec || 215,
energy: t.energy || defaultEnergy,
danceability: t.danceability || defaultDance,