diff --git a/assets/css/extra.css b/assets/css/extra.css index 6df4077..ea4634e 100644 --- a/assets/css/extra.css +++ b/assets/css/extra.css @@ -14,7 +14,7 @@ h1{ #version{ margin:5px; } -input[type="text"]{ +input[type="text"], .input{ border-radius: 5px; padding:5px; outline: none; @@ -23,6 +23,10 @@ input[type="text"]{ height:35px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; } +.input{ + width:70px; + font-size: larger; +} .prefBox, #pathConfig{ display:flex; diff --git a/html/index.html b/html/index.html index 4cb856a..eadf308 100644 --- a/html/index.html +++ b/html/index.html @@ -115,10 +115,6 @@

Subtitles

Download subtitles if available - - @@ -143,11 +139,10 @@ -



+

-
-
+
diff --git a/html/preferences.html b/html/preferences.html index 6074bc5..9f89746 100644 --- a/html/preferences.html +++ b/html/preferences.html @@ -149,9 +149,11 @@ - +
+
+ Maximum number of active downloads + +
\ No newline at end of file diff --git a/src/preferences.js b/src/preferences.js index 775ef04..297006c 100644 --- a/src/preferences.js +++ b/src/preferences.js @@ -172,5 +172,21 @@ getId("resetFoldernameFormat").addEventListener("click", () => { localStorage.setItem("foldernameFormat", "%(playlist_title)s"); }); +// Max active downloads +getId("maxDownloads").addEventListener("input", ()=>{ + const number = Number(getId("maxDownloads").value) + + if (number < 1){ + localStorage.setItem("maxActiveDownloads", 1) + } + else{ + localStorage.setItem("maxActiveDownloads", number) + } +}) + +if (localStorage.getItem("maxActiveDownloads")){ + getId("maxDownloads").value = localStorage.getItem("maxActiveDownloads") +} + // Translation file require("../src/translate_preferences"); diff --git a/src/renderer.js b/src/renderer.js index 655d78d..dd78cb5 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -29,10 +29,21 @@ let title, onlyvideo, id, thumbnail, ytdlp, duration, extractFormat; let rangeCmd = ""; let subs = ""; let subLangs; -// let autoSubs = "" let rangeOption = "--download-sections"; let cookieArg = ""; 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 let preferredVideoQuality = ""; @@ -439,13 +450,68 @@ async function getInfo(url) { // Video download event getId("videoDownload").addEventListener("click", (event) => { 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 = ` +
+ No thumbnail + +
+
${title}
+
${i18n.__("Video")}
+

${i18n.__("Download pending")}

+
+
+ `; + getId("list").innerHTML += item; + const interval = setInterval(() => { + if (currentDownloads < maxActiveDownloads) { + getId(randId).remove() + download("video"); + currentDownloads++; + clearInterval(interval); + } + }, 2000); + } + }); // Audio download event getId("audioDownload").addEventListener("click", (event) => { 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 = ` +
+ No thumbnail + +
+
${title}
+
${i18n.__("Video")}
+

${i18n.__("Download pending")}

+
+
+ `; + getId("list").innerHTML += item; + const interval = setInterval(() => { + if (currentDownloads < maxActiveDownloads) { + getId(randId).remove() + download("video"); + currentDownloads++; + clearInterval(interval); + } + }, 2000); + } }); getId("extractBtn").addEventListener("click", () => { @@ -557,14 +623,13 @@ function manageAdvanced(duration) { ////////////////////////////// function download(type) { - let willBeSaved = true; manageAdvanced(duration); const url = getId("url").value; let ext; let extractExt; 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") { const videoValue = getId("videoFormatSelect").value; @@ -658,6 +723,9 @@ function download(type) { } const controller = new AbortController(); + controllers[randomId] = controller; + + console.log(rangeOption + " " + rangeCmd); if (type === "video" && onlyvideo) { @@ -735,7 +803,6 @@ function download(type) { } getId(randomId + ".close").addEventListener("click", () => { - willBeSaved = false; controller.abort(); }); @@ -765,8 +832,10 @@ function download(type) { .once("ytDlpEvent", (eventType, eventData) => { getId(randomId + "prog").textContent = i18n.__("Downloading..."); }) - .once("close", () => { - if (willBeSaved) { + .once("close", (code) => { + console.log("Closed with code " + code); + if (code == 0) { + currentDownloads--; // const items = JSON.parse(localStorage.getItem("itemList")); // // Clearing item from localstorage // for (let item of items) { @@ -801,6 +870,7 @@ function download(type) { } }) .once("error", (error) => { + currentDownloads--; getId(randomId + "prog").textContent = i18n.__( "Some error has occurred. Hover to see details" ); @@ -812,6 +882,8 @@ function download(type) { // Removing item function fadeItem(id) { + controllers[id].abort() + currentDownloads --; let count = 0; let opacity = 1; const fade = setInterval(() => {