From 26d5fc4171a948a255101b6a771e13b741a45e2d Mon Sep 17 00:00:00 2001
From: Andrew <66430340+aandrew-me@users.noreply.github.com>
Date: Sun, 24 Dec 2023 18:00:04 +0300
Subject: [PATCH] Translations, Vcodec, More formats option
---
README.md | 3 +-
assets/css/index.css | 2 +-
html/preferences.html | 23 +++++++++++--
src/preferences.js | 27 ++++++++++++++--
src/renderer.js | 75 ++++++++++++++++++++++++++++++++-----------
translations/en.json | 4 ++-
6 files changed, 108 insertions(+), 26 deletions(-)
diff --git a/README.md b/README.md
index 89a6437..9598e5a 100644
--- a/README.md
+++ b/README.md
@@ -129,6 +129,7 @@ Translations into other languages would be highly appreciated. If you want to he
| Greek | ✔️ |
| Hungarian | ✔️ |
| Italian | ✔️ |
+| Japanese | ✔️ |
| Persian | ✔️ |
| Polish | ✔️ |
| Portuguese (Brazil) | ✔️ |
@@ -138,7 +139,7 @@ Translations into other languages would be highly appreciated. If you want to he
| Ukrainian | ✔️ |
| Vietnamese | ✔️ |
-Thanks to [nxjosephofficial](https://github.com/nxjosephofficial), [LINUX-SAUNA](https://t.me/linuxsauna), [Proxycon](https://github.com/proxycon), [albanobattistella](https://github.com/albanobattistella), [TheBlueQuasar](https://github.com/TheBlueQuasar), [MrQuerter](https://github.com/MrQuerter), [KotoWhiskas](https://github.com/KotoWhiskas), [André](https://github.com/andre1828), [haggen88](https://github.com/haggen88), [XfedeX](https://github.com/XfedeX), [Jok3r](https://github.com/th3knv), [TitouanReal](https://github.com/TitouanReal), [soredake](https://github.com/soredake), [yoi](https://github.com/thiennguyenqn), [HowlingWerewolf](https://github.com/HowlingWerewolf) and others for helping.
+Thanks to [nxjosephofficial](https://github.com/nxjosephofficial), [LINUX-SAUNA](https://t.me/linuxsauna), [Proxycon](https://github.com/proxycon), [albanobattistella](https://github.com/albanobattistella), [TheBlueQuasar](https://github.com/TheBlueQuasar), [MrQuerter](https://github.com/MrQuerter), [KotoWhiskas](https://github.com/KotoWhiskas), [André](https://github.com/andre1828), [haggen88](https://github.com/haggen88), [XfedeX](https://github.com/XfedeX), [Jok3r](https://github.com/th3knv), [TitouanReal](https://github.com/TitouanReal), [soredake](https://github.com/soredake), [yoi](https://github.com/thiennguyenqn), [HowlingWerewolf](https://github.com/HowlingWerewolf), [Kum](https://github.com/kum4423) and others for helping.
## Used technologies
diff --git a/assets/css/index.css b/assets/css/index.css
index 7860308..e8601e6 100644
--- a/assets/css/index.css
+++ b/assets/css/index.css
@@ -401,7 +401,7 @@ body {
outline: none;
}
-#videoFormatSelect {
+#videoFormatSelect, #audioFormatSelect {
font-family: JetBrains, monospace;
font-size: medium;
}
diff --git a/html/preferences.html b/html/preferences.html
index 81e6e1d..12ad2e7 100644
--- a/html/preferences.html
+++ b/html/preferences.html
@@ -39,18 +39,18 @@
-
+
+
+
+
+
+
+ Preferred video codec
+
+
@@ -130,8 +143,14 @@
+
+
+ Show more format options
+
+
+
Filename format for playlists
{
});
// Handling preferred video quality
-
let preferredVideoQuality = localStorage.getItem("preferredVideoQuality");
if (preferredVideoQuality) {
getId("preferredVideoQuality").value = preferredVideoQuality;
@@ -113,7 +112,6 @@ getId("preferredVideoQuality").addEventListener("change", () => {
});
// Handling preferred audio quality
-
let preferredAudioQuality = localStorage.getItem("preferredAudioQuality");
if (preferredAudioQuality) {
getId("preferredAudioQuality").value = preferredAudioQuality;
@@ -124,6 +122,17 @@ getId("preferredAudioQuality").addEventListener("change", () => {
localStorage.setItem("preferredAudioQuality", preferredAudioQuality);
});
+// Handling preferred video codec
+let preferredVideoCodec = localStorage.getItem("preferredVideoCodec");
+if (preferredVideoCodec) {
+ getId("preferredVideoCodec").value = preferredVideoCodec;
+}
+
+getId("preferredVideoCodec").addEventListener("change", () => {
+ preferredVideoCodec = getId("preferredVideoCodec").value;
+ localStorage.setItem("preferredVideoCodec", preferredVideoCodec);
+});
+
// Reload
function reload() {
ipcRenderer.send("reload");
@@ -214,5 +223,19 @@ if (autoUpdate == "false"){
autoUpdateDisabled.checked = true;
}
+// Show more format options
+const showMoreFormats = getId("showMoreFormats");
+showMoreFormats.addEventListener("change", (event) => {
+ if (showMoreFormats.checked) {
+ localStorage.setItem("showMoreFormats", "true");
+ } else {
+ localStorage.setItem("showMoreFormats", "false");
+
+ }
+});
+const showMoreFormatOpts = localStorage.getItem("showMoreFormats")
+if (showMoreFormatOpts == "true"){
+ showMoreFormats.checked = true;
+}
// Translation file
require("../src/translate_preferences");
diff --git a/src/renderer.js b/src/renderer.js
index 990d552..49ead98 100644
--- a/src/renderer.js
+++ b/src/renderer.js
@@ -17,19 +17,21 @@ const path = require("path");
const {shell, ipcRenderer, clipboard} = require("electron");
const {default: YTDlpWrap} = require("yt-dlp-wrap-plus");
const {constants} = require("fs/promises");
-const { stdout } = require("process");
+const {stdout} = require("process");
// Directories
const homedir = os.homedir();
let appdir = path.join(homedir, "Downloads");
if (os.platform() === "linux") {
try {
- const xdgDownloadDir = cp.execSync("xdg-user-dir DOWNLOAD").toString().trim()
+ const xdgDownloadDir = cp
+ .execSync("xdg-user-dir DOWNLOAD")
+ .toString()
+ .trim();
if (xdgDownloadDir.length > 1) {
- appdir = xdgDownloadDir
- console.log("xdg download dir:", xdgDownloadDir)
+ appdir = xdgDownloadDir;
+ console.log("xdg download dir:", xdgDownloadDir);
}
-
} catch (err) {}
}
const hiddenDir = path.join(homedir, ".ytDownloader");
@@ -59,7 +61,8 @@ let rangeOption = "--download-sections";
let cookieArg = "";
let browser = "";
let maxActiveDownloads = 5;
-let showVcodec = true;
+let showMoreFormats = false;
+
function checkMaxDownloads() {
if (localStorage.getItem("maxActiveDownloads")) {
const number = Number(localStorage.getItem("maxActiveDownloads"));
@@ -88,6 +91,7 @@ let controllers = new Object();
// Video and audio preferences
let preferredVideoQuality = "";
let preferredAudioQuality = "";
+let preferredVideoCodec = "avc1";
function getId(id) {
return document.getElementById(id);
@@ -268,6 +272,14 @@ async function getInfo(url) {
preferredAudioQuality = localStorage.getItem("preferredAudioQuality");
getId("extractSelection").value = preferredAudioQuality;
}
+ if (localStorage.getItem("preferredVideoCodec")) {
+ preferredVideoCodec = localStorage.getItem("preferredVideoCodec");
+ }
+ if (localStorage.getItem("showMoreFormats") === "true") {
+ showMoreFormats = true;
+ } else {
+ showMoreFormats = false;
+ }
// Whether to use browser cookies or not
if (localStorage.getItem("browser")) {
@@ -347,6 +359,7 @@ async function getInfo(url) {
let audioSize = 0;
let defaultVideoFormat = 0;
+ let videoFormatCodecs = {};
let preferredAudioFormatLength = 0;
let preferredAudioFormatCount = 0;
@@ -357,10 +370,18 @@ async function getInfo(url) {
// Find the item with the preferred video format
if (
format.height <= preferredVideoQuality &&
- format.height > defaultVideoFormat &&
+ format.height >= defaultVideoFormat &&
format.video_ext !== "none"
) {
defaultVideoFormat = format.height;
+
+ // Creating a list of available codecs for the required video height
+ if (!videoFormatCodecs[format.height]) {
+ videoFormatCodecs[format.height] = {codecs: []};
+ }
+ videoFormatCodecs[format.height].codecs.push(
+ format.vcodec.split(".")[0]
+ );
}
// Going through audio list
@@ -385,12 +406,25 @@ async function getInfo(url) {
preferredAudioFormatLength++;
}
}
+
+ const availableCodecs =
+ videoFormatCodecs[defaultVideoFormat].codecs;
+
+ if (!availableCodecs.includes(preferredVideoCodec)) {
+ preferredVideoCodec =
+ availableCodecs[availableCodecs.length - 1];
+ }
+
for (let format of formats) {
let size;
let selectedText = "";
let audioSelectedText = "";
- if (format.height == defaultVideoFormat && !selected) {
+ if (
+ format.height == defaultVideoFormat &&
+ format.vcodec.split(".")[0] === preferredVideoCodec &&
+ !selected
+ ) {
selectedText = " selected ";
selected = true;
}
@@ -434,26 +468,29 @@ async function getInfo(url) {
// Video codec
const vcodec =
- format.vcodec && showVcodec
+ format.vcodec && showMoreFormats
? format.vcodec.split(".")[0]
: "";
- let spaceAfterVcodec = showVcodec
+ let spaceAfterVcodec = showMoreFormats
? " ".repeat(5 - vcodec.length)
: "";
- showVcodec
+ showMoreFormats
? (spaceAfterVcodec += "| ")
: (spaceAfterVcodec += "");
// Quality
- const quality = format.height
- ? format.height + "p" + (format.fps == 60 ? "60" : "")
- : "" ||
- format.resolution ||
- i18n.__(format.format_note) ||
- format.format_id ||
- "Unknown quality";
+ const quality =
+ format.format_note ||
+ (format.height
+ ? format.height +
+ "p" +
+ (format.fps == 60 ? "60" : "")
+ : "") ||
+ format.resolution ||
+ format.format_id ||
+ "Unknown quality";
const spaceAfterQuality = " ".repeat(
- 8 - quality.length
+ 12 - quality.length
);
// Extension
diff --git a/translations/en.json b/translations/en.json
index 1e3aed2..9b95651 100644
--- a/translations/en.json
+++ b/translations/en.json
@@ -106,5 +106,7 @@
"Frappé":"Frappé",
"One Dark":"One Dark",
"Matrix":"Matrix",
- "Solarized Dark": "Solarized Dark"
+ "Solarized Dark": "Solarized Dark",
+ "Preferred video codec": "Preferred video codec",
+ "Show more format options": "Show more format options"
}