diff --git a/appinfo/info.xml b/appinfo/info.xml
index 9f4f1be..db28e4d 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -8,7 +8,7 @@ Search for torrents within the app from mutiple BT sites;
Control Aria2 and manage download tasks from the web;
download videos from 700+ video sites(youtube,youku,vimo,dailymotion,twitter,facebook and the likes
- 0.5.1
+ 0.5.2
agpl
jiaxinhuang
NCDownloader
diff --git a/lib/Tools/Youtube.php b/lib/Tools/Youtube.php
index da5d1db..e8a9f60 100644
--- a/lib/Tools/Youtube.php
+++ b/lib/Tools/Youtube.php
@@ -15,7 +15,7 @@ class Youtube
private $options = [];
private $downloadDir;
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 $env = [];
@@ -48,6 +48,12 @@ class Youtube
$this->setEnv('LANG', $lang);
$this->addOption("--no-mtime");
$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)
@@ -63,7 +69,9 @@ class Youtube
$this->setOption('--metadata-from-title', "%(artist)s-%(title)s");
$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);
return $this;
}
@@ -140,11 +148,11 @@ class Youtube
}
$this->helper = YoutubeHelper::create();
$this->downloadDir = $this->downloadDir ?? $this->defaultDir;
- $this->setOption("--output", $this->downloadDir . $this->outTpl);
+ $this->setOption("--output", $this->downloadDir . "/" . $this->outTpl);
$this->setUrl($url);
$this->prependOption($this->bin);
+ //\OC::$server->getLogger()->error($process->getCommandLine(), ['app' => 'PHP']);
$process = new Process($this->options, null, $this->env);
- \OC::$server->getLogger()->error($process->getCommandLine(), ['app' => 'PHP']);
$process->setTimeout($this->timeout);
$process->run(function ($type, $buffer) use ($url) {
if (Process::ERR === $type) {
@@ -192,7 +200,7 @@ class Youtube
public function setOption($key, $value, $hyphens = false)
{
$this->addOption($key, $hyphens);
- $this->addOption($value, $hyphens);
+ $this->addOption($value, false);
return $this;
}
public function addOption(String $option, $hyphens = false)
@@ -203,6 +211,11 @@ class Youtube
array_push($this->options, $option);
}
+ protected function hasOption($name)
+ {
+ return array_search($name, $this->options);
+ }
+
public function forceIPV4()
{
$this->addOption('force-ipv4', true);