Add proxy support

pull/220/head
aandrew-me 2 years ago
parent 131f359fe2
commit aeef6b351d

@ -297,3 +297,11 @@ body::-webkit-scrollbar-thumb {
background: linear-gradient(rgb(110, 110, 110), rgb(77, 77, 77)); background: linear-gradient(rgb(110, 110, 110), rgb(77, 77, 77));
border-radius: 8px; border-radius: 8px;
} }
#proxyTxt:valid {
border: 2px solid var(--greenBtn);
}
#proxyTxt:invalid {
border: 2px solid var(--redBtn);
}

@ -128,6 +128,13 @@
</select> </select>
</div> </div>
<br> <br>
<div class="prefBox">
<span id="proxyTitle">Proxy</span>
<input type="text" id="proxyTxt" placeholder="Example: http://localhost:8080" pattern="^(http:\/\/|https:\/\/|socks5:\/\/)?[a-zA-Z0-9.]+:[\d]+$">
</div>
<br>
<div id="pathConfig"> <div id="pathConfig">
<div class="configBox"> <div class="configBox">

4
package-lock.json generated

@ -1,12 +1,12 @@
{ {
"name": "ytdownloader", "name": "ytdownloader",
"version": "3.17.0", "version": "3.17.4",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ytdownloader", "name": "ytdownloader",
"version": "3.17.0", "version": "3.17.4",
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"electron-updater": "^5.3.0", "electron-updater": "^5.3.0",

@ -4,7 +4,7 @@
"yt-dlp-wrap-plus": "^2.3.18" "yt-dlp-wrap-plus": "^2.3.18"
}, },
"name": "ytdownloader", "name": "ytdownloader",
"version": "3.17.4", "version": "3.17.5",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"start": "electron .", "start": "electron .",

