"use strict";
/**
* @file Resolve ffmpeg/ffprobe paths — LM Studio runs without the user's shell PATH,
* so we search common installation directories explicitly.
*
* Supports custom paths via config for Windows or non-standard installations.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.setCustomPaths = setCustomPaths;
exports.getFfmpegPath = getFfmpegPath;
exports.getFfprobePath = getFfprobePath;
const promises_1 = require("fs/promises");
const FFMPEG_SEARCH_PATHS = [
"/opt/homebrew/bin/ffmpeg",
"/usr/local/bin/ffmpeg",
"/usr/bin/ffmpeg",
"/opt/local/bin/ffmpeg",
// Windows common paths
"C:\\Program Files\\ffmpeg\\bin\\ffmpeg.exe",
"C:\\ffmpeg\\bin\\ffmpeg.exe",
];
const FFPROBE_SEARCH_PATHS = [
"/opt/homebrew/bin/ffprobe",
"/usr/local/bin/ffprobe",
"/usr/bin/ffprobe",
"/opt/local/bin/ffprobe",
// Windows common paths
"C:\\Program Files\\ffmpeg\\bin\\ffprobe.exe",
"C:\\ffmpeg\\bin\\ffprobe.exe",
];
let cachedFfmpegPath = null;
let cachedFfprobePath = null;
/** Custom paths set from config — take priority over auto-detection. */
let customFfmpegPath = null;
let customFfprobePath = null;
/**
* Set custom paths from plugin config. Call once during initialization.
* Empty strings are ignored (auto-detection will be used).
*/
function setCustomPaths(ffmpegPath, ffprobePath) {
if (ffmpegPath && ffmpegPath.trim()) {
customFfmpegPath = ffmpegPath.trim();
cachedFfmpegPath = null; // clear cache to pick up new path
}
if (ffprobePath && ffprobePath.trim()) {
customFfprobePath = ffprobePath.trim();
cachedFfprobePath = null;
}
}
async function findExecutable(candidates) {
for (const p of candidates) {
try {
const s = await (0, promises_1.stat)(p);
if (s.isFile())
return p;
}
catch {
// not found, try next
}
}
return null;
}
async function getFfmpegPath() {
if (cachedFfmpegPath)
return cachedFfmpegPath;
// Custom path takes priority
if (customFfmpegPath) {
try {
const s = await (0, promises_1.stat)(customFfmpegPath);
if (s.isFile()) {
cachedFfmpegPath = customFfmpegPath;
return customFfmpegPath;
}
}
catch { }
throw new Error(`Custom ffmpeg path not found: ${customFfmpegPath}`);
}
const found = await findExecutable(FFMPEG_SEARCH_PATHS);
if (!found) {
throw new Error("ffmpeg not found. Install it with: brew install ffmpeg (macOS) or download from https://ffmpeg.org (Windows)\n" +
"Or set a custom path in plugin settings (FFmpeg Path).\n" +
`Searched: ${FFMPEG_SEARCH_PATHS.join(", ")}`);
}
cachedFfmpegPath = found;
return found;
}
async function getFfprobePath() {
if (cachedFfprobePath)
return cachedFfprobePath;
if (customFfprobePath) {
try {
const s = await (0, promises_1.stat)(customFfprobePath);
if (s.isFile()) {
cachedFfprobePath = customFfprobePath;
return customFfprobePath;
}
}
catch { }
throw new Error(`Custom ffprobe path not found: ${customFfprobePath}`);
}
const found = await findExecutable(FFPROBE_SEARCH_PATHS);
if (!found) {
throw new Error("ffprobe not found. Install it with: brew install ffmpeg (macOS) or download from https://ffmpeg.org (Windows)\n" +
"Or set a custom path in plugin settings (FFprobe Path).\n" +
`Searched: ${FFPROBE_SEARCH_PATHS.join(", ")}`);
}
cachedFfprobePath = found;
return found;
}
//# sourceMappingURL=ffmpegPath.js.map