An attempt to obtain a functional version with the various fixes implemented so far.

This commit is contained in:
darkpisto
2025-12-11 14:05:40 +01:00
parent 6a36b24162
commit ddcaf72e6e
13 changed files with 65 additions and 57 deletions

View File

@@ -20,7 +20,7 @@ download videos from 700+ video sites(youtube,youku,vimo,dailymotion,twitter,fac
<repository>https://github.com/shiningw/ncdownloader</repository> <repository>https://github.com/shiningw/ncdownloader</repository>
<dependencies> <dependencies>
<php min-version="7.3" max-version="8.3" /> <php min-version="7.3" max-version="8.3" />
<nextcloud min-version="20" max-version="31"/> <nextcloud min-version="20" max-version="32"/>
</dependencies> </dependencies>
<navigations> <navigations>
<navigation> <navigation>

13
hooks/run.php Normal file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/php
<?php
require __DIR__ . "/../../../3rdparty/autoload.php";
require __DIR__ . "/../lib/Command/.php";
require __DIR__. "/../../../lib/composer/autoload.php";
use OCA\NCDownloader\Command\cmdTool;
use Symfony\Component\Console\Application;
$app = new Application();
$cmd = new cmdTool();
$app->add($cmd);
$app->run();

View File

@@ -11,9 +11,12 @@ use Symfony\Component\Console\Output\OutputInterface;
class Aria2Command extends Base class Aria2Command extends Base
{ {
// public function __construct()
private $dbconn; private $dbconn;
public function __construct(\OCP\IDBConnection $connection) public function __construct(\OCP\IDBConnection $connection)
{ {
// $this->dbconn = new DbHelper();
$this->dbconn = new DbHelper($connection); $this->dbconn = new DbHelper($connection);
parent::__construct(); parent::__construct();
} }

View File

@@ -11,6 +11,7 @@ use OCP\AppFramework\Http\JSONResponse;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\IL10N; use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;
use OC_Util;
use \OC\Files\Filesystem; use \OC\Files\Filesystem;
class Aria2Controller extends Controller class Aria2Controller extends Controller
@@ -33,9 +34,9 @@ class Aria2Controller extends Controller
$this->uid = $UserId; $this->uid = $UserId;
$this->l10n = $IL10N; $this->l10n = $IL10N;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); $this->urlGenerator = \OC::$server->getURLGenerator();
$this->downloadDir = Helper::getDownloadDir(); $this->downloadDir = Helper::getDownloadDir();
\OC_Util::setupFS(); OC_Util::setupFS();
//$this->config = \OC::$server->getAppConfig(); //$this->config = \OC::$server->getAppConfig();
$this->aria2 = $aria2; $this->aria2 = $aria2;
$this->aria2->init(); $this->aria2->init();

View File

@@ -15,6 +15,7 @@ use OCP\AppFramework\Http\TemplateResponse;
//use OCP\Files\IRootFolder; //use OCP\Files\IRootFolder;
use OCP\IL10N; use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;
use OC_Util;
use OCP\Util; use OCP\Util;
class MainController extends Controller class MainController extends Controller
@@ -46,7 +47,7 @@ class MainController extends Controller
//$this->rootFolder = $rootFolder; //$this->rootFolder = $rootFolder;
$this->aria2 = $aria2; $this->aria2 = $aria2;
$this->aria2->init(); $this->aria2->init();
$this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); $this->urlGenerator = \OC::$server->getURLGenerator();
$this->dbconn = new DbHelper(); $this->dbconn = new DbHelper();
$this->counters = new Counters($aria2, $this->dbconn, $UserId); $this->counters = new Counters($aria2, $this->dbconn, $UserId);
$this->ytdl = $ytdl; $this->ytdl = $ytdl;
@@ -63,8 +64,8 @@ class MainController extends Controller
{ {
// $str = \OC::$server->getDatabaseConnection()->getInner()->getPrefix(); // $str = \OC::$server->getDatabaseConnection()->getInner()->getPrefix();
//$config = \OC::$server->getAppConfig(); //$config = \OC::$server->getAppConfig();
Util::addScript($this->appName, 'app'); Util::addInitScript($this->appName, 'app');
Util::addStyle($this->appName, 'app'); OC_Util::addStyle($this->appName, 'app');
$params = $this->buildParams(); $params = $this->buildParams();
$response = new TemplateResponse($this->appName, 'Index', $params); $response = new TemplateResponse($this->appName, 'Index', $params);

View File

@@ -23,7 +23,7 @@ class SearchController extends Controller
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->appName = $appName; $this->appName = $appName;
$this->uid = $UserId; $this->uid = $UserId;
$this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); $this->urlGenerator = \OC::$server->getURLGenerator();
$this->search = new siteSearch(); $this->search = new siteSearch();
} }
/** /**

View File

@@ -32,7 +32,7 @@ class YtdlController extends Controller
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->appName = $appName; $this->appName = $appName;
$this->uid = $UserId; $this->uid = $UserId;
$this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class); $this->urlGenerator = \OC::$server->getURLGenerator();
$this->l10n = $IL10N; $this->l10n = $IL10N;
$this->downloadDir = Helper::getDownloadDir(); $this->downloadDir = Helper::getDownloadDir();
$this->dbconn = new DbHelper(); $this->dbconn = new DbHelper();

View File

@@ -12,7 +12,7 @@ class Helper
public function __construct() public function __construct()
{ {
$this->conn = \OC::$server->get(\OCP\IDBConnection::class); $this->conn = \OC::$server->getDatabaseConnection();
$this->queryBuilder = $this->conn->getQueryBuilder(); $this->queryBuilder = $this->conn->getQueryBuilder();
$this->prefixedTable = $this->queryBuilder->getTableName($this->table); $this->prefixedTable = $this->queryBuilder->getTableName($this->table);
//$container = \OC::$server->query(\OCP\IServerContainer::class); //$container = \OC::$server->query(\OCP\IServerContainer::class);
@@ -130,7 +130,7 @@ class Helper
public function getDBType(): string public function getDBType(): string
{ {
return \OC::$server->get(\OCP\IConfig::class)->getSystemValue('dbtype', "mysql"); return \OC::$server->getConfig()->getSystemValue('dbtype', "mysql");
} }
public function getExtra($data) public function getExtra($data)

View File

@@ -2,7 +2,9 @@
namespace OCA\NCDownloader\Db; namespace OCA\NCDownloader\Db;
class Settings use OC\AllConfig;
class Settings extends AllConfig
{ {
//@config OC\AppConfig //@config OC\AppConfig
private $appConfig; private $appConfig;
@@ -10,6 +12,8 @@ class Settings
//@OC\SystemConfig //@OC\SystemConfig
private $sysConfig; private $sysConfig;
//@OC\AllConfig
private $allConfig;
private $user; private $user;
private $appName; private $appName;
//type of settings (system = 1 or app =2) //type of settings (system = 1 or app =2)
@@ -18,11 +22,13 @@ class Settings
public const TYPE = ['SYSTEM' => 1, 'USER' => 2, 'APP' => 3]; public const TYPE = ['SYSTEM' => 1, 'USER' => 2, 'APP' => 3];
public function __construct($user = null) public function __construct($user = null)
{ {
$this->appConfig = \OC::$server->get(\OCP\IConfig::class); //$this->appConfig = \OC::$server->getAppConfig();
$this->sysConfig = \OC::$server->get(\OCP\IConfig::class); //$this->appConfig = \OC::$server->getAppConfig();
$this->sysConfig = \OC::$server->getSystemConfig();
$this->appName = 'ncdownloader'; $this->appName = 'ncdownloader';
$this->type = self::TYPE['USER']; $this->type = self::TYPE['USER'];
$this->user = $user; $this->user = $user;
$this->allConfig = new AllConfig($this->sysConfig);
//$this->connAdapter = \OC::$server->getDatabaseConnection(); //$this->connAdapter = \OC::$server->getDatabaseConnection();
//$this->conn = $this->connAdapter->getInner(); //$this->conn = $this->connAdapter->getInner();
} }
@@ -42,16 +48,16 @@ class Settings
public function get($key, $default = null) public function get($key, $default = null)
{ {
if ($this->type == self::TYPE['USER'] && isset($this->user)) { if ($this->type == self::TYPE['USER'] && isset($this->user)) {
return $this->appConfig->getUserValue($this->user, $this->appName, $key, $default); return $this->allConfig->getUserValue($this->user, $this->appName, $key, $default);
} else if ($this->type == self::TYPE['SYSTEM']) { } else if ($this->type == self::TYPE['SYSTEM']) {
return $this->appConfig->getSystemValue($key, $default); return $this->allConfig->getSystemValue($key, $default);
} else { } else {
return $this->appConfig->getAppValue($this->appName, $key, $default); return $this->allConfig->getAppValue($this->appName, $key, $default);
} }
} }
public function getAria2() public function getAria2()
{ {
$settings = $this->appConfig->getUserValue($this->user, $this->appName, "custom_aria2_settings", ''); $settings = $this->allConfig->getUserValue($this->user, $this->appName, "custom_aria2_settings", '');
return json_decode($settings, 1); return json_decode($settings, 1);
} }
@@ -74,11 +80,11 @@ class Settings
{ {
try { try {
if ($this->type == self::TYPE['USER'] && isset($this->user)) { if ($this->type == self::TYPE['USER'] && isset($this->user)) {
$this->appConfig->setUserValue($this->user, $this->appName, $key, $value); $this->allConfig->setUserValue($this->user, $this->appName, $key, $value);
} else if ($this->type == self::TYPE['SYSTEM']) { } else if ($this->type == self::TYPE['SYSTEM']) {
$this->appConfig->setSystemValue($key, $value); $this->allConfig->setSystemValue($key, $value);
} else { } else {
$this->appConfig->setAppValue($this->appName, $key, $value); $this->allConfig->setAppValue($this->appName, $key, $value);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
return ['error' => $e->getMessage()]; return ['error' => $e->getMessage()];
@@ -91,21 +97,21 @@ class Settings
$keys = $this->getAllKeys(); $keys = $this->getAllKeys();
$value = []; $value = [];
foreach ($keys as $key) { foreach ($keys as $key) {
$value[$key] = $this->appConfig->getAppValue($this->appName, $key); $value[$key] = $this->allConfig->getAppValue($this->appName, $key);
} }
return $value; return $value;
} }
public function getAllKeys() public function getAllKeys()
{ {
return $this->appConfig->getAppKeys($this->appName); return $this->allConfig->getAppKeys($this->appName);
} }
public function getAllUserSettings() public function getAllUserSettings()
{ {
$keys = $this->appConfig->getUserKeys($this->user, $this->appName); $keys = $this->allConfig->getUserKeys($this->user, $this->appName);
$value = []; $value = [];
foreach ($keys as $key) { foreach ($keys as $key) {
$value[$key] = $this->appConfig->getUserValue($this->user, $this->appName, $key); $value[$key] = $this->allConfig->getUserValue($this->user, $this->appName, $key);
} }
return $value; return $value;
} }

View File

@@ -15,7 +15,7 @@ class siteSearch
private $defaultSite = __NAMESPACE__ . '\Sites\TPB'; private $defaultSite = __NAMESPACE__ . '\Sites\TPB';
public function __construct() public function __construct()
{ {
$this->container = \OC::$server->get(IServerContainer::class); $this->container = \OC::$server->query(IServerContainer::class);
$this->site = __NAMESPACE__ . '\Sites\TPB'; $this->site = __NAMESPACE__ . '\Sites\TPB';
} }
public function go($keyword): array public function go($keyword): array

View File

@@ -10,8 +10,6 @@ use OCP\Settings\ISettings;
use OCA\NCDownloader\Db\Settings; use OCA\NCDownloader\Db\Settings;
use OCA\NCDownloader\Tools\Helper; use OCA\NCDownloader\Tools\Helper;
use OCP\IUserManager;
class Personal implements ISettings class Personal implements ISettings
{ {
@@ -21,22 +19,18 @@ class Personal implements ISettings
private $timeFactory; private $timeFactory;
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** @var IUserManager */
private $userManager;
private $uid; private $uid;
private $settings; private $settings;
public function __construct( public function __construct(
IDBConnection $connection, IDBConnection $connection,
ITimeFactory $timeFactory, ITimeFactory $timeFactory,
IConfig $config, IConfig $config
IUserManager $userManager
) { ) {
$this->connection = $connection; $this->connection = $connection;
$this->timeFactory = $timeFactory; $this->timeFactory = $timeFactory;
$this->config = $config; $this->config = $config;
$this->userManager = $userManager; $this->uid = \OC::$server->getUserSession()->getUser()->getUID();
$this->uid = \OC::$server->get(\OCP\IUserSession::class)->getUser()->getUID();
$this->settings = new Settings($this->uid); $this->settings = new Settings($this->uid);
} }
@@ -46,9 +40,6 @@ class Personal implements ISettings
public function getForm() public function getForm()
{ {
$path = '/apps/ncdownloader/personal/save'; $path = '/apps/ncdownloader/personal/save';
$user = $this->userManager->get($this->uid);
$groupManager = \OC::$server->get(\OCP\IGroupManager::class);
$isAdmin = ($user !== null) ? $groupManager->isInGroup($user->getUID(), 'admin') : false;
$parameters = [ $parameters = [
"settings" => [ "settings" => [
"ncd_downloader_dir" => Helper::getDownloadDir(), "ncd_downloader_dir" => Helper::getDownloadDir(),
@@ -58,7 +49,7 @@ class Personal implements ISettings
'ncd_seed_time' => $this->settings->get("ncd_seed_time"), 'ncd_seed_time' => $this->settings->get("ncd_seed_time"),
"path" => $path, "path" => $path,
"disallow_aria2_settings" => Helper::getAdminSettings("disallow_aria2_settings"), "disallow_aria2_settings" => Helper::getAdminSettings("disallow_aria2_settings"),
"is_admin" => $isAdmin, "is_admin" => \OC_User::isAdminUser($this->uid),
], ],
"options" => [ "options" => [
[ [

View File

@@ -8,6 +8,7 @@ use OCA\NCDownloader\Aria2\Options as aria2Options;
use OCA\NCDownloader\Db\Settings; use OCA\NCDownloader\Db\Settings;
use OCP\IUser; use OCP\IUser;
use OC\Files\Filesystem; use OC\Files\Filesystem;
use OC_Util;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use OCA\NCDownloader\Aria2\Aria2; use OCA\NCDownloader\Aria2\Aria2;
use OCA\NCDownloader\Ytdl\Ytdl; use OCA\NCDownloader\Ytdl\Ytdl;
@@ -147,6 +148,8 @@ class Helper
if (is_array($msg)) { if (is_array($msg)) {
$msg = implode(",", $msg); $msg = implode(",", $msg);
} }
$logger = \OC::$server->get(LoggerInterface::class);
// $logger = \OC::$server->getLogger();
$logger = self::getLogger(); $logger = self::getLogger();
$logger->error($msg, ['app' => 'ncdownloader']); $logger->error($msg, ['app' => 'ncdownloader']);
} }
@@ -159,19 +162,7 @@ class Helper
{ {
if (!isset($filter)) { if (!isset($filter)) {
$filter = array( $filter = array(
'status', 'status', 'followedBy', 'totalLength', 'errorMessage', 'dir', 'uploadLength', 'completedLength', 'downloadSpeed', 'files', 'numSeeders', 'connections', 'gid', 'following',
'followedBy',
'totalLength',
'errorMessage',
'dir',
'uploadLength',
'completedLength',
'downloadSpeed',
'files',
'numSeeders',
'connections',
'gid',
'following',
); );
} }
$value = array_filter($data, function ($k) use ($filter) { $value = array_filter($data, function ($k) use ($filter) {
@@ -236,7 +227,8 @@ class Helper
if ($memcache->hasKey($program)) { if ($memcache->hasKey($program)) {
return $memcache->get($program); return $memcache->get($program);
} }
$dataPath = \OC::$server->get(\OCP\IConfig::class)->getSystemValue('datadirectory');
$dataPath = \OC::$server->getSystemConfig()->getValue('datadirectory');
$paths = ['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/opt/bin', $dataPath . "/bin"]; $paths = ['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/opt/bin', $dataPath . "/bin"];
$result = $default; $result = $default;
$exeSniffer = new ExecutableFinder(); $exeSniffer = new ExecutableFinder();
@@ -403,13 +395,13 @@ class Helper
public static function getDataDir(): string public static function getDataDir(): string
{ {
return \OC::$server->get(\OCP\IConfig::class)->getSystemValue('datadirectory'); return \OC::$server->getSystemConfig()->getValue('datadirectory');
} }
public static function getLocalFolder(string $path): string public static function getLocalFolder(string $path): string
{ {
if (self::getUID()) { if (self::getUID()) {
\OC_Util::setupFS(); OC_Util::setupFS();
//get the real path of the file in the filesystem //get the real path of the file in the filesystem
return \OC\Files\Filesystem::getLocalFile($path); return \OC\Files\Filesystem::getLocalFile($path);
} }
@@ -429,6 +421,7 @@ class Helper
public static function getUser(): ?IUser public static function getUser(): ?IUser
{ {
// return \OC::$server->getUserSession()->getUser();
return \OC::$server->get(\OCP\IUserSession::class)->getUser(); return \OC::$server->get(\OCP\IUserSession::class)->getUser();
} }
@@ -498,7 +491,7 @@ class Helper
public static function getAppPath(): string public static function getAppPath(): string
{ {
return \OC::$server->get(\OCP\App\IAppManager::class)->getAppPath('ncdownloader'); return \OC::$server->getAppManager()->getAppPath('ncdownloader');
} }
public static function folderUpdated(string $dir): bool public static function folderUpdated(string $dir): bool
{ {

View File

@@ -19,7 +19,7 @@ class Helper
{ {
$this->dbconn = new DbHelper(); $this->dbconn = new DbHelper();
$this->tablename = $this->dbconn->queryBuilder->getTableName("ncdownloader_info"); $this->tablename = $this->dbconn->queryBuilder->getTableName("ncdownloader_info");
$this->user = \OC::$server->get(\OCP\IUserSession::class)->getUser()->getUID(); $this->user = \OC::$server->getUserSession()->getUser()->getUID();
} }
public static function create() public static function create()