Use node as js runtime for yt-dlp

pull/359/head
aandrew-me 7 days ago
parent 8e3a38fea3
commit b459d487c7

4
.gitignore vendored

@ -4,8 +4,10 @@ test.js
.* .*
!/.gitignore !/.gitignore
todo.txt todo.txt
ffmpeg ffmpeg*
ffmpeg.exe ffmpeg.exe
generated-sources.json generated-sources.json
ffmpeg.patch ffmpeg.patch
deno* deno*
node.exe
node

@ -7,8 +7,8 @@ if ! command -V curl > /dev/null 2>&1; then
fi fi
wget "https://github.com/aandrew-me/ffmpeg-builds/releases/download/v8/ffmpeg_linux_amd64.tar.xz" wget "https://github.com/aandrew-me/ffmpeg-builds/releases/download/v8/ffmpeg_linux_amd64.tar.xz"
wget "https://github.com/aandrew-me/ffmpeg-builds/releases/download/v8/deno_linux_amd64" -O deno wget "https://github.com/aandrew-me/ffmpeg-builds/releases/download/v8/node_linux_amd64" -O node
chmod +x deno chmod +x node
tar -xf ffmpeg_linux_amd64.tar.xz tar -xf ffmpeg_linux_amd64.tar.xz
mv ffmpeg_linux_amd64 ffmpeg mv ffmpeg_linux_amd64 ffmpeg
chmod +x ffmpeg/bin/ffmpeg chmod +x ffmpeg/bin/ffmpeg

