Add js runtime support and some fixes

pull/351/head
aandrew-me 2 weeks ago committed by Andrew
parent 184244209e
commit 5a80e010da

3
.gitignore vendored

@ -7,4 +7,5 @@ todo.txt
ffmpeg
ffmpeg.exe
generated-sources.json
ffmpeg.patch
ffmpeg.patch
deno*

@ -16,7 +16,6 @@
</head>
<body>
<div id="popupBox">
<div id="popup">
<p data-translate="downloadingNecessaryFilesWait">Please wait, necessary files are being downloaded</p>
@ -102,7 +101,7 @@
<p id="incorrectMsg"></p>
<button class="advancedToggle" id="errorBtn" onclick="toggleErrorDetails()" data-translate="errorDetails">Error
Details ▼</button>
<div id="errorDetails" onclick="copyErrorToClipboard()"></div>
<div id="errorDetails"></div>
<br>
<div id="hidden">

@ -39,9 +39,6 @@
</head>
<body>
<!-- Popup message -->
<span id="popupText" data-translate="copiedText">Text copied</span>
<!-- Menu icon -->
<img src="../assets/images/menu.png" alt="menu" id="menuIcon">
@ -88,7 +85,7 @@
<span id="link"></span>
<br><br>
<div id="videoBox">
<label id="videoFormat" data-translate="selectVideoFormat">Select Video Format </label>
<label id="videoFormat" data-translate="videoQuality">Select Video Quality </label>
<select id="select" class="select">
<option value="best" id="bestVideoOption" data-translate="best">Best</option>
<option value="worst" id="worstVideoOption" data-translate="qualityWorst">Worst</option>
@ -105,7 +102,7 @@
</select>
<br>
<div id="typeSelectBox">
<label id="videoQualityTxt" data-translate="videoQuality">Select video quality</label>
<label id="videoQualityTxt" data-translate="selectVideoFormat">Select video quality</label>
<select id="videoTypeSelect" class="select">
<option value="auto" id="autoTxt" data-translate="auto">Auto</option>
<option value="mp4">Mp4</option>
@ -185,7 +182,7 @@
<!-- Error button -->
<button class="advancedToggle" id="errorBtn" onclick="toggleErrorDetails()" data-translate="errorDetails">Error
Details ▼</button>
<div id="errorDetails" onclick="copyErrorToClipboard()"></div>
<div id="errorDetails"></div>
</div>

@ -53,7 +53,8 @@
"./src/*.js",
"ffmpeg*",
"!ffmpeg.patch",
"translations"
"translations",
"deno*"
],
"electronLanguages": [
"en-US"

@ -110,28 +110,10 @@ function toggleErrorDetails() {
if (status === "none") {
getId("errorDetails").style.display = "block";
// @ts-ignore
getId("errorBtn").textContent = i18n.__("Error Details") + " ▲";
getId("errorBtn").textContent = i18n.__("errorDetails") + " ▲";
} else {
getId("errorDetails").style.display = "none";
// @ts-ignore
getId("errorBtn").textContent = i18n.__("Error Details") + " ▼";
getId("errorBtn").textContent = i18n.__("errorDetails") + " ▼";
}
}
// Copying error txt
function copyErrorToClipboard() {
const error = getId("errorDetails").textContent;
electron.clipboard.writeText(error);
// @ts-ignore
showPopup(i18n.__("Copied text"));
}
// Popup message
function showPopup(text) {
getId("popupText").textContent = text;
getId("popupText").style.display = "inline-block";
setTimeout(() => {
getId("popupText").style.display = "none";
}, 2200);
}
}

