added delete option for youtube-dl download;added options for copying links;

This commit is contained in:
huangjx
2022-02-19 00:44:45 +08:00
parent d25e0c1ec1
commit 06e1588d06
13 changed files with 219 additions and 23 deletions

View File

@@ -43,6 +43,7 @@ class Helper
{
$host = parse_url($url, PHP_URL_HOST);
//$sites = ['twitter.com', 'www.twitter.com'];
$sites = [];
return (bool) (in_array($host, $sites));
}
public static function parseUrl($url)
@@ -134,7 +135,7 @@ class Helper
public static function debug($msg)
{
$logger = \OC::$server->getLogger();
$logger->debug($msg, ['app' => 'ncdownloader']);
$logger->error($msg, ['app' => 'ncdownloader']);
}
public static function log($msg, $file = "/tmp/nc.log")
@@ -298,4 +299,28 @@ class Helper
return filter_var($string, FILTER_SANITIZE_STRING);
}
public static function doSignal($pid, $signal): bool
{
if (\function_exists('posix_kill')) {
$ok = @posix_kill($pid, $signal);
} elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $pid), [2 => ['pipe', 'w']], $pipes)) {
$ok = false === fgets($pipes[2]);
}
if (!$ok) {
return false;
}
return true;
}
public static function isRunning($pid)
{
return self::doSignal($pid, 0);
}
public static function stop($pid)
{
return self::doSignal($pid, 9);
}
}

View File

@@ -154,11 +154,13 @@ class Youtube
//\OC::$server->getLogger()->error($process->getCommandLine(), ['app' => 'PHP']);
$process = new Process($this->options, null, $this->env);
$process->setTimeout($this->timeout);
$process->run(function ($type, $buffer) use ($url) {
$data = ['link' => $url];
$process->run(function ($type, $buffer) use ($data, $process) {
if (Process::ERR === $type) {
$this->onError($buffer);
// $this->onError($buffer);
} else {
$this->onOutput($buffer, $url);
$data['pid'] = $process->getPid();
$this->onOutput($buffer, $data);
}
});
if ($process->isSuccessful()) {
@@ -173,9 +175,9 @@ class Youtube
$this->helper->log($buffer);
}
public function onOutput($buffer, $url)
public function onOutput($buffer, $extra)
{
$this->helper->run($buffer, $url);
$this->helper->run($buffer, $extra);
}
public function getDownloadUrl($url)
{

View File

@@ -16,6 +16,7 @@ class YoutubeHelper
'(\s+in\s+(?<totalTime>[\d:]{2,8}))?#i';
public $file = null;
public $filesize = null;
protected $pid = 0;
public function __construct()
{
$this->dbconn = new DbHelper();
@@ -47,9 +48,13 @@ class YoutubeHelper
//$sql = sprintf("UPDATE %s set status = ? WHERE gid = ?", $this->tablename);
$this->dbconn->updateStatus($this->gid, $this->status);
}
public function run($buffer, $url)
public function setPid($pid)
{
$this->gid = Helper::generateGID($url);
$this->pid = $pid;
}
public function run($buffer, $extra)
{
$this->gid = Helper::generateGID($extra['link']);
$file = $this->getFilePath($buffer);
if ($file) {
$data = [
@@ -59,7 +64,7 @@ class YoutubeHelper
'filename' => basename($file),
'status' => Helper::STATUS['ACTIVE'],
'timestamp' => time(),
'data' => serialize(['link' => $url]),
'data' => serialize($extra),
];
//save the filename as this runs only once
$this->file = $file;