When a track's duration is known but nothing matches the duration window, the cascade no longer falls back to blind title-only/no-filter grabs (which pulled same-titled videos by other uploaders, e.g. a "recognize" fan clip). Instead it relaxes only the duration constraint while still REQUIRING the artist channel + title. If nothing matches, the download produces no file and the job now fails cleanly with "Nicht eindeutig gefunden — bitte Direktlink im Importer nutzen" (previously it falsely reported success with no file). Single, album and playlist paths all surface the not-found state. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
1.9 KiB
JavaScript
48 lines
1.9 KiB
JavaScript
const { log, updateJob } = require('./jobs');
|
|
const ytdlp = require('./ytdlp');
|
|
const CONFIG = require('./config');
|
|
|
|
// Download a single track via yt-dlp.
|
|
async function downloadTrack(opts) {
|
|
return ytdlp.downloadTrack(opts);
|
|
}
|
|
|
|
// Download all tracks of an album sequentially, updating job progress.
|
|
async function downloadAlbumTracks({ jobId, artist, albumTitle, tracks, artworkUrl }) {
|
|
const total = tracks.length;
|
|
log(jobId, `📀 Album "${albumTitle}" — ${total} Tracks`);
|
|
let done = 0, skipped = 0;
|
|
|
|
for (const track of tracks) {
|
|
try {
|
|
const result = await downloadTrack({
|
|
jobId,
|
|
artist: track.artistName || artist,
|
|
albumArtist: artist,
|
|
title: track.trackName || track.title,
|
|
album: albumTitle,
|
|
year: track.releaseDate ? new Date(track.releaseDate).getFullYear() : undefined,
|
|
trackNum: track.trackNumber || undefined,
|
|
totalTracks: total,
|
|
discNum: track.discNumber || undefined,
|
|
discTotal: track.discCount || undefined,
|
|
compilation: track.collectionType === 'Compilation' || undefined,
|
|
genre: track.primaryGenreName || undefined,
|
|
artworkUrl: artworkUrl || track.artworkUrl100,
|
|
explicit: track.trackExplicitness === 'explicit',
|
|
outputDir: CONFIG.musicPath,
|
|
durationMs: track.trackTimeMillis || undefined,
|
|
});
|
|
if (result?.skipped) skipped++;
|
|
else if (result?.notFound) log(jobId, `⚠️ Nicht eindeutig gefunden: "${track.trackName || track.title}" — Direktlink nutzen`);
|
|
else done++;
|
|
updateJob(jobId, { progress: Math.round(((done + skipped) / total) * 90) });
|
|
} catch (e) {
|
|
log(jobId, `⚠️ Fehler bei "${track.trackName || track.title}": ${e.message}`);
|
|
}
|
|
}
|
|
return { done, skipped };
|
|
}
|
|
|
|
module.exports = { downloadTrack, downloadAlbumTracks };
|