Merge branch 'master' of https://github.com/medismail/ncdownloader
This commit is contained in:
@@ -39,8 +39,11 @@ class MainController extends Controller
|
|||||||
$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->youtube = $youtube;
|
$this->youtube = $youtube;
|
||||||
$this->settings = new Settings($UserId);
|
$this->settings = new Settings($this->uid);
|
||||||
|
$this->isAdmin = \OC_User::isAdminUser($this->uid);
|
||||||
|
$this->hideError = $this->settings->get("ncd_hide_errors", false);
|
||||||
|
$this->disable_bt_nonadmin = $this->settings->setType($this->settings::TYPE['SYSTEM'])->get("ncd_disable_bt", false);
|
||||||
|
$this->accessDenied = $this->l10n->t("Sorry,only admin users can download files via BT!");
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
@@ -68,10 +71,11 @@ class MainController extends Controller
|
|||||||
$params['youtube_installed'] = $youtube_installed = $this->youtube->isInstalled();
|
$params['youtube_installed'] = $youtube_installed = $this->youtube->isInstalled();
|
||||||
$params['youtube_bin'] = $youtube_bin = $this->youtube->getBin();
|
$params['youtube_bin'] = $youtube_bin = $this->youtube->getBin();
|
||||||
$params['youtube_executable'] = $youtube_executable = $this->youtube->isExecutable();
|
$params['youtube_executable'] = $youtube_executable = $this->youtube->isExecutable();
|
||||||
$params['ncd_hide_errors'] = $this->settings->get("ncd_hide_errors", false);
|
$params['ncd_hide_errors'] = $this->hideError;
|
||||||
$params['counter'] = $this->counters->getCounters();
|
$params['counter'] = $this->counters->getCounters();
|
||||||
$params['python_installed'] = Helper::pythonInstalled();
|
$params['python_installed'] = Helper::pythonInstalled();
|
||||||
$params['ffmpeg_installed'] = Helper::ffmpegInstalled();
|
$params['ffmpeg_installed'] = Helper::ffmpegInstalled();
|
||||||
|
$params['is_admin'] = $this->isAdmin;
|
||||||
$sites = [];
|
$sites = [];
|
||||||
foreach (Helper::getSearchSites() as $site) {
|
foreach (Helper::getSearchSites() as $site) {
|
||||||
$label = $site['class']::getLabel();
|
$label = $site['class']::getLabel();
|
||||||
@@ -107,10 +111,11 @@ class MainController extends Controller
|
|||||||
$params['errors'] = $errors;
|
$params['errors'] = $errors;
|
||||||
|
|
||||||
$params['settings'] = json_encode([
|
$params['settings'] = json_encode([
|
||||||
'is_admin' => \OC_User::isAdminUser($this->uid),
|
'is_admin' => $this->isAdmin,
|
||||||
'admin_url' => $this->urlGenerator->linkToRoute("settings.AdminSettings.index", ['section' => 'ncdownloader']),
|
'admin_url' => $this->urlGenerator->linkToRoute("settings.AdminSettings.index", ['section' => 'ncdownloader']),
|
||||||
'personal_url' => $this->urlGenerator->linkToRoute("settings.PersonalSettings.index", ['section' => 'ncdownloader']),
|
'personal_url' => $this->urlGenerator->linkToRoute("settings.PersonalSettings.index", ['section' => 'ncdownloader']),
|
||||||
'ncd_hide_errors' => $params['ncd_hide_errors'],
|
'ncd_hide_errors' => $this->hideError,
|
||||||
|
'ncd_disable_bt' => $this->disable_bt_nonadmin,
|
||||||
]);
|
]);
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
@@ -121,6 +126,11 @@ class MainController extends Controller
|
|||||||
public function Download()
|
public function Download()
|
||||||
{
|
{
|
||||||
$url = trim($this->request->getParam('text-input-value'));
|
$url = trim($this->request->getParam('text-input-value'));
|
||||||
|
if (Helper::isMagnet($url)) {
|
||||||
|
if ($this->disable_bt_nonadmin && !($this->isAdmin)) {
|
||||||
|
return new JSONResponse(['error' => $this->accessDenied]);
|
||||||
|
}
|
||||||
|
}
|
||||||
//$type = trim($this->request->getParam('type'));
|
//$type = trim($this->request->getParam('type'));
|
||||||
$resp = $this->_download($url);
|
$resp = $this->_download($url);
|
||||||
return new JSONResponse($resp);
|
return new JSONResponse($resp);
|
||||||
@@ -156,6 +166,9 @@ class MainController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function Upload()
|
public function Upload()
|
||||||
{
|
{
|
||||||
|
if ($this->disable_bt_nonadmin && !$this->isAdmin) {
|
||||||
|
return new JSONResponse(['error' => $this->l10n->t($this->accessDenied)]);
|
||||||
|
}
|
||||||
if (is_uploaded_file($file = $_FILES['torrentfile']['tmp_name'])) {
|
if (is_uploaded_file($file = $_FILES['torrentfile']['tmp_name'])) {
|
||||||
$file = $this->aria2->getTorrentsDir() . '/' . Helper::cleanString($_FILES['torrentfile']['name']);
|
$file = $this->aria2->getTorrentsDir() . '/' . Helper::cleanString($_FILES['torrentfile']['name']);
|
||||||
|
|
||||||
|
|||||||
@@ -61,13 +61,12 @@ class sliderkz extends searchBase implements searchInterface
|
|||||||
try {
|
try {
|
||||||
$response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]);
|
$response = $this->client->request('GET', $this->searchUrl, ['query' => $this->query]);
|
||||||
$resp = $response->toArray();
|
$resp = $response->toArray();
|
||||||
} catch (ExceptionInterface $e) {
|
|
||||||
$this->errors[] = $e->getMessage();
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
if (isset($resp['audios'])) {
|
if (isset($resp['audios'])) {
|
||||||
return array_values($resp["audios"])[0];
|
return array_values($resp["audios"])[0];
|
||||||
}
|
}
|
||||||
|
} catch (ExceptionInterface $e) {
|
||||||
|
$this->errors[] = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,10 @@ class Aria2
|
|||||||
$this->startHook = $startHook;
|
$this->startHook = $startHook;
|
||||||
$this->rpcUrl = sprintf("http://%s:%s/jsonrpc", $host, $port);
|
$this->rpcUrl = sprintf("http://%s:%s/jsonrpc", $host, $port);
|
||||||
$this->tokenString = $token ?? 'ncdownloader123';
|
$this->tokenString = $token ?? 'ncdownloader123';
|
||||||
|
$this->rpcPort = $rpcPort ?? 6800;
|
||||||
|
$this->dlSpeed = $dlSpeed ?? 0;
|
||||||
|
$this->upSpeed = $upSpeed ?? "1M";
|
||||||
|
$this->logLevel = $logLevel ?? 'warn';
|
||||||
$this->setToken($this->tokenString);
|
$this->setToken($this->tokenString);
|
||||||
$this->confDir = $conf_dir;
|
$this->confDir = $conf_dir;
|
||||||
$this->sessionFile = $this->confDir . "/aria2.session";
|
$this->sessionFile = $this->confDir . "/aria2.session";
|
||||||
@@ -333,17 +337,17 @@ class Aria2
|
|||||||
'--save-session=' . $this->sessionFile,
|
'--save-session=' . $this->sessionFile,
|
||||||
'--input-file=' . $this->sessionFile,
|
'--input-file=' . $this->sessionFile,
|
||||||
'--log=' . $this->logFile,
|
'--log=' . $this->logFile,
|
||||||
'--rpc-listen-port=6800',
|
'--rpc-listen-port=' . $this->rpcPort,
|
||||||
'--follow-torrent=true',
|
'--follow-torrent=true',
|
||||||
'--enable-dht=true',
|
'--enable-dht=true',
|
||||||
'--enable-peer-exchange=true',
|
'--enable-peer-exchange=true',
|
||||||
'--peer-id-prefix=-TR2770-',
|
'--peer-id-prefix=-TR2770-',
|
||||||
'--user-agent=Transmission/2.77',
|
'--user-agent=Transmission/2.77',
|
||||||
'--log-level=notice',
|
'--log-level=' . $this->logLevel,
|
||||||
'--seed-ratio=1.0',
|
'--seed-ratio=1.0',
|
||||||
'--bt-seed-unverified=true',
|
'--bt-seed-unverified=true',
|
||||||
'--max-overall-upload-limit=1M',
|
'--max-overall-upload-limit=' . $this->upSpeed,
|
||||||
'--max-overall-download-limit=0',
|
'--max-overall-download-limit=' . $this->dlSpeed,
|
||||||
'--max-connection-per-server=4',
|
'--max-connection-per-server=4',
|
||||||
'--max-concurrent-downloads=10',
|
'--max-concurrent-downloads=10',
|
||||||
'--check-certificate=false',
|
'--check-certificate=false',
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ class Helper
|
|||||||
'/–/' => '-', // UTF-8 hyphen to "normal" hyphen
|
'/–/' => '-', // UTF-8 hyphen to "normal" hyphen
|
||||||
'/[’‘‹›‚]/u' => '', // Literally a single quote
|
'/[’‘‹›‚]/u' => '', // Literally a single quote
|
||||||
'/[“”«»„]/u' => '', // Double quote
|
'/[“”«»„]/u' => '', // Double quote
|
||||||
'/ /' => '_', // nonbreaking space(equiv. to 0x160)
|
//'/ /' => '_', // nonbreaking space(equiv. to 0x160)
|
||||||
// '/[^a-z0-9_\s.-]/i' => '_',
|
// '/[^a-z0-9_\s.-]/i' => '_',
|
||||||
);
|
);
|
||||||
return preg_replace(array_keys($replace), array_values($replace), $string);
|
return preg_replace(array_keys($replace), array_values($replace), $string);
|
||||||
@@ -174,8 +174,17 @@ class Helper
|
|||||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
$error = 'Error:' . curl_error($ch);
|
||||||
|
}
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
file_put_contents($file, $result);
|
if (isset($error)) {
|
||||||
|
throw new \Exception($error);
|
||||||
|
} else {
|
||||||
|
if (!file_put_contents($file, $result)) {
|
||||||
|
throw new \Exception("failed to save " . $file);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function is_function_enabled($function_name)
|
public static function is_function_enabled($function_name)
|
||||||
@@ -327,9 +336,9 @@ class Helper
|
|||||||
return self::doSignal($pid, 9);
|
return self::doSignal($pid, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function pythonInstalled()
|
public static function pythonInstalled(): bool
|
||||||
{
|
{
|
||||||
return (bool) self::findBinaryPath('python');
|
return (self::findBinaryPath('python') || self::findBinaryPath('python3'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function findSearchSites($dir, $suffix = 'php'): array
|
public static function findSearchSites($dir, $suffix = 'php'): array
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ namespace OCA\NCDownloader\Tools;
|
|||||||
|
|
||||||
use OCA\NCDownloader\Tools\Helper;
|
use OCA\NCDownloader\Tools\Helper;
|
||||||
use OCA\NCDownloader\Tools\YoutubeHelper;
|
use OCA\NCDownloader\Tools\YoutubeHelper;
|
||||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
class Youtube
|
class Youtube
|
||||||
@@ -31,7 +30,7 @@ class Youtube
|
|||||||
if (isset($binary) && $this->isExecutable($binary)) {
|
if (isset($binary) && $this->isExecutable($binary)) {
|
||||||
$this->bin = $binary;
|
$this->bin = $binary;
|
||||||
} else {
|
} else {
|
||||||
$this->bin = Helper::findBinaryPath('youtube-dl', __DIR__ . "/../../bin/youtube-dl");
|
$this->bin = Helper::findBinaryPath('youtube-dl', __DIR__ . "/../../bin/yt-dlp");
|
||||||
}
|
}
|
||||||
if ($this->isInstalled() && !$this->isExecutable()) {
|
if ($this->isInstalled() && !$this->isExecutable()) {
|
||||||
chmod($this->bin, 0744);
|
chmod($this->bin, 0744);
|
||||||
@@ -90,7 +89,7 @@ class Youtube
|
|||||||
$this->setOption('--audio-format', $format);
|
$this->setOption('--audio-format', $format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setvideoFormat($format)
|
public function setVideoFormat($format)
|
||||||
{
|
{
|
||||||
$this->videoFormat = $format;
|
$this->videoFormat = $format;
|
||||||
}
|
}
|
||||||
@@ -122,27 +121,6 @@ class Youtube
|
|||||||
array_unshift($this->options, $option);
|
array_unshift($this->options, $option);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function downloadSync($url)
|
|
||||||
{
|
|
||||||
$this->downloadDir = $this->downloadDir ?? $this->defaultDir;
|
|
||||||
$this->prependOption($this->downloadDir . $this->outTpl);
|
|
||||||
$this->prependOption("--output");
|
|
||||||
$this->setUrl($url);
|
|
||||||
$this->prependOption($this->bin);
|
|
||||||
// $this->buildCMD();
|
|
||||||
$process = new Process($this->options, null, $this->env);
|
|
||||||
//the maximum time required to download the file
|
|
||||||
$process->setTimeout($this->timeout);
|
|
||||||
try {
|
|
||||||
$process->mustRun();
|
|
||||||
$output = $process->getOutput();
|
|
||||||
} catch (ProcessFailedException $exception) {
|
|
||||||
$output = $exception->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function download($url)
|
public function download($url)
|
||||||
{
|
{
|
||||||
if ($this->audioOnly) {
|
if ($this->audioOnly) {
|
||||||
@@ -255,16 +233,22 @@ class Youtube
|
|||||||
{
|
{
|
||||||
return $this->bin;
|
return $this->bin;
|
||||||
}
|
}
|
||||||
public static function install()
|
public function install()
|
||||||
{
|
{
|
||||||
$url = $this->installUrl();
|
$url = $this->installUrl();
|
||||||
$path = \OC::$server->getSystemConfig()->getValue('datadirectory');
|
$file = __DIR__ . "/../../bin/yt-dlp2";
|
||||||
Helper::Download($url, $path . "/youtube-dl");
|
try {
|
||||||
|
Helper::Download($url, $file);
|
||||||
|
chmod($file, 0744);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function installUrl()
|
public function installUrl()
|
||||||
{
|
{
|
||||||
return "https://yt-dl.org/downloads/latest/youtube-dl";
|
return "https://github.com/shiningw/ncdownloader-bin/raw/master/yt-dlp";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export default {
|
|||||||
|
|
||||||
set(value) {
|
set(value) {
|
||||||
this.status = value;
|
this.status = value;
|
||||||
this.$emit("changed", value);
|
this.$emit("changed", this.name,value);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,11 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<section id="ncdownloader-settings-collapsible-container">
|
<section id="ncdownloader-settings-collapsible-container">
|
||||||
<div class="ncdownloader-settings-item" :data-tippy-content="tippy">
|
<div class="ncdownloader-settings-item" :data-tippy-content="errorTooltip">
|
||||||
<toggleButton
|
<toggleButton
|
||||||
:disabledText="toggleText"
|
:disabledText="errorText"
|
||||||
:enabledText="toggleText"
|
:enabledText="errorText"
|
||||||
:defaultStatus="toggleStatus"
|
:defaultStatus="toggleStatus"
|
||||||
@changed="toggle"
|
@changed="toggle"
|
||||||
|
name="ncd_hide_errors"
|
||||||
|
></toggleButton>
|
||||||
|
</div>
|
||||||
|
<div class="ncdownloader-settings-item" :data-tippy-content="btTooltip">
|
||||||
|
<toggleButton
|
||||||
|
v-if="isAdmin"
|
||||||
|
disabledText="Disable BT for non-admin users"
|
||||||
|
enabledText="Disable BT for non-admin users"
|
||||||
|
:defaultStatus="btStatus"
|
||||||
|
name="ncd_disable_bt"
|
||||||
|
@changed="toggle"
|
||||||
></toggleButton>
|
></toggleButton>
|
||||||
</div>
|
</div>
|
||||||
<div class="ncdownloader-settings-item">
|
<div class="ncdownloader-settings-item">
|
||||||
@@ -45,17 +56,20 @@ export default {
|
|||||||
admin: admin,
|
admin: admin,
|
||||||
isAdmin: this.settings.is_admin,
|
isAdmin: this.settings.is_admin,
|
||||||
sectionName: t("ncdownloader", "Settings"),
|
sectionName: t("ncdownloader", "Settings"),
|
||||||
toggleText: t("ncdownloader", "Hide Errors"),
|
errorText: t("ncdownloader", "Hide Errors"),
|
||||||
toggleStatus: helper.str2Boolean(this.settings.ncd_hide_errors),
|
toggleStatus: helper.str2Boolean(this.settings.ncd_hide_errors),
|
||||||
tippy: t("ncdownloader", "enable this to hide errors"),
|
btStatus: helper.str2Boolean(this.settings.ncd_disable_bt),
|
||||||
|
errorTooltip: t("ncdownloader", "Enable this to hide errors"),
|
||||||
|
btTooltip: t("ncdownload", "Disable BT for non-admin users"),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {},
|
created() {},
|
||||||
methods: {
|
methods: {
|
||||||
toggle(value) {
|
toggle(name, value) {
|
||||||
let data = {};
|
let data = {};
|
||||||
data["ncd_hide_errors"] = value ? 1 : 0;
|
data[name] = value ? 1 : 0;
|
||||||
const url = helper.generateUrl(basePath + "/personal/save");
|
let path = (name == "ncd_disable_bt") ? "/admin/save" : "/personal/save";
|
||||||
|
const url = helper.generateUrl(basePath + path);
|
||||||
Http.getInstance(url)
|
Http.getInstance(url)
|
||||||
.setData(data)
|
.setData(data)
|
||||||
.setHandler((resp) => {
|
.setHandler((resp) => {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ extract($_);
|
|||||||
<?php print($l->t('Download & Search'));?>
|
<?php print($l->t('Download & Search'));?>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<?php if ($is_admin): ?>
|
||||||
<div class="app-navigation-new" id="start-aria2">
|
<div class="app-navigation-new" id="start-aria2">
|
||||||
<?php if ($aria2_installed && $aria2_executable): ?>
|
<?php if ($aria2_installed && $aria2_executable): ?>
|
||||||
<button type="button" class="icon-power"
|
<button type="button" class="icon-power"
|
||||||
@@ -30,6 +31,7 @@ extract($_);
|
|||||||
</button>
|
</button>
|
||||||
<?php endif;?>
|
<?php endif;?>
|
||||||
</div>
|
</div>
|
||||||
|
<?php endif;?>
|
||||||
<ul>
|
<ul>
|
||||||
<li class="active-downloads">
|
<li class="active-downloads">
|
||||||
<div class="app-navigation-entry-bullet"></div>
|
<div class="app-navigation-entry-bullet"></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user