Add youtube-dl extension format select

This commit is contained in:
Moahmed-Ismail MEJRI
2022-03-16 17:20:51 +01:00
parent 7de95084be
commit 2c171152b2
4 changed files with 56 additions and 15 deletions

View File

@@ -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"]);
}

View File

@@ -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;