fixed locale issue for youtube-dl;updated regex rules for matching filename

This commit is contained in:
huangjx
2021-09-15 13:18:19 +08:00
parent 2e834d4f9c
commit 7427f395f5
4 changed files with 18 additions and 13 deletions

View File

@@ -5,7 +5,7 @@
<summary>Aria2 and youtube-dl web gui for nextcloud</summary> <summary>Aria2 and youtube-dl web gui for nextcloud</summary>
<description>built-in torrent search;Start and stop Aria2 process, manage Aria2 from the web; <description>built-in torrent search;Start and stop Aria2 process, manage Aria2 from the web;
Download videos from youtube, twitter and other sites;</description> Download videos from youtube, twitter and other sites;</description>
<version>0.0.3</version> <version>0.0.4</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

@@ -54,14 +54,10 @@ class Aria2Controller extends Controller
case "start": case "start":
$resp = $this->Start(); $resp = $this->Start();
break; break;
case "pause":
$resp = $this->doAction('pause', $gid);
break;
case "remove":
$resp = $this->doAction('remove', $gid);
break;
case "unpause": case "unpause":
$resp = $this->doAction('unpause', $gid); case "remove":
case "pause":
$resp = $this->doAction($path, $gid);
break; break;
case "get": case "get":
$resp = $this->doAction('tellStatus', $gid); $resp = $this->doAction('tellStatus', $gid);

View File

@@ -16,6 +16,7 @@ class Youtube
private $timeout = 60 * 60 * 15; private $timeout = 60 * 60 * 15;
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 = [];
public function __construct($config) public function __construct($config)
{ {
@@ -23,14 +24,21 @@ class Youtube
$this->bin = Helper::findBinaryPath('youtube-dl'); $this->bin = Helper::findBinaryPath('youtube-dl');
$this->init(); $this->init();
$this->setDownloadDir($config['downloadDir']); $this->setDownloadDir($config['downloadDir']);
$this->helper = YoutubeHelper::create();
} }
public function init() public function init()
{ {
if (empty($lang = getenv('LANG')) || strpos(strtolower($lang), 'utf-8') === false) {
$lang = 'C.UTF-8';
}
$this->setEnv('LANG', $lang);
$this->addOption("--no-mtime"); $this->addOption("--no-mtime");
} }
public function setEnv($key, $val)
{
$this->env[$key] = $val;
}
public function GetUrlOnly() public function GetUrlOnly()
{ {
$this->addOption('--get-filename'); $this->addOption('--get-filename');
@@ -66,7 +74,7 @@ class Youtube
$this->setUrl($url); $this->setUrl($url);
$this->prependOption($this->bin); $this->prependOption($this->bin);
// $this->buildCMD(); // $this->buildCMD();
$process = new Process($this->options); $process = new Process($this->options, null, $this->env);
//the maximum time required to download the file //the maximum time required to download the file
$process->setTimeout($this->timeout); $process->setTimeout($this->timeout);
try { try {
@@ -81,12 +89,13 @@ class Youtube
public function download($url) public function download($url)
{ {
$this->helper = YoutubeHelper::create();
$this->downloadDir = $this->downloadDir ?? $this->defaultDir; $this->downloadDir = $this->downloadDir ?? $this->defaultDir;
$this->prependOption($this->downloadDir . $this->outTpl); $this->prependOption($this->downloadDir . $this->outTpl);
$this->prependOption("-o"); $this->prependOption("-o");
$this->setUrl($url); $this->setUrl($url);
$this->prependOption($this->bin); $this->prependOption($this->bin);
$process = new Process($this->options); $process = new Process($this->options, null, $this->env);
$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) {

View File

@@ -29,7 +29,7 @@ class YoutubeHelper
} }
public function getFilePath($output) public function getFilePath($output)
{ {
$rules = '#\[download\]\s+Destination:\s+(?<filename>.*\.(?<ext>(mp4|mp3|aac)))$#i'; $rules = '#\[download\]\s+Destination:\s+(?<filename>.*\.(?<ext>(mp4|mp3|aac|webm|m4a|ogg)))$#i';
preg_match($rules, $output, $matches); preg_match($rules, $output, $matches);