From 3c18adee84a13454a564f85018cba53f54e0e718 Mon Sep 17 00:00:00 2001 From: bingus_violet Date: Wed, 31 Jul 2024 02:54:26 -0500 Subject: [PATCH] trim silence option --- downloader.js | 11 +++++++++-- package-lock.json | 18 +++++++++--------- package.json | 2 +- static/index.html | 14 +++++++++----- static/js/main.js | 19 ++++++++++++++++++- static/style.css | 6 +++--- 6 files changed, 49 insertions(+), 21 deletions(-) diff --git a/downloader.js b/downloader.js index 4809644..1c27785 100644 --- a/downloader.js +++ b/downloader.js @@ -23,7 +23,8 @@ var audioFormats = [ expressManager.app.get("/download", async (req, res) => { var url = req.query.url, quality = req.query.quality, - format = req.query.format + format = req.query.format, + trimAudio = req.query.trimAudio && audioFormats.includes(format) || false if (ytdl.validateURL(url) && qualityLabels.includes(quality)) { var needsVideo = !audioFormats.includes(format) @@ -83,12 +84,18 @@ expressManager.app.get("/download", async (req, res) => { '-map', '0:a' ] + var bonusArgs = [] + if (needsVideo) { inputArgs = inputArgs.concat(['-i', 'pipe:5']) mapArgs = mapArgs.concat(['-map', '1:v']) } - var args = inputArgs.concat(mapArgs).concat(baseArgs) + if (trimAudio) { + bonusArgs = bonusArgs.concat(['-af', 'silenceremove=1:0:-50dB']) + } + + var args = inputArgs.concat(mapArgs).concat(bonusArgs).concat(baseArgs) const ffmpegProcess = cp.spawn(ffmpeg, args, { windowsHide: true, diff --git a/package-lock.json b/package-lock.json index 47d414d..62badb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "univerter", - "version": "3.2.0", + "version": "4.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "univerter", - "version": "3.2.0", + "version": "4.0.0", "license": "MIT", "dependencies": { - "@distube/ytdl-core": "^4.13.5", + "@distube/ytdl-core": "^4.13.7", "child_process": "^1.0.2", "express": "^4.18.2", "ffmpeg-static": "^5.2.0" @@ -30,9 +30,9 @@ } }, "node_modules/@distube/ytdl-core": { - "version": "4.13.5", - "resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.13.5.tgz", - "integrity": "sha512-g+4UJIR/auAJbia7iB0aWvaJDbs22P53NySWa47b1NT4xMTDJYguxHFArPrvRkcJrb/AgKjv/XoSZGghpL0CJA==", + "version": "4.13.7", + "resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.13.7.tgz", + "integrity": "sha512-xpovwZVPwQ0R4Mrwt/fhh1rqmBjiZ5qj30ck5kz+mQJ5XPzW9dUiTDz89qCxO3YvgbCAqaC5BNNnWiFC2uCV5Q==", "license": "MIT", "dependencies": { "http-cookie-agent": "^6.0.5", @@ -970,9 +970,9 @@ } }, "@distube/ytdl-core": { - "version": "4.13.5", - "resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.13.5.tgz", - "integrity": "sha512-g+4UJIR/auAJbia7iB0aWvaJDbs22P53NySWa47b1NT4xMTDJYguxHFArPrvRkcJrb/AgKjv/XoSZGghpL0CJA==", + "version": "4.13.7", + "resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.13.7.tgz", + "integrity": "sha512-xpovwZVPwQ0R4Mrwt/fhh1rqmBjiZ5qj30ck5kz+mQJ5XPzW9dUiTDz89qCxO3YvgbCAqaC5BNNnWiFC2uCV5Q==", "requires": { "http-cookie-agent": "^6.0.5", "m3u8stream": "^0.8.6", diff --git a/package.json b/package.json index 54b4754..0df1a87 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/Violets-puragtory/YoutubeConverter#readme", "dependencies": { - "@distube/ytdl-core": "^4.13.5", + "@distube/ytdl-core": "^4.13.7", "child_process": "^1.0.2", "express": "^4.18.2", "ffmpeg-static": "^5.2.0" diff --git a/static/index.html b/static/index.html index 29b9c32..97767a8 100644 --- a/static/index.html +++ b/static/index.html @@ -56,14 +56,18 @@ - - - +
+ +

Trim Silence (mp3)

+
+
+ +
-
-
+

Inspired by Cobalt

diff --git a/static/js/main.js b/static/js/main.js index 77ca5e3..d298a8b 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1,7 +1,24 @@ +var audioFormats = ["mp3"] + +function updateOptions() { + var format = $("#format").val() + if (audioFormats.includes(format)) { + $("#audioOnly > input").attr("disabled", false) + $("#videoAndAudio > input").attr("disabled", true) + } else { + $("#audioOnly > input").attr("disabled", true) + $("#videoAndAudio > input").attr("disabled", false) + } +} + $(document).ready(() => { + updateOptions() + $("#format").on("change", updateOptions) + $("#quality").val(Cookies.get("quality") || "720") + $("#trim").prop("checked", Cookies.get("trim") == "true" || false) $("form").submit(() => { Cookies.set("quality", $("#quality").val()) - // $("#url").val("") + Cookies.set("trim", $("#trim").prop("checked")) }) }) \ No newline at end of file diff --git a/static/style.css b/static/style.css index 9fa715c..8a6531c 100644 --- a/static/style.css +++ b/static/style.css @@ -131,10 +131,10 @@ option { background-color: rgba(0, 0, 20); } -#adv { +input[type="checkbox"] { accent-color: var(--primary-color); - width: 1.15rem; - height: 1.15rem; + width: 1.05rem; + height: 1.05rem; } .error {