@ -69,6 +69,7 @@ let foldernameFormat = "%(playlist_title)s";
let filenameFormat = "%(playlist_index)s.%(title)s.%(ext)s"; let filenameFormat = "%(playlist_index)s.%(title)s.%(ext)s";
let playlistIndex = 1; let playlistIndex = 1;
let playlistEnd = ""; let playlistEnd = "";
let proxy = ""
/** /**
* *
@ -113,6 +114,9 @@ function download(type) {
configArg = "--config-location"; configArg = "--config-location";
configTxt = `"${localStorage.getItem("configPath")}"`; configTxt = `"${localStorage.getItem("configPath")}"`;
} }
proxy = localStorage.getItem("proxy") || "";
console.log("Proxy:", proxy)
nameFormatting(); nameFormatting();
originalCount = 0; originalCount = 0;
@ -174,12 +178,54 @@ function download(type) {
const controller = new AbortController(); const controller = new AbortController();
if (type === "video") { if (type === "video") {
const args = [
format,
"--yes-playlist",
"-o",
`"${path.join(downloadDir, foldernameFormat, filenameFormat)}"`,
"-I",
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
ffmpeg,
cookieArg,
browser,
configArg,
configTxt,
"--embed-metadata",
subs,
subLangs,
videoType == "mp4" ? "--embed-thumbnail" : "",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
`"${url}"`,
].filter(item => item);
downloadProcess = ytdlp.exec( downloadProcess = ytdlp.exec(
[ args,
format, {shell: true, detached: false},
controller.signal
);
} else {
// Youtube provides m4a as audio, so no need to convert
if (
(url.includes("youtube.com/") || url.includes("youtu.be/")) &&
format === "m4a" &&
audioQuality === "auto"
) {
console.log("Downloading m4a without extracting")
const args = [
"--yes-playlist", "--yes-playlist",
"--no-warnings",
"-f",
`ba[ext=${format}]/ba`,
"-o", "-o",
`"${path.join(downloadDir, foldernameFormat, filenameFormat)}"`, `"${path.join(
downloadDir,
foldernameFormat,
filenameFormat
)}"`,
"-I", "-I",
`"${playlistIndex}:${playlistEnd}"`, `"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location", "--ffmpeg-location",
@ -191,87 +237,62 @@ function download(type) {
"--embed-metadata", "--embed-metadata",
subs, subs,
subLangs, subLangs,
videoType == "mp4" ? "--embed-thumbnail" : "", "--embed-thumbnail",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
`"${url}"`, `"${url}"`,
], ].filter(item => item);
{shell: true, detached: false},
controller.signal
);
} else {
// Youtube provides m4a as audio, so no need to convert
if (
(url.includes("youtube.com/") || url.includes("youtu.be/")) &&
format === "m4a" &&
audioQuality === "auto"
) {
console.log("Downloading m4a without extracting")
downloadProcess = ytdlp.exec( downloadProcess = ytdlp.exec(
[ args,
"--yes-playlist",
"--no-warnings",
"-f",
`ba[ext=${format}]/ba`,
"-o",
`"${path.join(
downloadDir,
foldernameFormat,
filenameFormat
)}"`,
"-I",
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
ffmpeg,
cookieArg,
browser,
configArg,
configTxt,
"--embed-metadata",
subs,
subLangs,
"--embed-thumbnail",
`"${url}"`,
],
{shell: true, detached: false}, {shell: true, detached: false},
controller.signal controller.signal
); );
} else { } else {
console.log("Extracting audio") console.log("Extracting audio")
const args = [
"--yes-playlist",
"--no-warnings",
"-x",
"--audio-format",
format,
"--audio-quality",
audioQuality,
"-o",
`"${path.join(
downloadDir,
foldernameFormat,
filenameFormat
)}"`,
"-I",
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
ffmpeg,
cookieArg,
browser,
configArg,
configTxt,
"--embed-metadata",
subs,
subLangs,
format === "mp3" || format === "m4a" ? "--embed-thumbnail" : "",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
`"${url}"`,
].filter(item => item);
downloadProcess = ytdlp.exec( downloadProcess = ytdlp.exec(
[ args,
"--yes-playlist",
"--no-warnings",
"-x",
"--audio-format",
format,
"--audio-quality",
audioQuality,
"-o",
`"${path.join(
downloadDir,
foldernameFormat,
filenameFormat
)}"`,
"-I",
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
ffmpeg,
cookieArg,
browser,
configArg,
configTxt,
"--embed-metadata",
subs,
subLangs,
format === "mp3" || format === "m4a" ? "--embed-thumbnail" : "",
`"${url}"`,
],
{shell: true, detached: false}, {shell: true, detached: false},
controller.signal controller.signal
); );
} }
} }
downloadProcess.on("ytDlpEvent", (eventType, eventData) => { downloadProcess.on("ytDlpEvent", (_eventType, eventData) => {
// console.log(eventData); // console.log(eventData);
if (eventData.includes(playlistTxt)) { if (eventData.includes(playlistTxt)) {
@ -409,23 +430,29 @@ function downloadThumbnails() {
hideOptions(); hideOptions();
nameFormatting(); nameFormatting();
managePlaylistRange(); managePlaylistRange();
const args = [
"--yes-playlist",
"--no-warnings",
"-o",
`"${path.join(downloadDir, foldernameFormat, filenameFormat)}"`,
cookieArg,
browser,
"--write-thumbnail",
"--convert-thumbnails png",
"--skip-download",
"-I",
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
ffmpeg,
proxy ? "--no-check-certificate" : "",
"--proxy",
proxy,
`"${url}"`,
].filter(item => item);
const downloadProcess = ytdlp.exec( const downloadProcess = ytdlp.exec(
[ args,
"--yes-playlist",
"--no-warnings",
"-o",
`"${path.join(downloadDir, foldernameFormat, filenameFormat)}"`,
cookieArg,
browser,
"--write-thumbnail",
"--convert-thumbnails png",
"--skip-download",
"-I",
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
ffmpeg,
`"${url}"`,
],
{shell: true, detached: false} {shell: true, detached: false}
); );
@ -479,21 +506,27 @@ function saveLinks() {
hideOptions(); hideOptions();
nameFormatting(); nameFormatting();
managePlaylistRange(); managePlaylistRange();
const args = [
"--yes-playlist",
"--no-warnings",
cookieArg,
browser,
"--skip-download",
"--print-to-file",
"webpage_url",
`"${path.join(downloadDir, foldernameFormat, "links.txt")}"`,
"--skip-download",
"-I",
`"${playlistIndex}:${playlistEnd}"`,
proxy ? "--no-check-certificate" : "",
"--proxy",
proxy,
`"${url}"`,
].filter(item => item);
const downloadProcess = ytdlp.exec( const downloadProcess = ytdlp.exec(
[ args,
"--yes-playlist",
"--no-warnings",
cookieArg,
browser,
"--skip-download",
"--print-to-file",
"webpage_url",
`"${path.join(downloadDir, foldernameFormat, "links.txt")}"`,
"--skip-download",
"-I",
`"${playlistIndex}:${playlistEnd}"`,
`"${url}"`,
],
{shell: true, detached: false} {shell: true, detached: false}
); );

@ -138,6 +138,17 @@ getId("preferredVideoCodec").addEventListener("change", () => {
localStorage.setItem("preferredVideoCodec", preferredVideoCodec); localStorage.setItem("preferredVideoCodec", preferredVideoCodec);
}); });
// Proxy
let proxy = localStorage.getItem("proxy");
if (proxy) {
getId("proxyTxt").value = proxy;
}
getId("proxyTxt").addEventListener("change", () => {
proxy = getId("proxyTxt").value;
localStorage.setItem("proxy", proxy);
});
// Reload // Reload
function reload() { function reload() {
ipcRenderer.send("reload"); ipcRenderer.send("reload");

@ -70,6 +70,7 @@ let maxActiveDownloads = 5;
let showMoreFormats = false; let showMoreFormats = false;
let configArg = ""; let configArg = "";
let configTxt = ""; let configTxt = "";
let proxy = "";
if (localStorage.getItem("configPath")) { if (localStorage.getItem("configPath")) {
configArg = "--config-location"; configArg = "--config-location";
@ -319,6 +320,8 @@ async function getInfo(url) {
showMoreFormats = false; showMoreFormats = false;
} }
proxy = getLocalStorageItem("proxy");
// Whether to use browser cookies or not // Whether to use browser cookies or not
if (localStorage.getItem("browser")) { if (localStorage.getItem("browser")) {
browser = localStorage.getItem("browser"); browser = localStorage.getItem("browser");
@ -336,18 +339,23 @@ async function getInfo(url) {
// Twitter/X compatibility // Twitter/X compatibility
url = url.replace("//x.com/", "//twitter.com/") url = url.replace("//x.com/", "//twitter.com/")
const infoOptions = [
"-j",
"--no-playlist",
"--no-warnings",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
cookieArg,
browser,
configArg,
configTxt,
`"${url}"`,
].filter(item => item)
const infoProcess = cp.spawn( const infoProcess = cp.spawn(
`"${ytDlp}"`, `"${ytDlp}"`,
[ infoOptions,
"-j",
"--no-playlist",
"--no-warnings",
cookieArg,
browser,
configArg,
configTxt,
`"${url}"`,
],
{ {
shell: true, shell: true,
} }
@ -1082,28 +1090,33 @@ function download(
// If video has no sound, audio needs to be downloaded // If video has no sound, audio needs to be downloaded
console.log("Downloading both video and audio"); console.log("Downloading both video and audio");
const args = [
range1 || rangeOption,
range2 || rangeCmd,
"-f",
`${format_id}${audioFormat}`,
"-o",
`"${path.join(downloadDir, filename + `.${ext}`)}"`,
"--ffmpeg-location",
ffmpeg,
subs1 || subs,
subs2 || subLangs,
"--no-playlist",
"--embed-metadata",
ext == "mp4" && audioForVideoExt === "m4a" ? "--embed-thumbnail" : "",
configArg,
configTxt,
cookieArg,
browser,
"--no-mtime",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
`"${url}"`,
].filter(item => item);
downloadProcess = ytdlp.exec( downloadProcess = ytdlp.exec(
[ args,
range1 || rangeOption,
range2 || rangeCmd,
"-f",
`${format_id}${audioFormat}`,
"-o",
`"${path.join(downloadDir, filename + `.${ext}`)}"`,
"--ffmpeg-location",
ffmpeg,
subs1 || subs,
subs2 || subLangs,
"--no-playlist",
"--embed-metadata",
ext == "mp4" && audioForVideoExt === "m4a" ? "--embed-thumbnail" : "",
configArg,
configTxt,
cookieArg,
browser,
"--no-mtime",
`"${url}"`,
],
{shell: true, detached: false}, {shell: true, detached: false},
controller.signal controller.signal
); );
@ -1121,29 +1134,34 @@ function download(
console.log(extractFormat1); console.log(extractFormat1);
console.log(extractQuality1); console.log(extractQuality1);
const args = [
"-x",
"--audio-format",
extractFormat1,
"--audio-quality",
extractQuality1,
"-o",
`"${path.join(downloadDir, filename + `.${extractExt}`)}"`,
"--ffmpeg-location",
ffmpeg,
"--no-playlist",
"--embed-metadata",
extractFormat1 == "m4a" || extractFormat1 == "mp3"
? "--embed-thumbnail"
: "",
cookieArg,
browser,
configArg,
configTxt,
"--no-mtime",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
`"${url}"`,
].filter(item => item)
downloadProcess = ytdlp.exec( downloadProcess = ytdlp.exec(
[ args,
"-x",
"--audio-format",
extractFormat1,
"--audio-quality",
extractQuality1,
"-o",
`"${path.join(downloadDir, filename + `.${extractExt}`)}"`,
"--ffmpeg-location",
ffmpeg,
"--no-playlist",
"--embed-metadata",
extractFormat1 == "m4a" || extractFormat1 == "mp3"
? "--embed-thumbnail"
: "",
cookieArg,
browser,
configArg,
configTxt,
"--no-mtime",
`"${url}"`,
],
{shell: true, detached: false}, {shell: true, detached: false},
controller.signal controller.signal
); );
@ -1152,28 +1170,33 @@ function download(
else { else {
console.log("downloading only audio or video with audio"); console.log("downloading only audio or video with audio");
const args = [
range1 || rangeOption,
range2 || rangeCmd,
"-f",
format_id,
"-o",
`"${path.join(downloadDir, filename + `.${ext}`)}"`,
"--ffmpeg-location",
ffmpeg,
subs1 || subs,
subs2 || subLangs,
"--no-playlist",
"--embed-metadata",
ext == "m4a" || ext == "mp4" ? "--embed-thumbnail" : "",
cookieArg,
browser,
configArg,
configTxt,
"--no-mtime",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
`"${url}"`,
].filter(item => item)
downloadProcess = ytdlp.exec( downloadProcess = ytdlp.exec(
[ args,
range1 || rangeOption,
range2 || rangeCmd,
"-f",
format_id,
"-o",
`"${path.join(downloadDir, filename + `.${ext}`)}"`,
"--ffmpeg-location",
ffmpeg,
subs1 || subs,
subs2 || subLangs,
"--no-playlist",
"--embed-metadata",
ext == "m4a" || ext == "mp4" ? "--embed-thumbnail" : "",
cookieArg,
browser,
configArg,
configTxt,
"--no-mtime",
`"${url}"`,
],
{shell: true, detached: false}, {shell: true, detached: false},
controller.signal controller.signal
); );
@ -1344,6 +1367,15 @@ function showPopup(text) {
}, 2200); }, 2200);
} }
/**
*
* @param {string} item
* @returns string
*/
function getLocalStorageItem(item) {
return localStorage.getItem(item) || "";
}
// Menu // Menu
getId("preferenceWin").addEventListener("click", () => { getId("preferenceWin").addEventListener("click", () => {
closeMenu(); closeMenu();

@ -39,6 +39,7 @@ getId("trayTxt").textContent = i18n.__("Close app to system tray");
getId("autoUpdateTxt").textContent = i18n.__("Disable auto updates"); getId("autoUpdateTxt").textContent = i18n.__("Disable auto updates");
getId("showMoreFormatsTxt").textContent = i18n.__("Show more format options"); getId("showMoreFormatsTxt").textContent = i18n.__("Show more format options");
getId("preferredVideoCodecTxt").textContent = i18n.__("Preferred video codec"); getId("preferredVideoCodecTxt").textContent = i18n.__("Preferred video codec");
getId("proxyTitle").textContent = i18n.__("Proxy");
if (process.env.FLATPAK_ID) { if (process.env.FLATPAK_ID) {
getId("flatpakTxt").textContent = i18n.__( getId("flatpakTxt").textContent = i18n.__(

@ -110,5 +110,6 @@
"Preferred video codec": "Preferred video codec", "Preferred video codec": "Preferred video codec",
"Show more format options": "Show more format options", "Show more format options": "Show more format options",
"You need to give the app permission to access home directory to use this. You can do it with Flatseal by enabling the permission with text 'filesystem=home'": "You need to give the app permission to access home directory to use this. You can do it with Flatseal by enabling the permission with text 'filesystem=home'", "You need to give the app permission to access home directory to use this. You can do it with Flatseal by enabling the permission with text 'filesystem=home'": "You need to give the app permission to access home directory to use this. You can do it with Flatseal by enabling the permission with text 'filesystem=home'",
"No Audio":"No Audio" "No Audio":"No Audio",
"Proxy": "Proxy"
} }

Loading…
Cancel
Save