@ -51,7 +51,7 @@
"./ffmpeg/**/*", "./ffmpeg/**/*",
"!ffmpeg.patch", "!ffmpeg.patch",
"translations", "translations",
"deno*" "node*"
], ],
"electronLanguages": [ "electronLanguages": [
"en-US" "en-US"

@ -14,7 +14,7 @@ const playlistDownloader = {
ytDlpPath: null, ytDlpPath: null,
ytDlpWrap: null, ytDlpWrap: null,
ffmpegPath: null, ffmpegPath: null,
denoPath: null, jsRuntimePath: null,
playlistName: "", playlistName: "",
originalCount: 0, originalCount: 0,
currentDownloadProcess: null, currentDownloadProcess: null,
@ -123,9 +123,9 @@ const playlistDownloader = {
localStorage.setItem("downloadPath", defaultDownloadsDir); localStorage.setItem("downloadPath", defaultDownloadsDir);
} }
// ffmpeg and deno path setup // ffmpeg and js runtime path setup
this.state.ffmpegPath = this.getFfmpegPath(); this.state.ffmpegPath = this.getFfmpegPath();
this.state.denoPath = this.getJsRuntimePath(); this.state.jsRuntimePath = this.getJsRuntimePath();
if (localStorage.getItem("preferredVideoQuality")) { if (localStorage.getItem("preferredVideoQuality")) {
this.ui.videoQualitySelect.value = localStorage.getItem( this.ui.videoQualitySelect.value = localStorage.getItem(
@ -263,8 +263,8 @@ const playlistDownloader = {
`"${start}:${end}"`, `"${start}:${end}"`,
"--ffmpeg-location", "--ffmpeg-location",
`"${this.state.ffmpegPath}"`, `"${this.state.ffmpegPath}"`,
...(this.state.denoPath ...(this.state.jsRuntimePath
? ["--no-js-runtimes", "--js-runtime", this.state.denoPath] ? ["--no-js-runtimes", "--js-runtime", this.state.jsRuntimePath]
: []), : []),
this.config.cookie.arg, this.config.cookie.arg,
this.config.cookie.browser, this.config.cookie.browser,
@ -658,19 +658,41 @@ const playlistDownloader = {
}, },
getJsRuntimePath() { getJsRuntimePath() {
if ( {
process.env.YTDOWNLOADER_DENO_PATH && const exeName = "node";
fs.existsSync(process.env.YTDOWNLOADER_DENO_PATH)
) {
return `deno:"${process.env.YTDOWNLOADER_DENO_PATH}"`;
}
if (os.platform() === "darwin") return ""; if (process.env.YTDOWNLOADER_NODE_PATH) {
if (fs.existsSync(process.env.YTDOWNLOADER_NODE_PATH)) {
return `$node:"${process.env.YTDOWNLOADER_NODE_PATH}"`;
}
let denoExe = os.platform() === "win32" ? "deno.exe" : "deno"; return "";
const denoPath = path.join(__dirname, "..", denoExe); }
if (process.env.YTDOWNLOADER_DENO_PATH) {
if (fs.existsSync(process.env.YTDOWNLOADER_DENO_PATH)) {
return `$deno:"${process.env.YTDOWNLOADER_DENO_PATH}"`;
}
return "";
}
return fs.existsSync(denoPath) ? `deno:"${denoPath}"` : ""; if (os.platform() === "darwin") {
return "";
}
let jsRuntimePath = path.join(__dirname, "..", exeName);
if (os.platform() === "win32") {
jsRuntimePath = path.join(__dirname, "..", `${exeName}.exe`);
}
if (fs.existsSync(jsRuntimePath)) {
return `${exeName}:"${jsRuntimePath}"`;
} else {
return "";
}
}
}, },
}; };

@ -483,9 +483,19 @@ class YtDownloaderApp {
* @returns {Promise<string>} A promise that resolves with the JS runtime path. * @returns {Promise<string>} A promise that resolves with the JS runtime path.
*/ */
async _getJsRuntimePath() { async _getJsRuntimePath() {
const exeName = "node";
if (process.env.YTDOWNLOADER_NODE_PATH) {
if (existsSync(process.env.YTDOWNLOADER_NODE_PATH)) {
return `$node:"${process.env.YTDOWNLOADER_NODE_PATH}"`;
}
return "";
}
if (process.env.YTDOWNLOADER_DENO_PATH) { if (process.env.YTDOWNLOADER_DENO_PATH) {
if (existsSync(process.env.YTDOWNLOADER_DENO_PATH)) { if (existsSync(process.env.YTDOWNLOADER_DENO_PATH)) {
return `deno:"${process.env.YTDOWNLOADER_DENO_PATH}"`; return `$deno:"${process.env.YTDOWNLOADER_DENO_PATH}"`;
} }
return ""; return "";
@ -495,14 +505,14 @@ class YtDownloaderApp {
return ""; return "";
} }
let denoPath = join(__dirname, "..", "deno"); let jsRuntimePath = join(__dirname, "..", exeName);
if (platform() === "win32") { if (platform() === "win32") {
denoPath = join(__dirname, "..", "deno.exe"); jsRuntimePath = join(__dirname, "..", `${exeName}.exe`);
} }
if (existsSync(denoPath)) { if (existsSync(jsRuntimePath)) {
return `deno:"${denoPath}"`; return `${exeName}:"${jsRuntimePath}"`;
} else { } else {
return ""; return "";
} }

@ -1,4 +1,4 @@
Invoke-WebRequest -Uri "https://github.com/aandrew-me/ffmpeg-builds/releases/download/v8/deno.exe" -OutFile deno.exe Invoke-WebRequest -Uri "https://github.com/aandrew-me/ffmpeg-builds/releases/download/v8/node.exe" -OutFile node.exe
Invoke-WebRequest -Uri "https://github.com/aandrew-me/ffmpeg-builds/releases/download/v8/ffmpeg_win64.zip" -OutFile ffmpeg_win64.zip Invoke-WebRequest -Uri "https://github.com/aandrew-me/ffmpeg-builds/releases/download/v8/ffmpeg_win64.zip" -OutFile ffmpeg_win64.zip
Expand-Archive -Path ffmpeg_win64.zip -DestinationPath . Expand-Archive -Path ffmpeg_win64.zip -DestinationPath .
Remove-Item -Path ffmpeg_win64.zip Remove-Item -Path ffmpeg_win64.zip

Loading…
Cancel
Save