|
|
|
@ -29,10 +29,21 @@ let title, onlyvideo, id, thumbnail, ytdlp, duration, extractFormat;
|
|
|
|
let rangeCmd = "";
|
|
|
|
let rangeCmd = "";
|
|
|
|
let subs = "";
|
|
|
|
let subs = "";
|
|
|
|
let subLangs;
|
|
|
|
let subLangs;
|
|
|
|
// let autoSubs = ""
|
|
|
|
|
|
|
|
let rangeOption = "--download-sections";
|
|
|
|
let rangeOption = "--download-sections";
|
|
|
|
let cookieArg = "";
|
|
|
|
let cookieArg = "";
|
|
|
|
let browser = "";
|
|
|
|
let browser = "";
|
|
|
|
|
|
|
|
let maxActiveDownloads = 5;
|
|
|
|
|
|
|
|
if (localStorage.getItem("maxActiveDownloads")){
|
|
|
|
|
|
|
|
const number = Number(localStorage.getItem("maxActiveDownloads"))
|
|
|
|
|
|
|
|
if (number < 1){
|
|
|
|
|
|
|
|
maxActiveDownloads = 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
maxActiveDownloads = number
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let currentDownloads = 0;
|
|
|
|
|
|
|
|
let controllers = new Object;
|
|
|
|
|
|
|
|
|
|
|
|
// Video and audio preferences
|
|
|
|
// Video and audio preferences
|
|
|
|
let preferredVideoQuality = "";
|
|
|
|
let preferredVideoQuality = "";
|
|
|
|
@ -439,13 +450,68 @@ async function getInfo(url) {
|
|
|
|
// Video download event
|
|
|
|
// Video download event
|
|
|
|
getId("videoDownload").addEventListener("click", (event) => {
|
|
|
|
getId("videoDownload").addEventListener("click", (event) => {
|
|
|
|
getId("hidden").style.display = "none";
|
|
|
|
getId("hidden").style.display = "none";
|
|
|
|
download("video");
|
|
|
|
console.log(`Current:${currentDownloads} Max:${maxActiveDownloads}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentDownloads < maxActiveDownloads) {
|
|
|
|
|
|
|
|
download("video");
|
|
|
|
|
|
|
|
currentDownloads++;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const randId = Math.random().toFixed(10).toString().slice(2);
|
|
|
|
|
|
|
|
const item = `
|
|
|
|
|
|
|
|
<div class="item" id="${randId}">
|
|
|
|
|
|
|
|
<img src="${thumbnail}" alt="No thumbnail" class="itemIcon" crossorigin="anonymous">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="itemBody">
|
|
|
|
|
|
|
|
<div class="itemTitle">${title}</div>
|
|
|
|
|
|
|
|
<div class="itemType">${i18n.__("Video")}</div>
|
|
|
|
|
|
|
|
<p>${i18n.__("Download pending")}</p>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
getId("list").innerHTML += item;
|
|
|
|
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
|
|
|
|
if (currentDownloads < maxActiveDownloads) {
|
|
|
|
|
|
|
|
getId(randId).remove()
|
|
|
|
|
|
|
|
download("video");
|
|
|
|
|
|
|
|
currentDownloads++;
|
|
|
|
|
|
|
|
clearInterval(interval);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Audio download event
|
|
|
|
// Audio download event
|
|
|
|
getId("audioDownload").addEventListener("click", (event) => {
|
|
|
|
getId("audioDownload").addEventListener("click", (event) => {
|
|
|
|
getId("hidden").style.display = "none";
|
|
|
|
getId("hidden").style.display = "none";
|
|
|
|
download("audio");
|
|
|
|
console.log(`Current:${currentDownloads} Max:${maxActiveDownloads}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentDownloads < maxActiveDownloads) {
|
|
|
|
|
|
|
|
download("audio");
|
|
|
|
|
|
|
|
currentDownloads++;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const randId = Math.random().toFixed(10).toString().slice(2);
|
|
|
|
|
|
|
|
const item = `
|
|
|
|
|
|
|
|
<div class="item" id="${randId}">
|
|
|
|
|
|
|
|
<img src="${thumbnail}" alt="No thumbnail" class="itemIcon" crossorigin="anonymous">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="itemBody">
|
|
|
|
|
|
|
|
<div class="itemTitle">${title}</div>
|
|
|
|
|
|
|
|
<div class="itemType">${i18n.__("Video")}</div>
|
|
|
|
|
|
|
|
<p>${i18n.__("Download pending")}</p>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
getId("list").innerHTML += item;
|
|
|
|
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
|
|
|
|
if (currentDownloads < maxActiveDownloads) {
|
|
|
|
|
|
|
|
getId(randId).remove()
|
|
|
|
|
|
|
|
download("video");
|
|
|
|
|
|
|
|
currentDownloads++;
|
|
|
|
|
|
|
|
clearInterval(interval);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
getId("extractBtn").addEventListener("click", () => {
|
|
|
|
getId("extractBtn").addEventListener("click", () => {
|
|
|
|
@ -557,14 +623,13 @@ function manageAdvanced(duration) {
|
|
|
|
//////////////////////////////
|
|
|
|
//////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
function download(type) {
|
|
|
|
function download(type) {
|
|
|
|
let willBeSaved = true;
|
|
|
|
|
|
|
|
manageAdvanced(duration);
|
|
|
|
manageAdvanced(duration);
|
|
|
|
const url = getId("url").value;
|
|
|
|
const url = getId("url").value;
|
|
|
|
let ext;
|
|
|
|
let ext;
|
|
|
|
let extractExt;
|
|
|
|
let extractExt;
|
|
|
|
|
|
|
|
|
|
|
|
let format_id;
|
|
|
|
let format_id;
|
|
|
|
const randomId = Math.random().toFixed(10).toString().slice(2);
|
|
|
|
const randomId = "a" + Math.random().toFixed(10).toString().slice(2);
|
|
|
|
|
|
|
|
|
|
|
|
if (type === "video") {
|
|
|
|
if (type === "video") {
|
|
|
|
const videoValue = getId("videoFormatSelect").value;
|
|
|
|
const videoValue = getId("videoFormatSelect").value;
|
|
|
|
@ -658,6 +723,9 @@ function download(type) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
const controller = new AbortController();
|
|
|
|
|
|
|
|
controllers[randomId] = controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(rangeOption + " " + rangeCmd);
|
|
|
|
console.log(rangeOption + " " + rangeCmd);
|
|
|
|
|
|
|
|
|
|
|
|
if (type === "video" && onlyvideo) {
|
|
|
|
if (type === "video" && onlyvideo) {
|
|
|
|
@ -735,7 +803,6 @@ function download(type) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getId(randomId + ".close").addEventListener("click", () => {
|
|
|
|
getId(randomId + ".close").addEventListener("click", () => {
|
|
|
|
willBeSaved = false;
|
|
|
|
|
|
|
|
controller.abort();
|
|
|
|
controller.abort();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@ -765,8 +832,10 @@ function download(type) {
|
|
|
|
.once("ytDlpEvent", (eventType, eventData) => {
|
|
|
|
.once("ytDlpEvent", (eventType, eventData) => {
|
|
|
|
getId(randomId + "prog").textContent = i18n.__("Downloading...");
|
|
|
|
getId(randomId + "prog").textContent = i18n.__("Downloading...");
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.once("close", () => {
|
|
|
|
.once("close", (code) => {
|
|
|
|
if (willBeSaved) {
|
|
|
|
console.log("Closed with code " + code);
|
|
|
|
|
|
|
|
if (code == 0) {
|
|
|
|
|
|
|
|
currentDownloads--;
|
|
|
|
// const items = JSON.parse(localStorage.getItem("itemList"));
|
|
|
|
// const items = JSON.parse(localStorage.getItem("itemList"));
|
|
|
|
// // Clearing item from localstorage
|
|
|
|
// // Clearing item from localstorage
|
|
|
|
// for (let item of items) {
|
|
|
|
// for (let item of items) {
|
|
|
|
@ -801,6 +870,7 @@ function download(type) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.once("error", (error) => {
|
|
|
|
.once("error", (error) => {
|
|
|
|
|
|
|
|
currentDownloads--;
|
|
|
|
getId(randomId + "prog").textContent = i18n.__(
|
|
|
|
getId(randomId + "prog").textContent = i18n.__(
|
|
|
|
"Some error has occurred. Hover to see details"
|
|
|
|
"Some error has occurred. Hover to see details"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
@ -812,6 +882,8 @@ function download(type) {
|
|
|
|
// Removing item
|
|
|
|
// Removing item
|
|
|
|
|
|
|
|
|
|
|
|
function fadeItem(id) {
|
|
|
|
function fadeItem(id) {
|
|
|
|
|
|
|
|
controllers[id].abort()
|
|
|
|
|
|
|
|
currentDownloads --;
|
|
|
|
let count = 0;
|
|
|
|
let count = 0;
|
|
|
|
let opacity = 1;
|
|
|
|
let opacity = 1;
|
|
|
|
const fade = setInterval(() => {
|
|
|
|
const fade = setInterval(() => {
|
|
|
|
|