downloadAlbumTracks passed each track's artistName as `artist` but no `rawArtist`,
so in ytdlp.js the YTM/YouTube search query and the channel filter used
`mainArtist = albumArtist || artist` — always the album-artist blob. On mixed-artist
soundtracks that matched nothing: e.g. TWICE's "Strategy" and MeloMance's "Love,
Maybe" were searched as "KPop Demon Hunters Cast, HUNTR/X & Saja Boys <title>" with
`channel ~= KPop`, and failed with "Nicht eindeutig gefunden".
Pass rawArtist = track.artistName so the search + channel filter use the actual
performer ("TWICE Strategy", channel ~= TWICE). The album_artist tag still comes from
`albumArtist`, so album grouping is unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
53 lines
2.3 KiB
JavaScript
53 lines
2.3 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,
|
|
// Drive the YTM/YouTube search + channel filter with THIS track's own artist, not the album
|
|
// artist. On mixed-artist soundtracks/compilations (e.g. "Strategy" is TWICE, "Love, Maybe"
|
|
// is MeloMance) the album-artist blob + its channel filter matches nothing. album_artist tag
|
|
// still uses `albumArtist` below, so album grouping is unaffected.
|
|
rawArtist: 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 };
|