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));
border-radius: 8px;
}
#proxyTxt:valid {
border: 2px solid var(--greenBtn);
}
#proxyTxt:invalid {
border: 2px solid var(--redBtn);
}

@ -128,6 +128,13 @@
</select>
</div>
<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 class="configBox">

4
package-lock.json generated

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

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

@ -69,6 +69,7 @@ let foldernameFormat = "%(playlist_title)s";
let filenameFormat = "%(playlist_index)s.%(title)s.%(ext)s";
let playlistIndex = 1;
let playlistEnd = "";
let proxy = ""
/**
*
@ -113,6 +114,9 @@ function download(type) {
configArg = "--config-location";
configTxt = `"${localStorage.getItem("configPath")}"`;
}
proxy = localStorage.getItem("proxy") || "";
console.log("Proxy:", proxy)
nameFormatting();
originalCount = 0;
@ -174,12 +178,54 @@ function download(type) {
const controller = new AbortController();
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(
[
format,
args,
{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",
"--no-warnings",
"-f",
`ba[ext=${format}]/ba`,
"-o",
`"${path.join(downloadDir, foldernameFormat, filenameFormat)}"`,
`"${path.join(
downloadDir,
foldernameFormat,
filenameFormat
)}"`,
"-I",
`"${playlistIndex}:${playlistEnd}"`,
"--ffmpeg-location",
@ -191,87 +237,62 @@ function download(type) {
"--embed-metadata",
subs,
subLangs,
videoType == "mp4" ? "--embed-thumbnail" : "",
"--embed-thumbnail",
proxy ? "--no-check-certificate" : "",
proxy ? "--proxy" : "",
proxy,
`"${url}"`,
],
{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")
].filter(item => item);
downloadProcess = ytdlp.exec(
[
"--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}"`,
],
args,
{shell: true, detached: false},
controller.signal
);
} else {
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(
[
"--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}"`,
],
args,
{shell: true, detached: false},
controller.signal
);
}
}
downloadProcess.on("ytDlpEvent", (eventType, eventData) => {
downloadProcess.on("ytDlpEvent", (_eventType, eventData) => {
// console.log(eventData);
if (eventData.includes(playlistTxt)) {
@ -409,23 +430,29 @@ function downloadThumbnails() {
hideOptions();
nameFormatting();
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(
[
"--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}"`,
],
args,
{shell: true, detached: false}
);
@ -479,21 +506,27 @@ function saveLinks() {
hideOptions();
nameFormatting();
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(
[
"--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}"`,
],
args,
{shell: true, detached: false}
);

@ -138,6 +138,17 @@ getId("preferredVideoCodec").addEventListener("change", () => {
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
function reload() {
ipcRenderer.send("reload");

@ -70,6 +70,7 @@ let maxActiveDownloads = 5;
let showMoreFormats = false;
let configArg = "";
let configTxt = "";
let proxy = "";
if (localStorage.getItem("configPath")) {
configArg = "--config-location";
@ -319,6 +320,8 @@ async function getInfo(url) {
showMoreFormats = false;
}
proxy = getLocalStorageItem("proxy");
// Whether to use browser cookies or not
if (localStorage.getItem("browser")) {
browser = localStorage.getItem("browser");
@ -336,18 +339,23 @@ async function getInfo(url) {
// Twitter/X compatibility
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(
`"${ytDlp}"`,
[
"-j",
"--no-playlist",
"--no-warnings",
cookieArg,
browser,
configArg,
configTxt,
`"${url}"`,
],
infoOptions,
{
shell: true,
}
@ -1082,28 +1090,33 @@ function download(
// If video has no sound, audio needs to be downloaded
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(
[
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}"`,
],
args,
{shell: true, detached: false},
controller.signal
);
@ -1121,29 +1134,34 @@ function download(
console.log(extractFormat1);
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(
[
"-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}"`,
],
args,
{shell: true, detached: false},
controller.signal
);
@ -1152,28 +1170,33 @@ function download(
else {
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(
[
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}"`,
],
args,
{shell: true, detached: false},
controller.signal
);
@ -1344,6 +1367,15 @@ function showPopup(text) {
}, 2200);
}
/**
*
* @param {string} item
* @returns string
*/
function getLocalStorageItem(item) {
return localStorage.getItem(item) || "";
}
// Menu
getId("preferenceWin").addEventListener("click", () => {
closeMenu();

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

@ -110,5 +110,6 @@
"Preferred video codec": "Preferred video codec",
"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'",
"No Audio":"No Audio"
"No Audio":"No Audio",
"Proxy": "Proxy"
}

Loading…
Cancel
Save