fix: strip ?si= from Spotify URL, improve spotdl error logging

spotdl doesn't handle tracking params in URLs. Also separate stdout/stderr
in Python script and always try parsing stdout before checking exit code.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-11 14:55:41 +02:00
1 parent 3c85deab40
commit 9b197e119a
2 files changed
+32 -16

No files matched your search

+14 -8
View File
@@ -379,16 +379,22 @@ app.get('/api/health', (req, res) => {
async function _resolveSpotifyViaSpotdl(url) {
const { execFile } = require('child_process');
const scriptPath = path.join(__dirname, 'spotify_resolve.py');
// Strip ?si= and other tracking params — spotdl doesn't handle them
const cleanUrl = url.split('?')[0];
return new Promise((resolve, reject) => {
execFile('python3', [scriptPath, url], { timeout: 90000, maxBuffer: 10 * 1024 * 1024 }, (err, stdout, stderr) => {
if (err) return reject(new Error(`spotdl: ${stderr?.trim() || err.message}`));
try {
const data = JSON.parse(stdout.trim());
if (data.error) return reject(new Error(data.error));
resolve(data);
} catch {
reject(new Error(`spotdl: ungültige Ausgabe — ${stdout.slice(0, 200)}`));
execFile('python3', [scriptPath, cleanUrl], { timeout: 90000, maxBuffer: 10 * 1024 * 1024 }, (err, stdout, stderr) => {
if (stderr?.trim()) console.log('[spotdl-py]', stderr.trim().slice(0, 500));
// Always try to parse stdout first — script outputs JSON even on error
const out = stdout?.trim();
if (out) {
try {
const data = JSON.parse(out);
if (data.error) return reject(new Error(`spotdl: ${data.error}`));
return resolve(data);
} catch { /* not JSON, fall through */ }
}
if (err) return reject(new Error(`spotdl exited ${err.code}: ${stderr?.trim() || out || err.message}`));
reject(new Error(`spotdl: keine Ausgabe`));
});
});
}