Allowing for manually setting binary path for both Aria2 and Youtube-dl
This commit is contained in:
@@ -36,7 +36,11 @@ class Application extends App
|
|||||||
});
|
});
|
||||||
|
|
||||||
$container->registerService('Youtube', function (IContainer $container) {
|
$container->registerService('Youtube', function (IContainer $container) {
|
||||||
return new Youtube(['downloadDir' => $this->getRealDownloadDir()]);
|
$config = [
|
||||||
|
'binary' => $this->settings->setType(Settings::TYPE['SYSTEM'])->get("ncd_yt_binary"),
|
||||||
|
'downloadDir' => $this->getRealDownloadDir(),
|
||||||
|
];
|
||||||
|
return new Youtube($config);
|
||||||
});
|
});
|
||||||
|
|
||||||
$container->registerService('Settings', function (IContainer $container) {
|
$container->registerService('Settings', function (IContainer $container) {
|
||||||
@@ -112,8 +116,14 @@ class Application extends App
|
|||||||
if (is_array($customSettings = $this->settings->getAria2())) {
|
if (is_array($customSettings = $this->settings->getAria2())) {
|
||||||
$settings = array_merge($customSettings, $settings);
|
$settings = array_merge($customSettings, $settings);
|
||||||
}
|
}
|
||||||
$token = $this->settings->setType(1)->get('ncd_rpctoken');
|
$token = $this->settings->setType(Settings::TYPE['SYSTEM'])->get('ncd_rpctoken');
|
||||||
$config = ['dir' => $realDownloadDir, 'conf_dir' => $aria2_dir, 'token' => $token, 'settings' => $settings];
|
$config = [
|
||||||
|
'dir' => $realDownloadDir,
|
||||||
|
'conf_dir' => $aria2_dir,
|
||||||
|
'token' => $token,
|
||||||
|
'settings' => $settings,
|
||||||
|
'binary' => $this->settings->setType(Settings::TYPE['SYSTEM'])->get('ncd_aria2_binary'),
|
||||||
|
];
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<summary>Aria2 and youtube-dl web gui for nextcloud</summary>
|
<summary>Aria2 and youtube-dl web gui for nextcloud</summary>
|
||||||
<description>built-in torrent search;Start and stop Aria2 process, manage Aria2 from the web;
|
<description>built-in torrent search;Start and stop Aria2 process, manage Aria2 from the web;
|
||||||
Download videos from youtube, twitter and other sites;</description>
|
Download videos from youtube, twitter and other sites;</description>
|
||||||
<version>0.1.2</version>
|
<version>0.1.3</version>
|
||||||
<licence>agpl</licence>
|
<licence>agpl</licence>
|
||||||
<author mail="freefallbenson@gmail.com" homepage="https://github.com/shiningw">jiaxinhuang</author>
|
<author mail="freefallbenson@gmail.com" homepage="https://github.com/shiningw">jiaxinhuang</author>
|
||||||
<namespace>NCDownloader</namespace>
|
<namespace>NCDownloader</namespace>
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class SettingsController extends Controller
|
|||||||
|
|
||||||
public function admin()
|
public function admin()
|
||||||
{
|
{
|
||||||
$this->settings->setType($this->settings::SYSTEM);
|
$this->settings->setType($this->settings::TYPE['SYSTEM']);
|
||||||
$params = $this->request->getParams();
|
$params = $this->request->getParams();
|
||||||
foreach ($params as $key => $value) {
|
foreach ($params as $key => $value) {
|
||||||
if (substr($key, 0, 1) == '_') {
|
if (substr($key, 0, 1) == '_') {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Admin implements ISettings {
|
|||||||
* @return TemplateResponse
|
* @return TemplateResponse
|
||||||
*/
|
*/
|
||||||
public function getForm() {
|
public function getForm() {
|
||||||
$this->settings->setType($this->settings::SYSTEM);
|
$this->settings->setType($this->settings::TYPE['SYSTEM']);
|
||||||
$parameters = [
|
$parameters = [
|
||||||
"path" => "/apps/ncdownloader/admin/save",
|
"path" => "/apps/ncdownloader/admin/save",
|
||||||
"ncd_yt_binary" => $this->settings->get("ncd_yt_binary"),
|
"ncd_yt_binary" => $this->settings->get("ncd_yt_binary"),
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ class Aria2
|
|||||||
}
|
}
|
||||||
public function isInstalled()
|
public function isInstalled()
|
||||||
{
|
{
|
||||||
return (bool) isset($this->bin);
|
return (bool) (isset($this->bin) && @is_executable($this->bin));
|
||||||
}
|
}
|
||||||
public function isRunning()
|
public function isRunning()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class Helper
|
|||||||
{
|
{
|
||||||
public const DOWNLOADTYPE = ['ARIA2' => 1, 'YOUTUBE-DL' => 2, 'OTHERS' => 3];
|
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, 'ERROR' => 4];
|
||||||
|
|
||||||
public static function isUrl($URL)
|
public static function isUrl($URL)
|
||||||
{
|
{
|
||||||
$URLPattern = '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}'
|
$URLPattern = '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}'
|
||||||
|
|||||||
@@ -17,15 +17,13 @@ class Settings extends AllConfig
|
|||||||
|
|
||||||
//type of settings (system = 1 or app =2)
|
//type of settings (system = 1 or app =2)
|
||||||
private $type;
|
private $type;
|
||||||
const SYSTEM = 0x001;
|
public const TYPE = ['SYSTEM' => 0x001, 'USER' => 0x010, 'APP' => 0x100];
|
||||||
const USER = 0x010;
|
|
||||||
const APP = 0x100;
|
|
||||||
public function __construct($user = null)
|
public function __construct($user = null)
|
||||||
{
|
{
|
||||||
$this->appConfig = \OC::$server->getAppConfig();
|
$this->appConfig = \OC::$server->getAppConfig();
|
||||||
$this->sysConfig = \OC::$server->getSystemConfig();
|
$this->sysConfig = \OC::$server->getSystemConfig();
|
||||||
$this->appName = 'ncdownloader';
|
$this->appName = 'ncdownloader';
|
||||||
$this->type = self::USER;
|
$this->type = self::TYPE['USER'];
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->allConfig = new AllConfig($this->sysConfig);
|
$this->allConfig = new AllConfig($this->sysConfig);
|
||||||
//$this->connAdapter = \OC::$server->getDatabaseConnection();
|
//$this->connAdapter = \OC::$server->getDatabaseConnection();
|
||||||
@@ -38,9 +36,9 @@ class Settings extends AllConfig
|
|||||||
}
|
}
|
||||||
public function get($key, $default = null)
|
public function get($key, $default = null)
|
||||||
{
|
{
|
||||||
if ($this->type == self::USER && isset($this->user)) {
|
if ($this->type == self::TYPE['USER'] && isset($this->user)) {
|
||||||
return $this->allConfig->getUserValue($this->user, $this->appName, $key, $default);
|
return $this->allConfig->getUserValue($this->user, $this->appName, $key, $default);
|
||||||
} else if ($this->type == self::SYSTEM) {
|
} else if ($this->type == self::TYPE['SYSTEM']) {
|
||||||
return $this->allConfig->getSystemValue($key, $default);
|
return $this->allConfig->getSystemValue($key, $default);
|
||||||
} else {
|
} else {
|
||||||
return $this->allConfig->getAppValue($this->appName, $key, $default);
|
return $this->allConfig->getAppValue($this->appName, $key, $default);
|
||||||
@@ -53,7 +51,7 @@ class Settings extends AllConfig
|
|||||||
}
|
}
|
||||||
public function getAll()
|
public function getAll()
|
||||||
{
|
{
|
||||||
if ($this->type === self::APP) {
|
if ($this->type === self::TYPE['APP']) {
|
||||||
return $this->getAllAppValues();
|
return $this->getAllAppValues();
|
||||||
} else {
|
} else {
|
||||||
$data = $this->getAllUserSettings();
|
$data = $this->getAllUserSettings();
|
||||||
@@ -63,9 +61,9 @@ class Settings extends AllConfig
|
|||||||
}
|
}
|
||||||
public function save($key, $value)
|
public function save($key, $value)
|
||||||
{
|
{
|
||||||
if ($this->type == self::USER && isset($this->user)) {
|
if ($this->type == self::TYPE['USER'] && isset($this->user)) {
|
||||||
return $this->allConfig->setUserValue($this->user, $this->appName, $key, $value);
|
return $this->allConfig->setUserValue($this->user, $this->appName, $key, $value);
|
||||||
} else if ($this->type == self::SYSTEM) {
|
} else if ($this->type == self::TYPE['SYSTEM']) {
|
||||||
return $this->allConfig->setSystemValue($key, $value);
|
return $this->allConfig->setSystemValue($key, $value);
|
||||||
} else {
|
} else {
|
||||||
return $this->allConfig->setAppValue($this->appName, $key, $value);
|
return $this->allConfig->setAppValue($this->appName, $key, $value);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Youtube
|
|||||||
public function __construct($config)
|
public function __construct($config)
|
||||||
{
|
{
|
||||||
$config += ['downloadDir' => '/tmp/downloads'];
|
$config += ['downloadDir' => '/tmp/downloads'];
|
||||||
$this->bin = Helper::findBinaryPath('youtube-dl');
|
$this->bin = $config['binary'] ?? Helper::findBinaryPath('youtube-dl');
|
||||||
$this->init();
|
$this->init();
|
||||||
$this->setDownloadDir($config['downloadDir']);
|
$this->setDownloadDir($config['downloadDir']);
|
||||||
}
|
}
|
||||||
@@ -183,7 +183,7 @@ class Youtube
|
|||||||
}
|
}
|
||||||
public function isInstalled()
|
public function isInstalled()
|
||||||
{
|
{
|
||||||
return (bool) isset($this->bin);
|
return (bool) (isset($this->bin) && @is_executable($this->bin));
|
||||||
}
|
}
|
||||||
public static function install()
|
public static function install()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ import helper from './helper';
|
|||||||
window.addEventListener('DOMContentLoaded', function () {
|
window.addEventListener('DOMContentLoaded', function () {
|
||||||
|
|
||||||
eventHandler.add('click', '.ncdownloader-admin-settings', 'input[type="button"]', function (event) {
|
eventHandler.add('click', '.ncdownloader-admin-settings', 'input[type="button"]', function (event) {
|
||||||
e.stopPropagation();
|
event.stopPropagation();
|
||||||
OC_msg.startSaving('#ncdownloader-message-banner');
|
OC_msg.startSaving('#ncdownloader-message-banner');
|
||||||
const target = this.getAttribute("data-rel");
|
const target = this.getAttribute("data-rel");
|
||||||
|
let inputData = helper.getData(target);
|
||||||
const path = inputData.url || "/apps/ncdownloader/admin/save";
|
const path = inputData.url || "/apps/ncdownloader/admin/save";
|
||||||
let url = generateUrl(path);
|
let url = generateUrl(path);
|
||||||
Http.getInstance(url).setData(helper.getData(target)).setHandler(function () {
|
Http.getInstance(url).setData(helper.getData(target)).setHandler(function () {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
script("ncdownloader", 'appSettings');
|
script("ncdownloader", 'appSettings');
|
||||||
|
extract($_);
|
||||||
?>
|
?>
|
||||||
<div class="ncdownloader-admin-settings">
|
<div class="ncdownloader-admin-settings">
|
||||||
<form id="ncdownloader" class="section">
|
<form id="ncdownloader" class="section">
|
||||||
<h2>ncDownloader admin Settings</h2>
|
<h2>ncDownloader admin Settings</h2>
|
||||||
<div>
|
<div>
|
||||||
<span id="ncdownloader-message"></span>
|
<span id="ncdownloader-message-banner"></span>
|
||||||
</div>
|
</div>
|
||||||
<div id="ncd_rpctoken_settings" path="<?php print $path;?>">
|
<div id="ncd_rpctoken_settings" path="<?php print $path;?>">
|
||||||
<label for="ncd_rpctoken">
|
<label for="ncd_rpctoken">
|
||||||
@@ -16,5 +17,23 @@ script("ncdownloader", 'appSettings');
|
|||||||
placeholder="ncdownloader123" />
|
placeholder="ncdownloader123" />
|
||||||
<input type="button" value="<?php print($l->t('Save'));?>" data-rel="ncd_rpctoken_settings" />
|
<input type="button" value="<?php print($l->t('Save'));?>" data-rel="ncd_rpctoken_settings" />
|
||||||
</div>
|
</div>
|
||||||
|
<div id="ncd_yt_binary_container" path="<?php print $path;?>">
|
||||||
|
<label for="ncd_yt_binary">
|
||||||
|
<?php print($l->t('Youtube-dl Binary Path'));?>
|
||||||
|
</label>
|
||||||
|
<input type="text" class="ncd_yt_binary" id="ncd_yt_binary" name="ncd_yt_binary"
|
||||||
|
value="<?php print($ncd_yt_binary ?? '/usr/local/bin/youtube-dl');?>"
|
||||||
|
placeholder='/usr/local/bin/youtube-dl' />
|
||||||
|
<input type="button" value="<?php print($l->t('Save'));?>" data-rel="ncd_yt_binary_container" />
|
||||||
|
</div>
|
||||||
|
<div id="ncd_aria2_binary_container" path="<?php print $path;?>">
|
||||||
|
<label for="ncd_aria2_binary">
|
||||||
|
<?php print($l->t('Aria2 Binary Path'));?>
|
||||||
|
</label>
|
||||||
|
<input type="text" class="ncd_aria2_binary" id="ncd_aria2_binary" name="ncd_aria2_binary"
|
||||||
|
value="<?php print($ncd_aria2_binary ?? '/usr/bin/aria2c');?>"
|
||||||
|
placeholder="/usr/bin/aria2c" />
|
||||||
|
<input type="button" value="<?php print($l->t('Save'));?>" data-rel="ncd_aria2_binary" />
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user