Merge pull request #40 from medismail/master

Add select youtube-dl format extension
This commit is contained in:
jiaxin huang
2022-03-18 08:29:37 +08:00
committed by GitHub
4 changed files with 68 additions and 15 deletions

View File

@@ -80,6 +80,11 @@ class YoutubeController extends Controller
$url = trim($this->request->getParam('text-input-value')); $url = trim($this->request->getParam('text-input-value'));
$yt = $this->youtube; $yt = $this->youtube;
$yt->audioOnly = (bool) $this->request->getParam('audio-only'); $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()) { if (!$yt->isInstalled()) {
return new JSONResponse(["error" => "Please install the latest youtube-dl or make the bundled binary file executable in ncdownloader/bin"]); 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->addOption('--add-metadata');
$this->setOption('--metadata-from-title', "%(artist)s-%(title).64s"); $this->setOption('--metadata-from-title', "%(artist)s-%(title).64s");
$this->addOption('--extract-audio'); $this->addOption('--extract-audio');
} else {
$this->audioFormat = "m4a";
} }
$pos = strrpos($this->outTpl, '.'); $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->outTpl = "/%(id)s-%(title)s.m4a";
$this->setAudioFormat($this->audioFormat); $this->setAudioFormat($this->audioFormat);
return $this; return $this;
@@ -91,7 +93,8 @@ class Youtube
public function setVideoFormat($format) public function setVideoFormat($format)
{ {
$this->videoFormat = $format; //$this->videoFormat = $format;
$this->setOption('--recode-video', $format);
} }
public function GetUrlOnly() public function GetUrlOnly()
@@ -126,7 +129,12 @@ class Youtube
if ($this->audioOnly) { if ($this->audioOnly) {
$this->audioMode(); $this->audioMode();
} else { } 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->helper = YoutubeHelper::create();
$this->downloadDir = $this->downloadDir ?? $this->defaultDir; $this->downloadDir = $this->downloadDir ?? $this->defaultDir;

View File

@@ -58,9 +58,15 @@ export default {
let formData = helper.getData(formWrapper); let formData = helper.getData(formWrapper);
let inputValue = formData["text-input-value"]; let inputValue = formData["text-input-value"];
let message; let message;
//formData.audioOnly = document.getElementById('audio-only').checked;
if (formData.type === "youtube-dl") { if (formData.type === "youtube-dl") {
formData["audio-only"] = formData["audio-only"] === "true"; formData["audio-only"] = "";
formData["extension"] = "";
if (formData["select-value-extension"] !== "Default") {
formData["extension"] = formData["select-value-extension"];
if ((formData["select-value-extension"] === "mp3" ) || (formData["select-value-extension"] === "m4a" ) || (formData["select-value-extension"] === "vorbis" ) ) {
formData["audio-only"] = "true";
}
}
message = helper.t("Download task started!"); message = helper.t("Download task started!");
} }
if (!helper.isURL(inputValue) && !helper.isMagnetURI(inputValue)) { if (!helper.isURL(inputValue) && !helper.isMagnetURI(inputValue)) {

View File

@@ -24,16 +24,49 @@
<div class="download-input-container" v-if="inputType === 'download'"> <div class="download-input-container" v-if="inputType === 'download'">
<textInput :placeholder="placeholder" :dataType="downloadType"></textInput> <textInput :placeholder="placeholder" :dataType="downloadType"></textInput>
<div class="download-controls-container"> <div class="download-controls-container">
<div v-if="checkboxes" class="checkboxes"> <div v-if="checkboxes" id="select-value-extension-container">
<label for="audio-only" class="checkbox-label" <select :value="selectedExt" id="select-value-extension">
><input <option
type="checkbox" id="defaultext"
id="audio-only" :value="defaultext"
v-model="checkedValue" >
:value="checkedValue" Default
name="audio-only" </option>
/><span>Audio Only</span></label <optgroup label="Video">
> <option
id="mp4"
value="mp4"
>
mp4
</option>
<option
id="webm"
value="webm"
>
webm
</option>
</optgroup>
<optgroup label="Audio">
<option
id="m4a"
value="m4a"
>
m4a
</option>
<option
id="mp3"
value="mp3"
>
mp3
</option>
<option
id="vorbis"
value="vorbis"
>
vorbis
</option>
</optgroup>
</select>
</div> </div>
<actionButton className="download-button" @clicked="download"></actionButton> <actionButton className="download-button" @clicked="download"></actionButton>
<uploadFile <uploadFile
@@ -71,6 +104,7 @@ export default {
placeholder: t("ncdownloader", "Paste your http/magnet link here"), placeholder: t("ncdownloader", "Paste your http/magnet link here"),
searchLabel: t("ncdownloader", "Search Torrents"), searchLabel: t("ncdownloader", "Search Torrents"),
searchOptions: this.search_sites ? this.search_sites : this.noOptions(), searchOptions: this.search_sites ? this.search_sites : this.noOptions(),
selectedExt: "Default",
}; };
}, },
components: { components: {