From 2c171152b2418aa6daab1b65dbed55bf68abc80f Mon Sep 17 00:00:00 2001 From: Moahmed-Ismail MEJRI Date: Wed, 16 Mar 2022 17:20:51 +0100 Subject: [PATCH] Add youtube-dl extension format select --- lib/Controller/YoutubeController.php | 5 ++++ lib/Tools/Youtube.php | 14 ++++++++-- src/App.vue | 10 +++++-- src/components/mainForm.vue | 42 +++++++++++++++++++++------- 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/lib/Controller/YoutubeController.php b/lib/Controller/YoutubeController.php index c691ef6..b9d87ab 100644 --- a/lib/Controller/YoutubeController.php +++ b/lib/Controller/YoutubeController.php @@ -80,6 +80,11 @@ class YoutubeController extends Controller $url = trim($this->request->getParam('text-input-value')); $yt = $this->youtube; $yt->audioOnly = (bool) $this->request->getParam('audio-only'); + if ($yt->audioOnly) { + $yt->audioFormat = $this->request->getParam('extension'); + } else { + $yt->videoFormat = $this->request->getParam('extension'); + } if (!$yt->isInstalled()) { return new JSONResponse(["error" => "Please install the latest youtube-dl or make the bundled binary file executable in ncdownloader/bin"]); } diff --git a/lib/Tools/Youtube.php b/lib/Tools/Youtube.php index e126c39..0623d58 100644 --- a/lib/Tools/Youtube.php +++ b/lib/Tools/Youtube.php @@ -71,9 +71,11 @@ class Youtube $this->addOption('--add-metadata'); $this->setOption('--metadata-from-title', "%(artist)s-%(title).64s"); $this->addOption('--extract-audio'); + } else { + $this->audioFormat = "m4a"; } $pos = strrpos($this->outTpl, '.'); - $this->outTpl = substr($this->outTpl, 0, $pos) . ".m4a"; + $this->outTpl = substr($this->outTpl, 0, $pos) . "." . $this->audioFormat; //$this->outTpl = "/%(id)s-%(title)s.m4a"; $this->setAudioFormat($this->audioFormat); return $this; @@ -91,7 +93,8 @@ class Youtube public function setVideoFormat($format) { - $this->videoFormat = $format; + //$this->videoFormat = $format; + $this->setOption('--recode-video', $format); } public function GetUrlOnly() @@ -126,7 +129,12 @@ class Youtube if ($this->audioOnly) { $this->audioMode(); } else { - $this->setOption('--format', $this->format); + if ((Helper::ffmpegInstalled()) && ($this->videoFormat != "")) { + $this->setOption('--format', 'bestvideo+bestaudio/best'); + $this->setVideoFormat($this->videoFormat); + } else { + $this->setOption('--format', $this->format); + } } $this->helper = YoutubeHelper::create(); $this->downloadDir = $this->downloadDir ?? $this->defaultDir; diff --git a/src/App.vue b/src/App.vue index 4a6c685..5db44c8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -58,9 +58,15 @@ export default { let formData = helper.getData(formWrapper); let inputValue = formData["text-input-value"]; let message; - //formData.audioOnly = document.getElementById('audio-only').checked; if (formData.type === "youtube-dl") { - formData["audio-only"] = formData["audio-only"] === "true"; + formData["audio-only"] = ""; + formData["extension"] = formData["select-value-extension"]; + if (formData["select-value-extension"] === "Default") { + formData["extension"] = ""; + } else if ((formData["select-value-extension"] === "mp3" ) || (formData["select-value-extension"] === "m4a" )) { + formData["audio-only"] = "true"; + } + helper.info(formData["extension"]); message = helper.t("Download task started!"); } if (!helper.isURL(inputValue) && !helper.isMagnetURI(inputValue)) { diff --git a/src/components/mainForm.vue b/src/components/mainForm.vue index 8ba091f..b009d44 100644 --- a/src/components/mainForm.vue +++ b/src/components/mainForm.vue @@ -24,16 +24,37 @@
-
- +
+