fixed #9; tweaked aria2 settings(including disabling certificate check);added aria2 event hooks;other minor changes;
This commit is contained in:
@@ -32,6 +32,7 @@ class Aria2
|
||||
'dir' => '/tmp/Downloads',
|
||||
'token' => null,
|
||||
'conf_dir' => '/tmp/aria2',
|
||||
'completeHook' => $_SERVER['DOCUMENT_ROOT'] . "/apps/ncdownloader/hooks/completeHook.sh",
|
||||
'settings' => [],
|
||||
);
|
||||
//turn keys in $options into variables
|
||||
@@ -43,6 +44,8 @@ class Aria2
|
||||
}
|
||||
}
|
||||
$this->bin = Helper::findBinaryPath('aria2c');
|
||||
$this->php = Helper::findBinaryPath('php');
|
||||
$this->completeHook = $completeHook;
|
||||
$this->rpcUrl = sprintf("http://%s:%s/jsonrpc", $host, $port);
|
||||
$this->tokenString = $token ?? 'ncdownloader123';
|
||||
$this->setToken($this->tokenString);
|
||||
@@ -169,14 +172,6 @@ class Aria2
|
||||
$this->filterResponse = true;
|
||||
return $result;
|
||||
}
|
||||
public function getCounters()
|
||||
{
|
||||
$active = is_array($data = $this->tellActive([])) ? count($data) : 0;
|
||||
$waiting = is_array($data = $this->tellWaiting([0, 999])) ? count($data) : 0;
|
||||
$stopped = is_array($data = $this->tellStopped([0, 999])) ? count($data) : 0;
|
||||
$fail = is_array($data = $this->tellFail([0, 999])) ? count($data) : 0;
|
||||
return ['active' => $active, 'waiting' => $waiting, 'complete' => $stopped, 'fail' => $fail];
|
||||
}
|
||||
public function tellAll()
|
||||
{
|
||||
$this->filterResponse = false;
|
||||
@@ -303,13 +298,15 @@ class Aria2
|
||||
'--enable-peer-exchange=true',
|
||||
'--peer-id-prefix=-TR2770-',
|
||||
'--user-agent=Transmission/2.77',
|
||||
'--log-level=info',
|
||||
'--log-level=notice',
|
||||
'--seed-ratio=1.0',
|
||||
'--bt-seed-unverified=true',
|
||||
'--max-overall-upload-limit=1M',
|
||||
'--max-overall-download-limit=0',
|
||||
'--max-connection-per-server=4',
|
||||
'--max-concurrent-downloads=5',
|
||||
'--max-concurrent-downloads=10',
|
||||
'--check-certificate=false',
|
||||
'--on-download-complete=' . $this->completeHook,
|
||||
];
|
||||
}
|
||||
public function start($bin = null)
|
||||
|
||||
@@ -11,6 +11,7 @@ class DBConn
|
||||
{
|
||||
$this->conn = \OC::$server->getDatabaseConnection();
|
||||
$this->queryBuilder = $this->conn->getQueryBuilder();
|
||||
$this->prefixedTable = $this->queryBuilder->getTableName($this->table);
|
||||
//$container = \OC::$server->query(\OCP\IServerContainer::class);
|
||||
//Helper::debug(get_class($container->query(\OCP\RichObjectStrings\IValidator::class)));
|
||||
//$this->conn = \OC::$server->query(Connection::class);//working only with 22
|
||||
@@ -46,17 +47,28 @@ class DBConn
|
||||
return $queryBuilder->fetchAll();
|
||||
}
|
||||
|
||||
public function getYoutubeByUid($uid)
|
||||
public function getUidByGid($gid)
|
||||
{
|
||||
$queryBuilder = $this->queryBuilder
|
||||
->select('uid')
|
||||
->from($this->table)
|
||||
->where('gid = :gid')
|
||||
->setParameter('gid', $gid)
|
||||
->execute();
|
||||
return $queryBuilder->fetchColumn();
|
||||
}
|
||||
|
||||
public function getYoutubeByUid($uid)
|
||||
{
|
||||
$qb = $this->queryBuilder
|
||||
->select('*')
|
||||
->from($this->table)
|
||||
->where('uid = :uid')
|
||||
->where('type = :type')
|
||||
->andWhere('type = :type')
|
||||
->setParameter('uid', $uid)
|
||||
->setParameter('type', 2)
|
||||
->setParameter('type', Helper::DOWNLOADTYPE['YOUTUBE-DL'])
|
||||
->execute();
|
||||
return $queryBuilder->fetchAll();
|
||||
return $qb->fetchAll();
|
||||
}
|
||||
|
||||
public function getByGid($gid)
|
||||
@@ -70,34 +82,34 @@ class DBConn
|
||||
return $queryBuilder->fetch();
|
||||
}
|
||||
|
||||
public function save(array $keys, $values = array(),$conditions = array())
|
||||
public function save(array $keys, $values = array(), $conditions = array())
|
||||
{
|
||||
return $this->conn->setValues($this->table, $keys, $values,$conditions);
|
||||
return $this->conn->setValues($this->table, $keys, $values, $conditions);
|
||||
}
|
||||
|
||||
public function deleteByGid($gid)
|
||||
{
|
||||
// $sql = sprintf("DELETE FROM %s WHERE gid = ?",'*PREFIX*'.$this->table);
|
||||
// return $this->conn->executeStatement($sql,array($gid));
|
||||
$qb = $this->queryBuilder
|
||||
->delete($this->table)
|
||||
->where('gid = :gid')
|
||||
->setParameter('gid', $gid);
|
||||
return $qb->execute();
|
||||
}
|
||||
public function execute($sql, $values)
|
||||
public function executeUpdate($sql, $values)
|
||||
{
|
||||
return $this->conn->executeUpdate($sql, $values);
|
||||
}
|
||||
|
||||
// for some reason this doesn't work
|
||||
public function updateStatus($gid, $status = 1)
|
||||
{
|
||||
$query = $this->queryBuilder;
|
||||
$query->update('ncdownloader_info')
|
||||
->set("data", $query->createNamedParameter($value))
|
||||
->where($query->expr()->eq('gid', $query->createNamedParameter($gid)));
|
||||
// ->setParameter('gid', $gid);
|
||||
// return $query->execute();
|
||||
//return $query->getSQL();
|
||||
return $this->queryBuilder->getSQL();
|
||||
->set("status", $query->createNamedParameter($status))
|
||||
->where('gid = :gid')
|
||||
->setParameter('gid', $gid);
|
||||
return $query->execute();
|
||||
//$sql = sprintf("UPDATE %s set status = ? WHERE gid = ?", $this->prefixedTable);
|
||||
//$this->execute($sql, [$status, $gid]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use OC\Files\Filesystem;
|
||||
class Helper
|
||||
{
|
||||
public const DOWNLOADTYPE = ['ARIA2' => 1, 'YOUTUBE-DL' => 2, 'OTHERS' => 3];
|
||||
public const STATUS = ['ACTIVE' => 1, 'PAUSED' => 2, 'COMPLETE' => 3, 'ERROR' => 4];
|
||||
public const STATUS = ['ACTIVE' => 1, 'PAUSED' => 2, 'COMPLETE' => 3, 'WAITING' => 4,'ERROR' => 5];
|
||||
|
||||
public static function isUrl($URL)
|
||||
{
|
||||
@@ -193,7 +193,7 @@ class Helper
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function findBinaryPath($program)
|
||||
public static function findBinaryPath($program,$default = null)
|
||||
{
|
||||
$memcache = \OC::$server->getMemCacheFactory()->createDistributed('findBinaryPath');
|
||||
if ($memcache->hasKey($program)) {
|
||||
@@ -204,7 +204,7 @@ class Helper
|
||||
$result = null;
|
||||
$exeSniffer = new ExecutableFinder();
|
||||
// Returns null if nothing is found
|
||||
$result = $exeSniffer->find($program, null, $paths);
|
||||
$result = $exeSniffer->find($program, $default, $paths);
|
||||
// store the value for 5 minutes
|
||||
$memcache->set($program, $result, 300);
|
||||
return $result;
|
||||
|
||||
@@ -14,7 +14,7 @@ class Youtube
|
||||
private $format = 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best';
|
||||
private $options = [];
|
||||
private $downloadDir;
|
||||
private $timeout = 60 * 60 * 15;
|
||||
private $timeout = 60 * 60 * 3;//3 hours
|
||||
private $outTpl = "/%(id)s-%(title)s.%(ext)s";
|
||||
private $defaultDir = "/tmp/downloads";
|
||||
private $env = [];
|
||||
|
||||
@@ -44,8 +44,8 @@ class YoutubeHelper
|
||||
if (isset($status)) {
|
||||
$this->status = trim($status);
|
||||
}
|
||||
$sql = sprintf("UPDATE %s set status = ? WHERE gid = ?", $this->tablename);
|
||||
$this->dbconn->execute($sql, [$this->status, $this->gid]);
|
||||
//$sql = sprintf("UPDATE %s set status = ? WHERE gid = ?", $this->tablename);
|
||||
$this->dbconn->updateStatus($this->gid, $this->status);
|
||||
}
|
||||
public function run($buffer, $url)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ class YoutubeHelper
|
||||
$percentage = $match['percentage'];
|
||||
$speed = $match['speed'] . "|" . $match['eta'];
|
||||
$sql = sprintf("UPDATE %s set filesize = ?,speed = ?,progress = ? WHERE gid = ?", $this->tablename);
|
||||
$this->dbconn->execute($sql, [$this->filesize, $speed, $percentage, $this->gid]);
|
||||
$this->dbconn->executeUpdate($sql, [$this->filesize, $speed, $percentage, $this->gid]);
|
||||
/* $data = [
|
||||
'filesize' => $size,
|
||||
'speed' => $speed,
|
||||
|
||||
Reference in New Issue
Block a user