make it possible to set your own output template in settings fixed #22

This commit is contained in:
huangjx
2022-01-28 21:18:27 +08:00
parent 293f30ed40
commit 7cf0f0e336
2 changed files with 19 additions and 6 deletions

View File

@@ -8,7 +8,7 @@ Search for torrents within the app from mutiple BT sites;
Control Aria2 and manage download tasks from the web; Control Aria2 and manage download tasks from the web;
download videos from 700+ video sites(youtube,youku,vimo,dailymotion,twitter,facebook and the likes download videos from 700+ video sites(youtube,youku,vimo,dailymotion,twitter,facebook and the likes
</description> </description>
<version>0.5.1</version> <version>0.5.2</version>
<licence>agpl</licence> <licence>agpl</licence>
<author mail="freefallbenson@gmail.com" homepage="https://github.com/shiningw">jiaxinhuang</author> <author mail="freefallbenson@gmail.com" homepage="https://github.com/shiningw">jiaxinhuang</author>
<namespace>NCDownloader</namespace> <namespace>NCDownloader</namespace>

View File

@@ -15,7 +15,7 @@ class Youtube
private $options = []; private $options = [];
private $downloadDir; private $downloadDir;
private $timeout = 60 * 60 * 10; //10 hours private $timeout = 60 * 60 * 10; //10 hours
private $outTpl = "/%(id)s-%(title)s.%(ext)s"; private $outTpl = "%(id)s-%(title)s.%(ext)s";
private $defaultDir = "/tmp/downloads"; private $defaultDir = "/tmp/downloads";
private $env = []; private $env = [];
@@ -48,6 +48,12 @@ class Youtube
$this->setEnv('LANG', $lang); $this->setEnv('LANG', $lang);
$this->addOption("--no-mtime"); $this->addOption("--no-mtime");
$this->addOption('--ignore-errors'); $this->addOption('--ignore-errors');
if (($index = $this->hasOption('--output')) !== false) {
$this->outTpl = $this->options[$index + 1];
unset($this->options[$index]);
unset($this->options[$index + 1]);
}
} }
public function setEnv($key, $val) public function setEnv($key, $val)
@@ -63,7 +69,9 @@ class Youtube
$this->setOption('--metadata-from-title', "%(artist)s-%(title)s"); $this->setOption('--metadata-from-title', "%(artist)s-%(title)s");
$this->addOption('--extract-audio'); $this->addOption('--extract-audio');
} }
$this->outTpl = "/%(id)s-%(title)s.m4a"; $pos = strrpos($this->outTpl, '.');
$this->outTpl = substr($this->outTpl, 0, $pos) . ".m4a";
//$this->outTpl = "/%(id)s-%(title)s.m4a";
$this->setAudioFormat($this->audioFormat); $this->setAudioFormat($this->audioFormat);
return $this; return $this;
} }
@@ -140,11 +148,11 @@ class Youtube
} }
$this->helper = YoutubeHelper::create(); $this->helper = YoutubeHelper::create();
$this->downloadDir = $this->downloadDir ?? $this->defaultDir; $this->downloadDir = $this->downloadDir ?? $this->defaultDir;
$this->setOption("--output", $this->downloadDir . $this->outTpl); $this->setOption("--output", $this->downloadDir . "/" . $this->outTpl);
$this->setUrl($url); $this->setUrl($url);
$this->prependOption($this->bin); $this->prependOption($this->bin);
//\OC::$server->getLogger()->error($process->getCommandLine(), ['app' => 'PHP']);
$process = new Process($this->options, null, $this->env); $process = new Process($this->options, null, $this->env);
\OC::$server->getLogger()->error($process->getCommandLine(), ['app' => 'PHP']);
$process->setTimeout($this->timeout); $process->setTimeout($this->timeout);
$process->run(function ($type, $buffer) use ($url) { $process->run(function ($type, $buffer) use ($url) {
if (Process::ERR === $type) { if (Process::ERR === $type) {
@@ -192,7 +200,7 @@ class Youtube
public function setOption($key, $value, $hyphens = false) public function setOption($key, $value, $hyphens = false)
{ {
$this->addOption($key, $hyphens); $this->addOption($key, $hyphens);
$this->addOption($value, $hyphens); $this->addOption($value, false);
return $this; return $this;
} }
public function addOption(String $option, $hyphens = false) public function addOption(String $option, $hyphens = false)
@@ -203,6 +211,11 @@ class Youtube
array_push($this->options, $option); array_push($this->options, $option);
} }
protected function hasOption($name)
{
return array_search($name, $this->options);
}
public function forceIPV4() public function forceIPV4()
{ {
$this->addOption('force-ipv4', true); $this->addOption('force-ipv4', true);