Support for YTDOWNLOADER_YTDLP_PATH, YTDOWNLOADER_FFMPEG_PATH

release
aandrew-me 2 months ago
parent 65b9f5050f
commit 315994db8c

@ -1,8 +1,9 @@
const {exec} = require("child_process");
const {exec, execSync} = require("child_process");
const path = require("path");
const {ipcRenderer, shell} = require("electron");
const os = require("os");
const si = require("systeminformation")
const si = require("systeminformation");
const { existsSync } = require("fs");
let menuIsOpen = false;
@ -33,68 +34,85 @@ getId("menuIcon").addEventListener("click", () => {
}
});
let ffmpeg;
// Ffmpeg check
if (os.platform() === "win32") {
ffmpeg = `"${__dirname}\\..\\ffmpeg.exe"`;
} else if (os.platform() === "freebsd") {
try {
ffmpeg = cp.execSync("which ffmpeg").toString("utf8").split("\n")[0].trim();
ffmpeg = execSync("which ffmpeg")
.toString("utf8")
.split("\n")[0]
.trim();
} catch (error) {
console.log(error)
showPopup("No ffmpeg found in PATH.");
showPopup("No ffmpeg found in PATH")
}
}
else {
} else {
ffmpeg = `"${__dirname}/../ffmpeg"`;
}
const vaapi_device = "/dev/dri/renderD128"
if (process.env.YTDOWNLOADER_FFMPEG_PATH) {
ffmpeg = `"${process.env.YTDOWNLOADER_FFMPEG_PATH}"`;
if (existsSync(process.env.YTDOWNLOADER_FFMPEG_PATH)) {
console.log("Using YTDOWNLOADER_FFMPEG_PATH");
} else {
showPopup("You have specified YTDOWNLOADER_FFMPEG_PATH, but no file exists there.")
}
}
console.log(ffmpeg);
const vaapi_device = "/dev/dri/renderD128";
// Checking GPU
si.graphics().then((info) => {
console.log({gpuInfo: info})
console.log({gpuInfo: info});
const gpuDevices = info.controllers;
gpuDevices.forEach((gpu) => {
// NVIDIA
const gpuName = gpu.vendor.toLowerCase()
const gpuModel = gpu.model.toLowerCase()
if (gpuName.includes("nvidia") || gpuModel.includes("nvidia")) {
document.querySelectorAll(".nvidia_opt").forEach((opt) => {
opt.style.display = "block"
})
} else if (gpuName.includes("advanced micro devices") || gpuModel.includes("amd")) {
if (os.platform() == "win32") {
document.querySelectorAll(".amf_opt").forEach((opt) => {
opt.style.display = "block"
})
} else {
document.querySelectorAll(".vaapi_opt").forEach((opt) => {
opt.style.display = "block"
})
}
} else if (gpuName.includes("intel")) {
if (os.platform() == "win32") {
document.querySelectorAll(".qsv_opt").forEach((opt) => {
opt.style.display = "block"
})
} else if (os.platform() != "darwin") {
document.querySelectorAll(".vaapi_opt").forEach((opt) => {
opt.style.display = "block"
})
}
} else {
if (os.platform() == "darwin") {
document.querySelectorAll(".videotoolbox_opt").forEach((opt) => {
opt.style.display = "block"
})
}
}
})
})
gpuDevices.forEach((gpu) => {
// NVIDIA
const gpuName = gpu.vendor.toLowerCase();
const gpuModel = gpu.model.toLowerCase();
if (gpuName.includes("nvidia") || gpuModel.includes("nvidia")) {
document.querySelectorAll(".nvidia_opt").forEach((opt) => {
opt.style.display = "block";
});
} else if (
gpuName.includes("advanced micro devices") ||
gpuModel.includes("amd")
) {
if (os.platform() == "win32") {
document.querySelectorAll(".amf_opt").forEach((opt) => {
opt.style.display = "block";
});
} else {
document.querySelectorAll(".vaapi_opt").forEach((opt) => {
opt.style.display = "block";
});
}
} else if (gpuName.includes("intel")) {
if (os.platform() == "win32") {
document.querySelectorAll(".qsv_opt").forEach((opt) => {
opt.style.display = "block";
});
} else if (os.platform() != "darwin") {
document.querySelectorAll(".vaapi_opt").forEach((opt) => {
opt.style.display = "block";
});
}
} else {
if (os.platform() == "darwin") {
document
.querySelectorAll(".videotoolbox_opt")
.forEach((opt) => {
opt.style.display = "block";
});
}
}
});
});
/** @type {File[]} */
let files = [];
@ -127,7 +145,7 @@ dropZone.addEventListener("drop", (e) => {
e.preventDefault();
dropZone.classList.remove("dragover");
// @ts-ignore
console.log(e.dataTransfer)
console.log(e.dataTransfer);
files = Array.from(e.dataTransfer.files);
updateSelectedFiles();
});
@ -139,8 +157,8 @@ fileInput.addEventListener("change", (e) => {
});
getId("custom-folder-select").addEventListener("click", (e) => {
ipcRenderer.send("get-directory", "")
})
ipcRenderer.send("get-directory", "");
});
function updateSelectedFiles() {
const fileList = files
@ -158,7 +176,6 @@ async function startCompression() {
const settings = getEncoderSettings();
for (const file of files) {
const itemId =
"f" + Math.random().toFixed(10).toString().slice(2).toString();
@ -173,30 +190,30 @@ async function startCompression() {
isCancelled = false;
} else {
updateProgress("success", "", itemId);
const fileSavedElement = document.createElement("b")
fileSavedElement.textContent = "File saved. Click to open"
const fileSavedElement = document.createElement("b");
fileSavedElement.textContent = "File saved. Click to open";
fileSavedElement.onclick = () => {
shell.showItemInFolder(outputPath)
}
getId(itemId + "_prog").appendChild(fileSavedElement)
currentItemId = ""
shell.showItemInFolder(outputPath);
};
getId(itemId + "_prog").appendChild(fileSavedElement);
currentItemId = "";
}
} catch (error) {
const errorElement = document.createElement("div")
const errorElement = document.createElement("div");
errorElement.onclick = () => {
ipcRenderer.send("error_dialog", error.message)
}
errorElement.textContent = "Error. Click for details"
ipcRenderer.send("error_dialog", error.message);
};
errorElement.textContent = "Error. Click for details";
updateProgress("error", "", itemId);
getId(itemId + "_prog").appendChild(errorElement)
currentItemId = ""
getId(itemId + "_prog").appendChild(errorElement);
currentItemId = "";
}
}
}
function cancelCompression() {
activeProcesses.forEach((child) => {
child.stdin.write("q")
child.stdin.write("q");
isCancelled = true;
});
activeProcesses.clear();
@ -207,18 +224,23 @@ function cancelCompression() {
* @param {File} file
*/
function generateOutputPath(file, settings) {
console.log({settings})
const output_extension = settings.extension
const parsed_file = path.parse(file.path)
let outputDir = settings.outputPath || parsed_file.dir
console.log({settings});
const output_extension = settings.extension;
const parsed_file = path.parse(file.path);
let outputDir = settings.outputPath || parsed_file.dir;
if (output_extension == "unchanged") {
return path.join(outputDir, `${parsed_file.name}${settings.outputSuffix}${parsed_file.ext}`);
}
if (output_extension == "unchanged") {
return path.join(
outputDir,
`${parsed_file.name}${settings.outputSuffix}${parsed_file.ext}`
);
}
return path.join(outputDir, `${parsed_file.name}_compressed.${output_extension}`);
return path.join(
outputDir,
`${parsed_file.name}_compressed.${output_extension}`
);
}
/**
@ -230,7 +252,7 @@ function generateOutputPath(file, settings) {
async function compressVideo(file, settings, itemId, outputPath) {
const command = buildFFmpegCommand(file, settings, outputPath);
console.log("Command: " + command)
console.log("Command: " + command);
return new Promise((resolve, reject) => {
const child = exec(command, (error) => {
@ -240,7 +262,7 @@ async function compressVideo(file, settings, itemId, outputPath) {
activeProcesses.add(child);
child.on("exit", (_code) => {
activeProcesses.delete(child)
activeProcesses.delete(child);
});
let video_info = {
@ -296,9 +318,9 @@ async function compressVideo(file, settings, itemId, outputPath) {
* @param {string} outputPath
*/
function buildFFmpegCommand(file, settings, outputPath) {
const inputPath = file.path;
const inputPath = file.path;
console.log("Output path: " + outputPath)
console.log("Output path: " + outputPath);
const args = ["-hide_banner", "-y", "-stats", "-i", `"${inputPath}"`];
@ -312,7 +334,8 @@ function buildFFmpegCommand(file, settings, outputPath) {
"libx264",
"-preset",
settings.speed,
"-vf", "format=yuv420p",
"-vf",
"format=yuv420p",
"-crf",
parseInt(settings.videoQuality).toString()
);
@ -321,7 +344,8 @@ function buildFFmpegCommand(file, settings, outputPath) {
args.push(
"-c:v",
"libx265",
"-vf", "format=yuv420p",
"-vf",
"format=yuv420p",
"-preset",
settings.speed,
"-crf",
@ -333,7 +357,8 @@ function buildFFmpegCommand(file, settings, outputPath) {
args.push(
"-c:v",
"h264_qsv",
"-vf", "format=yuv420p",
"-vf",
"format=yuv420p",
"-preset",
settings.speed,
"-global_quality",
@ -353,24 +378,25 @@ function buildFFmpegCommand(file, settings, outputPath) {
parseInt(settings.videoQuality).toString()
);
break;
case "hevc_vaapi":
args.push(
"-vaapi_device",
vaapi_device,
"-vf",
"format=nv12,hwupload",
"-c:v",
"hevc_vaapi",
"-qp",
parseInt(settings.videoQuality).toString()
);
break;
case "hevc_vaapi":
args.push(
"-vaapi_device",
vaapi_device,
"-vf",
"format=nv12,hwupload",
"-c:v",
"hevc_vaapi",
"-qp",
parseInt(settings.videoQuality).toString()
);
break;
// Nvidia windows and linux
case "nvenc":
args.push(
"-c:v",
"h264_nvenc",
"-vf", "format=yuv420p",
"-vf",
"format=yuv420p",
"-preset",
getNvencPreset(settings.speed),
"-rc",
@ -392,7 +418,8 @@ function buildFFmpegCommand(file, settings, outputPath) {
args.push(
"-c:v",
"hevc_amf",
"-vf", "format=yuv420p",
"-vf",
"format=yuv420p",
"-quality",
amf_hevc_quality,
"-rc",
@ -400,7 +427,7 @@ function buildFFmpegCommand(file, settings, outputPath) {
"-qp_i",
parseInt(settings.videoQuality).toString(),
"-qp_p",
parseInt(settings.videoQuality).toString(),
parseInt(settings.videoQuality).toString()
);
break;
case "amf":
@ -415,7 +442,8 @@ function buildFFmpegCommand(file, settings, outputPath) {
args.push(
"-c:v",
"h264_amf",
"-vf", "format=yuv420p",
"-vf",
"format=yuv420p",
"-quality",
amf_quality,
"-rc",
@ -431,7 +459,8 @@ function buildFFmpegCommand(file, settings, outputPath) {
case "videotoolbox":
args.push(
"-c:v",
"-vf", "format=yuv420p",
"-vf",
"format=yuv420p",
"h264_videotoolbox",
"-q:v",
parseInt(settings.videoQuality).toString()
@ -460,8 +489,8 @@ function getEncoderSettings() {
videoQuality: getId("video-quality").value,
// @ts-ignore
audioFormat: getId("audio-format").value,
// @ts-ignore
extension: getId("file_extension").value,
// @ts-ignore
extension: getId("file_extension").value,
outputPath: getId("custom-folder-path").textContent,
// @ts-ignore
outputSuffix: getId("output-suffix").value,
@ -550,13 +579,13 @@ getId("output-folder-input").addEventListener("change", (e) => {
const checked = e.target.checked;
if (!checked) {
getId("custom-folder-select").style.display = "block"
getId("custom-folder-select").style.display = "block";
} else {
getId("custom-folder-select").style.display = "none"
getId("custom-folder-path").textContent = ""
getId("custom-folder-path").style.display = "none"
getId("custom-folder-select").style.display = "none";
getId("custom-folder-path").textContent = "";
getId("custom-folder-path").style.display = "none";
}
})
});
const storageTheme = localStorage.getItem("theme");
if (storageTheme) {
@ -565,11 +594,11 @@ if (storageTheme) {
}
ipcRenderer.on("directory-path", (_event, msg) => {
let customFolderPathItem = getId("custom-folder-path")
let customFolderPathItem = getId("custom-folder-path");
customFolderPathItem.textContent = msg;
customFolderPathItem.style.display = "inline"
})
customFolderPathItem.style.display = "inline";
});
function closeMenu() {
getId("menuIcon").style.transform = "rotate(0deg)";
@ -618,4 +647,4 @@ function showPopup(text) {
setTimeout(() => {
getId("popupText").style.display = "none";
}, 2200);
}
}

@ -4,22 +4,26 @@ const path = require("path");
const os = require("os");
const fs = require("fs");
const {execSync} = require("child_process");
const { constants } = require("fs/promises");
const {constants} = require("fs/promises");
let url;
const ytDlp = localStorage.getItem("ytdlp");
console.log(`yt-dlp: ${ytDlp}`)
const ytdlp = new YTDlpWrap(`"${ytDlp}"`);
const downloadsDir = path.join(os.homedir(), "Downloads");
let downloadDir = localStorage.getItem("downloadPath") || downloadsDir;
try {
console.log("Trying to access", downloadDir)
fs.accessSync(downloadDir, constants.W_OK);
downloadDir = downloadDir;
} catch (err) {
console.log("Unable to write to download directory. Switching to default one.")
console.log("Err:", err)
console.log(
"Unable to write to download directory. Switching to default one."
);
console.log("Err:", err);
downloadDir = downloadsDir;
localStorage.setItem("downloadPath", downloadsDir);
}
getId("path").textContent = downloadDir;
const i18n = new (require("../translations/i18n"))();
let cookieArg = "";
@ -38,34 +42,41 @@ const formats = {
let originalCount = 0;
let ffmpeg;
let ffmpegPath;
if (os.platform() === "win32") {
ffmpeg = `"${__dirname}\\..\\ffmpeg.exe"`;
ffmpegPath = `${__dirname}\\..\\ffmpeg.exe`;
} else if (os.platform() === "freebsd") {
try {
ffmpegPath = execSync("which ffmpeg")
.toString("utf8")
.split("\n")[0]
.trim();
} catch (error) {
console.log(error);
}
} else {
ffmpeg = `"${__dirname}/../ffmpeg"`;
ffmpegPath = `${__dirname}/../ffmpeg`;
}
if (!fs.existsSync(ffmpegPath)) {
try {
if (os.platform() === "win32") {
ffmpeg = execSync("where ffmpeg.exe", {encoding: "utf8"});
console.log({ffmpeg})
ffmpeg = `"${ffmpeg.trimEnd()}"`;
} else {
ffmpeg = execSync("which ffmpeg", {encoding: "utf8"});
ffmpeg = `"${ffmpeg.trimEnd()}"`;
}
} catch (error) {
ffmpeg = `""`
console.log(error);
if (process.env.YTDOWNLOADER_FFMPEG_PATH) {
ffmpegPath = `${process.env.YTDOWNLOADER_FFMPEG_PATH}`;
if (fs.existsSync(process.env.YTDOWNLOADER_FFMPEG_PATH)) {
console.log("Using YTDOWNLOADER_FFMPEG_PATH");
} else {
console.error("No ffmpeg found in " + ffmpeg);
}
}
ffmpeg = `"${ffmpegPath}"`
console.log("ffmpeg:", ffmpeg);
if (localStorage.getItem("preferredVideoQuality")) {
const preferredVideoQuality = localStorage.getItem("preferredVideoQuality");
getId('select').value = preferredVideoQuality
getId("select").value = preferredVideoQuality;
}
if (localStorage.getItem("preferredAudioQuality")) {
const preferredAudioQuality = localStorage.getItem("preferredAudioQuality");
@ -76,11 +87,11 @@ let foldernameFormat = "%(playlist_title)s";
let filenameFormat = "%(playlist_index)s.%(title)s.%(ext)s";
let playlistIndex = 1;
let playlistEnd = "";
let proxy = ""
let proxy = "";
/**
*
* @param {string} id
*
* @param {string} id
* @returns {any}
*/
function getId(id) {
@ -111,7 +122,7 @@ const videoIndex = "Downloading item ";
const oldVideoIndex = "Downloading video ";
/**
* @param {string} type
* @param {string} type
*/
function download(type) {
// Config file
@ -122,7 +133,7 @@ function download(type) {
configTxt = `"${localStorage.getItem("configPath")}"`;
}
proxy = localStorage.getItem("proxy") || "";
console.log("Proxy:", proxy)
console.log("Proxy:", proxy);
nameFormatting();
originalCount = 0;
@ -147,7 +158,7 @@ function download(type) {
if (getId("subChecked").checked) {
subs = "--write-subs";
subLangs = "--sub-langs all";
console.log("Downloading with subtitles")
console.log("Downloading with subtitles");
} else {
subs = "";
subLangs = "";
@ -201,14 +212,18 @@ function download(type) {
"--embed-metadata",
subs,
subLangs,
videoType == "mp4" && (url.includes("youtube.com/") || url.includes("youtu.be/")) && os.platform() !== "darwin" ? "--embed-thumbnail" : "",
videoType == "mp4" &&
(url.includes("youtube.com/") || url.includes("youtu.be/")) &&
os.platform() !== "darwin"
? "--embed-thumbnail"
: "",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
"--compat-options",
"no-youtube-unavailable-videos",
`"${url}"`,
].filter(item => item);
].filter((item) => item);
downloadProcess = ytdlp.exec(
args,
@ -222,7 +237,7 @@ function download(type) {
format === "m4a" &&
audioQuality === "auto"
) {
console.log("Downloading m4a without extracting")
console.log("Downloading m4a without extracting");
const args = [
"--yes-playlist",
@ -230,11 +245,7 @@ function download(type) {
"-f",
`ba[ext=${format}]/ba`,
"-o",
`"${path.join(
downloadDir,
foldernameFormat,
filenameFormat
)}"`,
`"${path.join(downloadDir, foldernameFormat, filenameFormat)}"`,
"-I",
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
@ -253,7 +264,7 @@ function download(type) {
"--compat-options",
"no-youtube-unavailable-videos",
`"${url}"`,
].filter(item => item);
].filter((item) => item);
downloadProcess = ytdlp.exec(
args,
@ -261,7 +272,7 @@ function download(type) {
controller.signal
);
} else {
console.log("Extracting audio")
console.log("Extracting audio");
const args = [
"--yes-playlist",
@ -272,11 +283,7 @@ function download(type) {
"--audio-quality",
audioQuality,
"-o",
`"${path.join(
downloadDir,
foldernameFormat,
filenameFormat
)}"`,
`"${path.join(downloadDir, foldernameFormat, filenameFormat)}"`,
"-I",
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
@ -288,14 +295,20 @@ function download(type) {
"--embed-metadata",
subs,
subLangs,
format === "mp3" || format === "m4a" && (url.includes("youtube.com/") || url.includes("youtu.be/")) && os.platform() !== "darwin" ? "--embed-thumbnail" : "",
format === "mp3" ||
(format === "m4a" &&
(url.includes("youtube.com/") ||
url.includes("youtu.be/")) &&
os.platform() !== "darwin")
? "--embed-thumbnail"
: "",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
"--compat-options",
"no-youtube-unavailable-videos",
`"${url}"`,
].filter(item => item);
].filter((item) => item);
downloadProcess = ytdlp.exec(
args,
@ -305,7 +318,6 @@ function download(type) {
}
}
// getId("finishBtn").addEventListener("click", () => {
// controller.abort("user_finished")
// try {
@ -411,7 +423,7 @@ function showErrorTxt(error) {
getId("incorrectMsgPlaylist").textContent = i18n.__(
"Some error has occurred. Check your network and use correct URL"
);
getId("incorrectMsgPlaylist").style.display = "block"
getId("incorrectMsgPlaylist").style.display = "block";
getId("incorrectMsgPlaylist").title = error;
getId("errorBtn").style.display = "inline-block";
getId("errorDetails").innerHTML = `
@ -439,8 +451,8 @@ function hideOptions(justHide = false) {
getId("errorBtn").style.display = "none";
getId("errorDetails").style.display = "none";
getId("errorDetails").textContent = "";
getId("incorrectMsgPlaylist").style.display = "none"
if (!justHide){
getId("incorrectMsgPlaylist").style.display = "none";
if (!justHide) {
getId("playlistName").textContent = i18n.__("Processing") + "...";
getId("pasteLink").style.display = "none";
getId("openDownloads").style.display = "inline-block";
@ -474,12 +486,9 @@ function downloadThumbnails() {
"--compat-options",
"no-youtube-unavailable-videos",
`"${url}"`,
].filter(item => item);
].filter((item) => item);
const downloadProcess = ytdlp.exec(
args,
{shell: true, detached: false}
);
const downloadProcess = ytdlp.exec(args, {shell: true, detached: false});
// console.log(downloadProcess.ytDlpProcess.spawnargs[2])
@ -552,12 +561,9 @@ function saveLinks() {
"--compat-options",
"no-youtube-unavailable-videos",
`"${url}"`,
].filter(item => item);
const downloadProcess = ytdlp.exec(
args,
{shell: true, detached: false}
);
].filter((item) => item);
const downloadProcess = ytdlp.exec(args, {shell: true, detached: false});
downloadProcess.on("ytDlpEvent", (eventType, eventData) => {
// console.log(eventData);
@ -762,13 +768,13 @@ getId("githubTxt").textContent = i18n.__("Github");
getId("latteTxt").textContent = i18n.__("Latte");
getId("solarizedDarkTxt").textContent = i18n.__("Solarized Dark");
getId("audioQualitySelectTxt").textContent = i18n.__("Select Quality")
getId("audioQualityAuto").textContent = i18n.__("Auto")
getId("audioQualityNormal").textContent = i18n.__("Normal")
getId("audioQualityBest").textContent = i18n.__("Best")
getId("audioQualityGood").textContent = i18n.__("Good")
getId("audioQualityBad").textContent = i18n.__("Bad")
getId("audioQualityWorst").textContent = i18n.__("Worst")
getId("audioQualitySelectTxt").textContent = i18n.__("Select Quality");
getId("audioQualityAuto").textContent = i18n.__("Auto");
getId("audioQualityNormal").textContent = i18n.__("Normal");
getId("audioQualityBest").textContent = i18n.__("Best");
getId("audioQualityGood").textContent = i18n.__("Good");
getId("audioQualityBad").textContent = i18n.__("Bad");
getId("audioQualityWorst").textContent = i18n.__("Worst");
getId("subHeader").textContent = i18n.__("Subtitles");
getId("subTxt").textContent = i18n.__("Download subtitles if available");

@ -8,23 +8,6 @@ const {constants} = require("fs/promises");
let ffmpeg = "";
if (os.platform() === "win32") {
ffmpeg = `"${__dirname}\\..\\ffmpeg.exe"`;
} else if (os.platform() === "freebsd") {
try {
ffmpeg = cp
.execSync("which ffmpeg")
.toString("utf8")
.split("\n")[0]
.trim();
} catch (error) {
console.log(error);
showPopup("No ffmpeg found in PATH.");
}
} else {
ffmpeg = `"${__dirname}/../ffmpeg"`;
}
// Directories
const homedir = os.homedir();
let appdir = path.join(homedir, "Downloads");
@ -58,7 +41,7 @@ if (trayEnabled == "true") {
let downloadDir = "";
// Global variables
let title, onlyVideo, thumbnail, ytdlp, duration, extractor_key;
let title, onlyVideo, thumbnail, ytDlp, duration, extractor_key;
let audioExtensionList = [];
let rangeCmd = "";
let subs = "";
@ -106,7 +89,7 @@ if (process.windowsStore) {
}
if (process.env.YTDOWNLOADER_AUTO_UPDATES == "0") {
autoUpdate = false
autoUpdate = false;
}
ipcRenderer.send("autoUpdate", autoUpdate);
@ -133,6 +116,10 @@ const possiblePaths = [
// Checking for yt-dlp
let ytDlpPath = path.join(os.homedir(), ".ytDownloader", "ytdlp");
if (os.platform() == "win32") {
ytDlpPath = path.join(os.homedir(), ".ytDownloader", "ytdlp.exe");
}
// Macos yt-dlp check
if (os.platform() === "darwin") {
ytDlpPath = possiblePaths.find((p) => fs.existsSync(p)) || null;
@ -141,6 +128,7 @@ if (os.platform() === "darwin") {
showMacYtdlpPopup();
} else {
ytDlpIsPresent = true;
setLocalStorageYtDlp(ytDlpPath)
}
}
@ -154,40 +142,70 @@ if (os.platform() === "freebsd") {
.trim();
ytDlpIsPresent = true;
setLocalStorageYtDlp(ytDlpPath)
} catch (error) {
console.log(error);
hidePasteBtn()
getId("incorrectMsg").textContent = i18n.__(
"No yt-dlp found in PATH. Make sure you have the full executable. App will not work"
);
}
}
// Getting yt-dlp path from environment variable
if (process.env.YTDOWNLOADER_YTDLP_PATH) {
ytDlpPath = process.env.YTDOWNLOADER_YTDLP_PATH;
if (fs.existsSync(ytDlpPath)) {
logYtDlpPresent(ytDlpPath);
ytDlp = new YTDlpWrap(`"${ytDlpPath}"`);
ytDlpIsPresent = true;
setLocalStorageYtDlp(ytDlpPath)
} else {
hidePasteBtn()
getId("incorrectMsg").textContent = i18n.__(
"You have specified YTDOWNLOADER_YTDLP_PATH, but no file exists there."
);
}
}
// Checking if yt-dlp bin is present
if (
localStorage.getItem("ytdlp") &&
os.platform() != "darwin" &&
os.platform() != "freebsd"
os.platform() != "freebsd" &&
!process.env.YTDOWNLOADER_YTDLP_PATH
) {
const localStorageytDlpPath = localStorage.getItem("ytdlp");
if (fs.existsSync(localStorageytDlpPath)) {
console.log("yt-dlp binary is present in PATH");
ytdlp = new YTDlpWrap(`"${ytDlpPath}"`);
logYtDlpPresent(ytDlpPath)
ytDlp = new YTDlpWrap(`"${ytDlpPath}"`);
cp.spawn(`${ytDlpPath}`, ["-U"]).stdout.on("data", (data) =>
console.log(data.toString("utf8"))
);
console.log("yt-dlp bin Path: " + ytDlpPath);
ipcRenderer.send("ready-for-links");
ytDlpIsPresent = true;
setLocalStorageYtDlp(ytDlpPath)
}
}
// If path doesn't exist in localStorage
if (!ytDlpIsPresent) {
if (
!ytDlpIsPresent &&
!process.env.YTDOWNLOADER_YTDLP_PATH &&
os.platform() !== "freebsd" &&
os.platform() !== "darwin"
) {
// yt-dlp download path
let ytDlpDownloadPath;
if (os.platform() == "win32") {
@ -201,11 +219,7 @@ if (!ytDlpIsPresent) {
}
cp.exec(`"${ytDlpPath}" --version`, (error, _stdout, _stderr) => {
if (
error &&
os.platform() !== "freebsd" &&
os.platform() !== "darwin"
) {
if (error) {
getId("popupBox").style.display = "block";
process.on("uncaughtException", (_reason, _promise) => {
@ -214,19 +228,56 @@ if (!ytDlpIsPresent) {
downloadYtDlp(ytDlpDownloadPath);
} else {
console.log("yt-dlp binary is present in PATH");
ytdlp = new YTDlpWrap(`"${ytDlpPath}"`);
logYtDlpPresent(ytDlpPath)
ytDlp = new YTDlpWrap(`"${ytDlpPath}"`);
cp.spawn(`${ytDlpPath}`, ["-U"]).stdout.on("data", (data) =>
console.log(data.toString("utf8"))
);
console.log("yt-dlp bin Path: " + ytDlpPath);
ipcRenderer.send("ready-for-links");
setLocalStorageYtDlp(ytDlpPath)
}
});
}
// Ffmpeg check
if (os.platform() === "win32") {
ffmpeg = `"${__dirname}\\..\\ffmpeg.exe"`;
} else if (os.platform() === "freebsd") {
try {
ffmpeg = cp
.execSync("which ffmpeg")
.toString("utf8")
.split("\n")[0]
.trim();
} catch (error) {
console.log(error);
getId("incorrectMsg").textContent = i18n.__(
"No ffmpeg found in PATH"
);
}
} else {
ffmpeg = `"${__dirname}/../ffmpeg"`;
}
if (process.env.YTDOWNLOADER_FFMPEG_PATH) {
ffmpeg = `"${process.env.YTDOWNLOADER_FFMPEG_PATH}"`
if (fs.existsSync(process.env.YTDOWNLOADER_FFMPEG_PATH)) {
console.log("Using YTDOWNLOADER_FFMPEG_PATH")
} else {
getId("incorrectMsg").textContent = i18n.__(
"You have specified YTDOWNLOADER_FFMPEG_PATH, but no file exists there."
);
}
}
console.log(ffmpeg)
getId("closeHidden").addEventListener("click", () => {
hideHidden();
getId("loadingWrapper").style.display = "none";
@ -259,7 +310,7 @@ async function getInfo(url) {
downloadPathSelection();
// Cleaning text
resetDomValues()
resetDomValues();
if (localStorage.getItem("preferredVideoQuality")) {
preferredVideoQuality = Number(
@ -288,7 +339,7 @@ async function getInfo(url) {
if (localStorage.getItem("browser")) {
browser = localStorage.getItem("browser");
}
if (browser) {
cookieArg = "--cookies-from-browser";
} else {
@ -1096,7 +1147,7 @@ function download(
`"${url}"`,
].filter((item) => item);
downloadProcess = ytdlp.exec(
downloadProcess = ytDlp.exec(
args,
{shell: true, detached: false},
controller.signal
@ -1144,7 +1195,7 @@ function download(
`"${url}"`,
].filter((item) => item);
downloadProcess = ytdlp.exec(
downloadProcess = ytDlp.exec(
args,
{shell: true, detached: false},
controller.signal
@ -1184,7 +1235,7 @@ function download(
`"${url}"`,
].filter((item) => item);
downloadProcess = ytdlp.exec(
downloadProcess = ytDlp.exec(
args,
{shell: true, detached: false},
controller.signal
@ -1491,7 +1542,7 @@ async function downloadYtDlp(downloadPath) {
await YTDlpWrap.downloadFromGithub(downloadPath);
getId("popupBox").style.display = "none";
ytdlp = new YTDlpWrap(`"${ytDlpPath}"`);
ytDlp = new YTDlpWrap(`"${ytDlpPath}"`);
localStorage.setItem("ytdlp", ytDlpPath);
console.log("yt-dlp bin Path: " + ytDlpPath);
}
@ -1558,7 +1609,6 @@ function handleYtDlpError() {
});
}
function resetDomValues() {
getId("videoFormatSelect").innerHTML = "";
getId("audioFormatSelect").innerHTML = "";
@ -1570,4 +1620,18 @@ function resetDomValues() {
getId("errorBtn").style.display = "none";
getId("errorDetails").style.display = "none";
getId("errorDetails").textContent = "";
}
function logYtDlpPresent(ytDlpPath) {
console.log("yt-dlp bin is present");
console.log(ytDlpPath);
}
function hidePasteBtn() {
getId("pasteUrl").style.display = "none"
}
function setLocalStorageYtDlp(ytDlpPath) {
localStorage.setItem("ytdlp", ytDlpPath)
}
Loading…
Cancel
Save