"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isYtDlpAvailable = isYtDlpAvailable; exports.downloadVideo = downloadVideo; const child_process_1 = require("child_process"); const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); function isYtDlpAvailable() { try { (0, child_process_1.execSync)('yt-dlp --version', { stdio: 'pipe' }); return true; } catch { return false; } } function downloadVideo(url, outputDir) { if (!fs_1.default.existsSync(outputDir)) { fs_1.default.mkdirSync(outputDir, { recursive: true }); } const outputTemplate = path_1.default.join(outputDir, '%(title)s.%(ext)s'); const result = (0, child_process_1.execSync)(`yt-dlp -f "best[ext=mp4]/best" -o "${outputTemplate}" --print filename --print title "${url}"`, { encoding: 'utf-8', timeout: 600000 }); const lines = result.trim().split('\n'); const filename = lines[0]?.trim(); const title = lines[1]?.trim() || filename; if (!filename) { throw new Error('yt-dlp: Failed to parse downloaded filename'); } const filePath = path_1.default.resolve(outputDir, filename); if (!fs_1.default.existsSync(filePath)) { throw new Error(`yt-dlp: Downloaded file not found at ${filePath}`); } return { filePath, filename, title }; } //# sourceMappingURL=ytDlp.js.map