diff --git a/src/services/missing-file-scanner.ts b/src/services/missing-file-scanner.ts index 296f1f3..a265191 100644 --- a/src/services/missing-file-scanner.ts +++ b/src/services/missing-file-scanner.ts @@ -116,10 +116,16 @@ export class MissingFileScanner { .from(systemConfig) .where(eq(systemConfig.key, SCAN_LAST_RESULT_KEY)); - return { - lastRun: rows[0].value, - result: resultRows.length > 0 ? JSON.parse(resultRows[0].value) : { checked: 0, missing: 0, duration: 0 }, - }; + let result: ScanResult = { checked: 0, missing: 0, duration: 0 }; + if (resultRows.length > 0) { + try { + result = JSON.parse(resultRows[0].value) as ScanResult; + } catch { + // Corrupt stored result — return default + } + } + + return { lastRun: rows[0].value, result }; } // ── Private ── diff --git a/src/services/scheduler.ts b/src/services/scheduler.ts index 6b706c0..a8868af 100644 --- a/src/services/scheduler.ts +++ b/src/services/scheduler.ts @@ -480,9 +480,11 @@ export class SchedulerService { } try { - const videoUrl = `https://www.youtube.com/watch?v=${item.platformContentId}`; + // Use the item's original URL (platform-agnostic) instead of + // hardcoding YouTube — SoundCloud / generic items have their own URLs. + const contentUrl = item.url || `https://www.youtube.com/watch?v=${item.platformContentId}`; const enrichResult = await execYtDlp( - ['--dump-json', '--no-playlist', videoUrl], + ['--dump-json', '--no-playlist', contentUrl], { timeout: 15_000 } );