@ -12,7 +12,6 @@ const ytdlp = new YTDlpWrap(`"${ytDlp}"`);
const downloadsDir = path.join(os.homedir(), "Downloads");
let downloadDir = localStorage.getItem("downloadPath") || downloadsDir;
document.addEventListener("translations-loaded", () => {
window.i18n.translatePage();
});
@ -62,6 +61,8 @@ if (os.platform() === "win32") {
ffmpegPath = `${__dirname}/../ffmpeg`;
}
let denoPath = getJsRuntimePath();
if (process.env.YTDOWNLOADER_FFMPEG_PATH) {
ffmpegPath = `${process.env.YTDOWNLOADER_FFMPEG_PATH}`;
@ -207,6 +208,9 @@ function download(type) {
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
ffmpeg,
denoPath
? `--no-js-runtimes --js-runtime ${denoPath}`
: "",
cookieArg,
browser,
configArg,
@ -252,6 +256,9 @@ function download(type) {
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
ffmpeg,
denoPath
? `--no-js-runtimes --js-runtime ${denoPath}`
: "",
cookieArg,
browser,
configArg,
@ -290,6 +297,9 @@ function download(type) {
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
ffmpeg,
denoPath
? `--no-js-runtimes --js-runtime ${denoPath}`
: "",
cookieArg,
browser,
configArg,
@ -482,6 +492,9 @@ function downloadThumbnails() {
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
ffmpeg,
denoPath
? `--no-js-runtimes --js-runtime ${denoPath}`
: "",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
@ -609,6 +622,32 @@ function saveLinks() {
});
}
function getJsRuntimePath() {
if (process.env.YTDOWNLOADER_DENO_PATH) {
if (fs.existsSync(process.env.YTDOWNLOADER_DENO_PATH)) {
return `deno:"${process.env.YTDOWNLOADER_DENO_PATH}"`;
}
return "";
}
let denoPath = path.join(__dirname, "..", "deno");
if (os.platform() === "win32") {
denoPath = path.join(__dirname, "..", "deno.exe");
}
if (os.platform() === "darwin") {
return "";
} else {
if (fs.existsSync(denoPath)) {
return `deno:"${denoPath}"`;
} else {
return "";
}
}
}
// Downloading video
getId("download").addEventListener("click", () => {
download("video");

@ -87,6 +87,7 @@ class YtDownloaderApp {
ytDlp: null,
ytDlpPath: "",
ffmpegPath: "",
jsRuntimePath: "",
downloadDir: "",
maxActiveDownloads: 5,
currentDownloads: 0,
@ -136,9 +137,11 @@ class YtDownloaderApp {
this.state.ytDlpPath = await this._findOrDownloadYtDlp();
this.state.ytDlp = new YTDlpWrap(this.state.ytDlpPath);
this.state.ffmpegPath = await this._findFfmpeg();
this.state.jsRuntimePath = await this._getJsRuntimePath();
console.log("yt-dlp path:", this.state.ytDlpPath);
console.log("ffmpeg path:", this.state.ffmpegPath);
console.log("JS runtime path:", this.state.jsRuntimePath);
this._loadSettings();
this._addEventListeners();
@ -347,9 +350,14 @@ class YtDownloaderApp {
console.log("yt-dlp update check:", data.toString());
if (data.toString().toLowerCase().includes("updating to")) {
this._showPopup(i18n.__("updatingYtdlp"))
} else if (data.toString().toLowerCase().includes("updated yt-dlp to")) {
this._showPopup(i18n.__("updatedYtdlp"))
this._showPopup(i18n.__("updatingYtdlp"));
} else if (
data
.toString()
.toLowerCase()
.includes("updated yt-dlp to")
) {
this._showPopup(i18n.__("updatedYtdlp"));
}
});
} catch {
@ -420,6 +428,36 @@ class YtDownloaderApp {
: join(__dirname, "..", "ffmpeg");
}
/**
* Determines the JavaScript runtime path for yt-dlp.
* @returns {Promise<string>} A promise that resolves with the JS runtime path.
*/
async _getJsRuntimePath() {
if (process.env.YTDOWNLOADER_DENO_PATH) {
if (existsSync(process.env.YTDOWNLOADER_DENO_PATH)) {
return `deno:"${process.env.YTDOWNLOADER_DENO_PATH}"`;
}
return "";
}
if (platform() === "darwin") {
return "";
}
let denoPath = join(__dirname, "..", "deno");
if (platform() === "win32") {
denoPath = join(__dirname, "..", "deno.exe");
}
if (existsSync(denoPath)) {
return `deno:"${denoPath}"`;
} else {
return "";
}
}
/**
* Loads various settings from localStorage into the application state.
*/
@ -604,7 +642,14 @@ class YtDownloaderApp {
this._populateFormatSelectors(metadata.formats || []);
this._displayInfoPanel();
} catch (error) {
this._showError(error.message, url);
if (
error.message.includes("js-runtimes") &&
error.message.includes("no such option")
) {
this._showError(i18n.__("ytDlpUpdateRequired"), url);
} else {
this._showError(error.message, url);
}
} finally {
$(CONSTANTS.DOM_IDS.LOADING_WRAPPER).style.display = "none";
}
@ -661,6 +706,9 @@ class YtDownloaderApp {
proxy,
browserForCookies ? "--cookies-from-browser" : "",
browserForCookies,
this.state.jsRuntimePath
? `--no-js-runtimes --js-runtime ${this.state.jsRuntimePath}`
: "",
configPath ? "--config-location" : "",
configPath ? `"${configPath}"` : "",
`"${url}"`,
@ -671,7 +719,9 @@ class YtDownloaderApp {
let stdout = "";
let stderr = "";
process.ytDlpProcess.stdout.on("data", (data) => (stdout += data));
process.ytDlpProcess.stdout.on("data", (data) => {
stdout += data;
});
process.ytDlpProcess.stderr.on("data", (data) => (stderr += data));
process.on("close", () => {
@ -735,6 +785,9 @@ class YtDownloaderApp {
const el = $(`${randomId}_prog`);
if (el) el.textContent = i18n.__("downloading");
})
// .on("ytDlpEvent", (eventType, eventData) => {
// console.log(eventData)
// })
.once("close", (code) => {
this._handleDownloadCompletion(
code,
@ -871,6 +924,10 @@ class YtDownloaderApp {
configPath ? `"${configPath}"` : "",
"--ffmpeg-location",
`"${this.state.ffmpegPath}"`,
this.state.jsRuntimePath
? `--no-js-runtimes --js-runtime ${this.state.jsRuntimePath}`
: "",
`"${url}"`,
].filter(Boolean);
@ -1362,7 +1419,7 @@ class YtDownloaderApp {
if (popupContainer.childElementCount === 0) {
popupContainer.remove();
}
}, 400);
}, 1000);
}, 2200);
}

@ -154,5 +154,6 @@
"confirmClearAllHistory": "Are you sure you want to clear all download history? This cannot be undone!",
"fileDoesNotExist": "File does not exist anymore",
"updatingYtdlp": "Updating yt-dlp",
"updatedYtdlp": "Updated yt-dlp"
"updatedYtdlp": "Updated yt-dlp",
"ytDlpUpdateRequired": "If yt-dlp is updating, wait for the update to finish. If you have installed yt-dlp by yourself, please update it."
}

Loading…
Cancel
Save