fixed #15;added support for downloading via bittorrent files;added new class for getting download statistics
This commit is contained in:
@@ -3,6 +3,7 @@ namespace OCA\NCDownloader\Controller;
|
||||
|
||||
use OCA\NCDownloader\Tools\Aria2;
|
||||
use OCA\NCDownloader\Tools\DBConn;
|
||||
use OCA\NCDownloader\Tools\Counters;
|
||||
use OCA\NCDownloader\Tools\folderScan;
|
||||
use OCA\NCDownloader\Tools\Helper;
|
||||
use OCA\NCDownloader\Tools\Settings;
|
||||
@@ -38,6 +39,8 @@ class Aria2Controller extends Controller
|
||||
$this->aria2 = $aria2;
|
||||
$this->aria2->init();
|
||||
$this->dbconn = new DBConn();
|
||||
$this->counters = new Counters($aria2, $this->dbconn,$UserId);
|
||||
|
||||
}
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
@@ -98,7 +101,7 @@ class Aria2Controller extends Controller
|
||||
return ['message' => $this->l10n->t("DONE!"), 'status' => 1];
|
||||
}
|
||||
if (is_string($result)) {
|
||||
return ['message' => $this->l10n->t($result), 'status' => 1];
|
||||
return ['message' => $this->l10n->t("DONE!"), 'status' => 1];
|
||||
}
|
||||
} else {
|
||||
return ['error' => $this->l10n->t("FAILED!"), 'status' => 0];
|
||||
@@ -140,7 +143,7 @@ class Aria2Controller extends Controller
|
||||
public function getStatus($path)
|
||||
{
|
||||
//$path = $this->request->getRequestUri();
|
||||
$counter = $this->getCounters();
|
||||
$counter = $this->counters->getCounters();
|
||||
folderScan::sync();
|
||||
switch (strtolower($path)) {
|
||||
case "active":
|
||||
@@ -269,6 +272,9 @@ class Aria2Controller extends Controller
|
||||
if (empty($resp)) {
|
||||
return $data;
|
||||
}
|
||||
if (isset($resp['error'])) {
|
||||
return $resp;
|
||||
}
|
||||
|
||||
$data = array_filter($resp, function ($value) {
|
||||
$gid = $value['following'] ?? $value['gid'];
|
||||
@@ -277,26 +283,4 @@ class Aria2Controller extends Controller
|
||||
|
||||
return $data;
|
||||
}
|
||||
private function getCounters()
|
||||
{
|
||||
return [
|
||||
'active' => $this->getCounter(),
|
||||
'waiting' => $this->getCounter('tellWaiting'),
|
||||
'complete' => $this->getCounter('tellStopped'),
|
||||
'fail' => $this->getCounter('tellFail'),
|
||||
];
|
||||
}
|
||||
private function getCounter($action = 'tellActive')
|
||||
{
|
||||
if ($action === 'tellActive') {
|
||||
$data = $this->aria2->{$action}([]);
|
||||
} else {
|
||||
$data = $this->aria2->{$action}($this->minmax);
|
||||
}
|
||||
|
||||
if (!is_array($data)) {
|
||||
return 0;
|
||||
}
|
||||
return count($this->filterData($data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace OCA\NCDownloader\Controller;
|
||||
|
||||
use OCA\NCDownloader\Tools\Aria2;
|
||||
use OCA\NCDownloader\Tools\Counters;
|
||||
use OCA\NCDownloader\Tools\DBConn;
|
||||
use OCA\NCDownloader\Tools\Helper;
|
||||
use OCP\AppFramework\Controller;
|
||||
@@ -33,6 +34,7 @@ class MainController extends Controller
|
||||
$this->aria2 = $aria2;
|
||||
$this->aria2->init();
|
||||
$this->dbconn = new DBConn();
|
||||
$this->counters = new Counters($aria2, $this->dbconn, $UserId);
|
||||
}
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
@@ -43,24 +45,24 @@ class MainController extends Controller
|
||||
// $str = \OC::$server->getDatabaseConnection()->getInner()->getPrefix();
|
||||
//$config = \OC::$server->getAppConfig();
|
||||
OC_Util::addScript($this->appName, 'app');
|
||||
// OC_Util::addStyle($this->appName, 'style');
|
||||
// OC_Util::addStyle($this->appName, 'table');
|
||||
// OC_Util::addStyle($this->appName, 'table');
|
||||
$params = array();
|
||||
$params['aria2_running'] = $this->aria2->isRunning();
|
||||
$params['aria2_installed'] = $this->aria2->isInstalled();
|
||||
$params['youtube_installed'] = (bool) Helper::findBinaryPath('youtube-dl');
|
||||
$params['counter'] = $this->counters->getCounters();
|
||||
|
||||
$response = new TemplateResponse($this->appName, 'Index', $params);
|
||||
|
||||
return $response;
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function Download()
|
||||
{
|
||||
$url = trim($this->request->getParam('form_input_text'));
|
||||
$url = trim($this->request->getParam('text-input-value'));
|
||||
//$type = trim($this->request->getParam('type'));
|
||||
$resp = $this->_download($url);
|
||||
return new JSONResponse($resp);
|
||||
@@ -89,8 +91,39 @@ class MainController extends Controller
|
||||
'data' => serialize(['link' => $url]),
|
||||
];
|
||||
$this->dbconn->save($data);
|
||||
$resp = ['message' => $filename, 'result' => $result,'file' => $filename];
|
||||
$resp = ['message' => $filename, 'result' => $result, 'file' => $filename];
|
||||
return $resp;
|
||||
}
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function Upload()
|
||||
{
|
||||
if (is_uploaded_file($file = $_FILES['torrentfile']['tmp_name'])) {
|
||||
$file = $this->aria2->getTorrentsDir() . '/' . Helper::cleanString($_FILES['torrentfile']['name']);
|
||||
|
||||
move_uploaded_file($_FILES['torrentfile']['tmp_name'], $file);
|
||||
|
||||
$result = $this->aria2->btDownload($file);
|
||||
if (!$result) {
|
||||
return ['error' => 'failed to download the file for some reason!'];
|
||||
}
|
||||
if (isset($result['error'])) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'uid' => $this->uid,
|
||||
'gid' => $result['gid'],
|
||||
'type' => Helper::DOWNLOADTYPE['ARIA2'],
|
||||
'filename' => $result['filename'] ?? 'unknown',
|
||||
'timestamp' => time(),
|
||||
];
|
||||
$this->dbconn->save($data);
|
||||
$resp = ['message' => $result['filename'], 'result' => $result['gid'], 'file' => $result['filename']];
|
||||
}
|
||||
return new JSONResponse($resp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class SearchController extends Controller
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$keyword = trim($this->request->getParam('form_input_text'));
|
||||
$keyword = trim($this->request->getParam('text-input-value'));
|
||||
$site = trim($this->request->getParam('select-value-search'));
|
||||
$this->search->setSite($site);
|
||||
$data = $this->search->go($keyword);
|
||||
|
||||
@@ -77,9 +77,9 @@ class YoutubeController extends Controller
|
||||
public function Download()
|
||||
{
|
||||
$params = array();
|
||||
$url = trim($this->request->getParam('form_input_text'));
|
||||
$url = trim($this->request->getParam('text-input-value'));
|
||||
$yt = $this->youtube;
|
||||
$yt->audioOnly = (bool) $this->request->getParam('audioOnly');
|
||||
$yt->audioOnly = (bool) $this->request->getParam('audio-only');
|
||||
if (!$yt->isInstalled()) {
|
||||
return new JSONResponse($this->installYTD());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user