fixed youtube-dl issues

This commit is contained in:
huangjx
2021-09-11 15:07:01 +08:00
parent bf539e90b7
commit cba9d22cc8
3 changed files with 53 additions and 38 deletions

View File

@@ -2,33 +2,40 @@
namespace OCA\NCDownloader\AppInfo;
use OCA\NCDownloader\Controller\MainController;
use OCA\NCDownloader\Controller\Aria2Controller;
use OCA\NCDownloader\Controller\MainController;
use OCA\NCDownloader\Tools\Aria2;
use OCA\NCDownloader\Tools\Helper;
use OCA\NCDownloader\Tools\Settings;
use OCA\NCDownloader\Tools\Youtube;
use OCP\AppFramework\App;
use OCP\IContainer;
use \OC\Files\Filesystem;
class Application extends App
{
public function __construct(array $urlParams = array())
{
parent::__construct('ncdownloader', $urlParams);
$user = \OC::$server->getUserSession()->getUser();
$this->uid = ($user) ? $user->getUID() : '';
$this->settings = new Settings($this->uid);
$this->dataDir = \OC::$server->getSystemConfig()->getValue('datadirectory');
$this->userFolder = Helper::getUserFolder($this->uid);
$container = $this->getContainer();
$container->registerService('UserId', function (IContainer $container) {
$user = \OC::$server->getUserSession()->getUser();
return ($user) ? $user->getUID() : '';
return $this->uid;
});
$container->registerService('Aria2', function (IContainer $container) {
$uid = $container->query('UserId');
return new Aria2($this->getConfig($uid));
return new Aria2($this->getConfig());
});
$container->registerService('Youtube', function (IContainer $container) {
return new Youtube(['downloadDir' => $this->getRealDownloadDir()]);
});
$container->registerService('Settings', function (IContainer $container) {
$uid = $container->query('UserId');
return new Settings($uid);
return new Settings($this->uid);
});
$container->registerService('MainController', function (IContainer $container) {
@@ -37,7 +44,8 @@ class Application extends App
$container->query('Request'),
$container->query('UserId'),
\OC::$server->getL10N('ncdownloader'),
\OC::$server->getRootFolder(),
//\OC::$server->getRootFolder(),
$container->query("Youtube"),
$container->query('Aria2')
);
});
@@ -54,26 +62,28 @@ class Application extends App
});
}
private function getConfig($uid)
private function getRealDownloadDir()
{
//relative nextcloud user path
$dir = $this->settings->get('ncd_downloader_dir') ?? "/Downloads";
return $this->dataDir . $this->userFolder . $dir;
}
private function getConfig()
{
//$this->config = \OC::$server->getAppConfig();
$this->settings = new Settings($uid);
$this->userFolder = Filesystem::getRoot();
$this->dataDir = \OC::$server->getSystemConfig()->getValue('datadirectory');
//relative nextcloud user path
$this->downloadDir = $this->settings->get('ncd_downloader_dir') ?? "/Downloads";
$realDownloadDir = $this->getRealDownloadDir();
$this->torrentsDir = $this->settings->get('torrents_dir');
//get the absolute path
$this->realDownloadDir = $this->dataDir . $this->userFolder . $this->downloadDir;
$aria2_dir = $this->dataDir . "/aria2";
$this->appPath = \OC::$server->getAppManager()->getAppPath('ncdownloader');
//$this->appPath = \OC::$server->getAppManager()->getAppPath('ncdownloader');
$settings['seed_time'] = $this->settings->get("ncd_seed_time");
$settings['seed_ratio'] = $this->settings->get("ncd_seed_ratio");
if (is_array($customSettings = $this->settings->getAria2())) {
$settings = array_merge($customSettings, $settings);
}
$token = $this->settings->setType(1)->get('ncd_rpctoken');
$config = ['dir' => $this->realDownloadDir, 'conf_dir' => $aria2_dir, 'token' => $token, 'settings' => $settings];
$config = ['dir' => $realDownloadDir, 'conf_dir' => $aria2_dir, 'token' => $token, 'settings' => $settings];
return $config;
}