diff --git a/src/server/youtube.ts b/src/server/youtube.ts index 8b64286..02c7831 100644 --- a/src/server/youtube.ts +++ b/src/server/youtube.ts @@ -69,6 +69,14 @@ export async function ensureYtDlp(): Promise { const probe = await probeVersion(target) if (probe.ok) return target } + // Fast path: 네이티브가 안 도는 환경에서 이전에 받아둔 zipapp 이 살아있으면 그걸 재사용 + if (process.platform !== 'win32') { + const zipappPath = getYtDlpZipappPath() + if (await fileExists(zipappPath)) { + const probe = await probeVersion(zipappPath) + if (probe.ok) return zipappPath + } + } if (installPromise) return installPromise installPromise = (async () => { try { @@ -83,13 +91,23 @@ export async function ensureYtDlp(): Promise { async function prepareYtDlp(target: string): Promise { const diagnostics: string[] = [] - // 1. 기존 파일이 있으면 우선 그걸로 시도 + // 1a. 기존 네이티브 파일이 있으면 우선 그걸로 시도 if (await fileExists(target)) { const probe = await probeVersion(target) if (probe.ok) return target diagnostics.push(`기존 ${path.basename(target)} 검증 실패: ${probe.detail}`) } + // 1b. (POSIX) 기존 zipapp 이 있으면 재다운로드 전에 먼저 시도 + if (process.platform !== 'win32') { + const existingZipapp = getYtDlpZipappPath() + if (await fileExists(existingZipapp)) { + const probe = await probeVersion(existingZipapp) + if (probe.ok) return existingZipapp + diagnostics.push(`기존 yt-dlp_zipapp 검증 실패: ${probe.detail}`) + } + } + // 2. PATH 에 yt-dlp(.exe) 가 시스템 전역으로 설치돼 있으면 그걸 사용 const pathCmd = process.platform === 'win32' ? 'yt-dlp.exe' : 'yt-dlp' const pathProbe = await probeVersion(pathCmd)