Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aandrew-me committed Dec 26, 2023
1 parent c151d11 commit b39d4ae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"./public/**/*",
"package.json",
"./assets/**/*",
"./src/**/*",
"./src/*.js",
"ffmpeg*",
"translations"
],
Expand Down
29 changes: 19 additions & 10 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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);

Expand All @@ -358,7 +361,7 @@ async function getInfo(url) {
`<input class="title" id="titleName" type="text" value="${title}" onchange="renameTitle()">`;

let audioSize = 0;
let defaultVideoFormat = 0;
let defaultVideoFormat = 720;
let videoFormatCodecs = {};

let preferredAudioFormatLength = 0;
Expand All @@ -374,6 +377,7 @@ async function getInfo(url) {
format.video_ext !== "none" &&
!(
format.video_ext === "mp4" &&
format.vcodec &&
format.vcodec.split(".")[0] === "vp09"
)
) {
Expand All @@ -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
Expand All @@ -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 =
Expand All @@ -426,6 +433,7 @@ async function getInfo(url) {

if (
format.height == defaultVideoFormat &&
format.vcodec &&
format.vcodec.split(".")[0] === preferredVideoCodec &&
!selected &&
!(
Expand Down Expand Up @@ -460,6 +468,7 @@ async function getInfo(url) {
format.audio_ext === "none" &&
!(
format.video_ext === "mp4" &&
format.vcodec &&
format.vcodec.split(".")[0] === "vp09"
)
) {
Expand Down Expand Up @@ -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 = "&#160".repeat(
12 - quality.length
8 - quality.length
);

// Extension
Expand Down
17 changes: 17 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit b39d4ae

Please sign in to comment.