yt-dlx
Version:
Effortless Audio-Video Downloader And Streamer!
59 lines • 1.76 kB
JavaScript
import * as path from "path";
import * as fsx from "fs-extra";
async function findRootDirectory(currentPath) {
const markerFile = "package.json";
try {
const files = await fsx.readdir(currentPath);
if (files.includes(markerFile))
return currentPath;
const parentDir = path.resolve(currentPath, "..");
if (parentDir === currentPath)
return null;
else
return findRootDirectory(parentDir);
}
catch {
return null;
}
}
async function scanner(directory, execName) {
try {
const files = await fsx.readdir(directory);
for (const file of files) {
const filePath = path.join(directory, file);
const stat = await fsx.stat(filePath);
if (stat.isDirectory()) {
const result = await scanner(filePath, execName);
if (result)
return result;
}
else {
if (file.toLowerCase() === execName.toLowerCase() ||
file.toLowerCase() === execName.toLowerCase() + ".exe") {
return filePath;
}
}
}
return null;
}
catch {
return null;
}
}
export async function locator() {
try {
const rootDirectory = await findRootDirectory(__dirname);
if (!rootDirectory)
return {};
const results = {};
for (const execName of ["ffmpeg", "ffprobe", "cprobe"]) {
const execPath = await scanner(rootDirectory, execName);
results[execName] = execPath || "";
}
return results;
}
catch (error) {
return {};
}
}
//# sourceMappingURL=locator.js.map