From b39d4ae5c5198cd5e7a6d04ec268865e54f0dcee Mon Sep 17 00:00:00 2001 From: Andrew <66430340+aandrew-me@users.noreply.github.com> Date: Tue, 26 Dec 2023 19:02:32 +0300 Subject: [PATCH] Fixes --- package.json | 2 +- src/renderer.js | 29 +++++++++++++++++++---------- src/types.d.ts | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 src/types.d.ts diff --git a/package.json b/package.json index acdff38..29051b9 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "./public/**/*", "package.json", "./assets/**/*", - "./src/**/*", + "./src/*.js", "ffmpeg*", "translations" ], diff --git a/src/renderer.js b/src/renderer.js index 234c88e..88dd673 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -17,7 +17,6 @@ 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"); // Directories const homedir = os.homedir(); @@ -89,7 +88,7 @@ let currentDownloads = 0; let controllers = new Object(); // Video and audio preferences -let preferredVideoQuality = ""; +let preferredVideoQuality = 720; let preferredAudioQuality = ""; let preferredVideoCodec = "avc1"; @@ -339,6 +338,10 @@ async function getInfo(url) { id = info.id; thumbnail = info.thumbnail; duration = info.duration; + /** + * @typedef {import("./types").format} format + * @type {format[]} + */ const formats = info.formats; console.log(formats); @@ -358,7 +361,7 @@ async function getInfo(url) { ``; let audioSize = 0; - let defaultVideoFormat = 0; + let defaultVideoFormat = 720; let videoFormatCodecs = {}; let preferredAudioFormatLength = 0; @@ -374,6 +377,7 @@ async function getInfo(url) { format.video_ext !== "none" && !( format.video_ext === "mp4" && + format.vcodec && format.vcodec.split(".")[0] === "vp09" ) ) { @@ -383,9 +387,11 @@ async function getInfo(url) { if (!videoFormatCodecs[format.height]) { videoFormatCodecs[format.height] = {codecs: []}; } - videoFormatCodecs[format.height].codecs.push( - format.vcodec.split(".")[0] - ); + if (format.vcodec) { + videoFormatCodecs[format.height].codecs.push( + format.vcodec.split(".")[0] + ); + } } // Going through audio list @@ -411,8 +417,9 @@ async function getInfo(url) { } } - const availableCodecs = - videoFormatCodecs[defaultVideoFormat].codecs; + const availableCodecs = videoFormatCodecs[defaultVideoFormat] + ? videoFormatCodecs[defaultVideoFormat].codecs + : []; if (!availableCodecs.includes(preferredVideoCodec)) { preferredVideoCodec = @@ -426,6 +433,7 @@ async function getInfo(url) { if ( format.height == defaultVideoFormat && + format.vcodec && format.vcodec.split(".")[0] === preferredVideoCodec && !selected && !( @@ -460,6 +468,7 @@ async function getInfo(url) { format.audio_ext === "none" && !( format.video_ext === "mp4" && + format.vcodec && format.vcodec.split(".")[0] === "vp09" ) ) { @@ -492,17 +501,17 @@ async function getInfo(url) { // Quality const quality = - format.format_note || (format.height ? format.height + "p" + (format.fps == 60 ? "60" : "") : "") || + format.format_note || format.resolution || format.format_id || "Unknown quality"; const spaceAfterQuality = " ".repeat( - 12 - quality.length + 8 - quality.length ); // Extension diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..fd214be --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,17 @@ +type format = { + vcodec?: string, + acodec?: string, + ext: string, + filesize?: number, + format_id: string, + format_note: string, + height: number, + resolution: string, + video_ext: string, + audio_ext: string, + filesize_approx?: number, +} + +export { + format, +} \ No newline at end of file