tidying up
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
namespace OCA\NCDownloader\Controller;
|
||||
|
||||
use OCA\NCDownloader\Tools\Aria2;
|
||||
use OCA\NCDownloader\Aria2\Aria2;
|
||||
use OCA\NCDownloader\Tools\Counters;
|
||||
use OCA\NCDownloader\Tools\DbHelper;
|
||||
use OCA\NCDownloader\Db\Helper as DbHelper;
|
||||
use OCA\NCDownloader\Tools\folderScan;
|
||||
use OCA\NCDownloader\Tools\Helper;
|
||||
use OCP\AppFramework\Controller;
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace OCA\NCDownloader\Controller;
|
||||
|
||||
use OCA\NCDownloader\Tools\Aria2;
|
||||
use OCA\NCDownloader\Aria2\Aria2;
|
||||
use OCA\NCDownloader\Tools\Counters;
|
||||
use OCA\NCDownloader\Tools\DbHelper;
|
||||
use OCA\NCDownloader\Db\Helper as DbHelper;
|
||||
use OCA\NCDownloader\Tools\folderScan;
|
||||
use OCA\NCDownloader\Tools\Helper;
|
||||
use OCA\NCDownloader\Tools\Settings;
|
||||
use OCA\NCDownloader\Tools\Youtube;
|
||||
use OCA\NCDownloader\Db\Settings;
|
||||
use OCA\NCDownloader\Ytdl\Ytdl;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
@@ -26,7 +26,7 @@ class MainController extends Controller
|
||||
private $aria2Opts;
|
||||
private $l10n;
|
||||
|
||||
public function __construct($appName, IRequest $request, $UserId, IL10N $IL10N, Aria2 $aria2, Youtube $youtube)
|
||||
public function __construct($appName, IRequest $request, $UserId, IL10N $IL10N, Aria2 $aria2, Ytdl $ytdl)
|
||||
{
|
||||
|
||||
parent::__construct($appName, $request);
|
||||
@@ -39,7 +39,7 @@ class MainController extends Controller
|
||||
$this->urlGenerator = \OC::$server->getURLGenerator();
|
||||
$this->dbconn = new DbHelper();
|
||||
$this->counters = new Counters($aria2, $this->dbconn, $UserId);
|
||||
$this->youtube = $youtube;
|
||||
$this->ytdl = $ytdl;
|
||||
$this->isAdmin = \OC_User::isAdminUser($this->uid);
|
||||
$this->hideError = Helper::getSettings("ncd_hide_errors", false);
|
||||
$this->disable_bt_nonadmin = Helper::getSettings("ncd_disable_bt", false, Settings::TYPE["SYSTEM"]);
|
||||
@@ -67,9 +67,9 @@ class MainController extends Controller
|
||||
$params['aria2_installed'] = $aria2_installed = $this->aria2->isInstalled();
|
||||
$params['aria2_bin'] = $aria2_bin = $this->aria2->getBin();
|
||||
$params['aria2_executable'] = $aria2_executable = $this->aria2->isExecutable();
|
||||
$params['youtube_installed'] = $youtube_installed = $this->youtube->isInstalled();
|
||||
$params['youtube_bin'] = $youtube_bin = $this->youtube->getBin();
|
||||
$params['youtube_executable'] = $youtube_executable = $this->youtube->isExecutable();
|
||||
$params['ytdlinstalled'] = $ytdlinstalled = $this->ytdl->isInstalled();
|
||||
$params['ytdlbin'] = $ytdlbin = $this->ytdl->getBin();
|
||||
$params['ytdlexecutable'] = $ytdlexecutable = $this->ytdl->isExecutable();
|
||||
$params['ncd_hide_errors'] = $this->hideError;
|
||||
$params['counter'] = $this->counters->getCounters();
|
||||
$params['python_installed'] = Helper::pythonInstalled();
|
||||
@@ -92,8 +92,8 @@ class MainController extends Controller
|
||||
$this->aria2->start();
|
||||
}
|
||||
}
|
||||
if ($youtube_installed && (!$youtube_executable || !@is_readable($youtube_bin))) {
|
||||
array_push($errors, sprintf("youtube-dl is installed but don't have the right permissions.Please execute command sudo chmod 755 %s", $youtube_bin));
|
||||
if ($ytdlinstalled && (!$ytdlexecutable || !@is_readable($ytdlbin))) {
|
||||
array_push($errors, sprintf("ytdl is installed but don't have the right permissions.Please execute command sudo chmod 755 %s", $ytdlbin));
|
||||
}
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace OCA\NCDownloader\Controller;
|
||||
|
||||
use OCA\NCDownloader\Tools\Helper;
|
||||
use OCA\NCDownloader\Tools\Settings;
|
||||
use OCA\NCDownloader\Db\Settings;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
@@ -101,33 +101,33 @@ class SettingsController extends Controller
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function youtubeGet()
|
||||
public function ytdlGet()
|
||||
{
|
||||
$data = json_decode($this->settings->get("custom_youtube_dl_settings"));
|
||||
$data = json_decode($this->settings->get("custom_ytdl_settings"));
|
||||
return new JSONResponse($data);
|
||||
}
|
||||
|
||||
public function youtubeSave()
|
||||
public function ytdlSave()
|
||||
{
|
||||
$params = $this->request->getParams();
|
||||
$data = array_filter($params, function ($key) {
|
||||
return (bool) (!in_array(substr($key, 0, 1), ['_']));
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
$resp = $this->settings->save("custom_youtube_dl_settings", json_encode($data));
|
||||
$resp = $this->settings->save("custom_ytdl_settings", json_encode($data));
|
||||
return new JSONResponse($resp);
|
||||
}
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function youtubeDelete()
|
||||
public function ytdlDelete()
|
||||
{
|
||||
$saved = json_decode($this->settings->get("custom_youtube_dl_settings"), 1);
|
||||
$saved = json_decode($this->settings->get("custom_ytdl_settings"), 1);
|
||||
$params = $this->request->getParams();
|
||||
foreach ($params as $key => $value) {
|
||||
unset($saved[$key]);
|
||||
}
|
||||
$resp = $this->settings->save("custom_youtube_dl_settings", json_encode($saved));
|
||||
$resp = $this->settings->save("custom_ytdl_settings", json_encode($saved));
|
||||
return new JSONResponse($resp);
|
||||
}
|
||||
public function save($key, $value)
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
<?php
|
||||
namespace OCA\NCDownloader\Controller;
|
||||
|
||||
use OCA\NCDownloader\Tools\Aria2;
|
||||
use OCA\NCDownloader\Tools\DbHelper;
|
||||
use OCA\NCDownloader\Aria2\Aria2;
|
||||
use OCA\NCDownloader\Db\Helper as DbHelper;
|
||||
use OCA\NCDownloader\Tools\folderScan;
|
||||
use OCA\NCDownloader\Tools\Helper;
|
||||
use OCA\NCDownloader\Tools\Youtube;
|
||||
use OCA\NCDownloader\Ytdl\Ytdl;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
|
||||
class YoutubeController extends Controller
|
||||
class YtdlController extends Controller
|
||||
{
|
||||
//@config OC\AppConfig
|
||||
private $l10n;
|
||||
private $audio_extensions = array("mp3", "m4a", "vorbis");
|
||||
|
||||
public function __construct($appName, IRequest $request, $UserId, IL10N $IL10N, Aria2 $aria2, Youtube $youtube)
|
||||
public function __construct($appName, IRequest $request, $UserId, IL10N $IL10N, Aria2 $aria2, Ytdl $ytdl)
|
||||
{
|
||||
parent::__construct($appName, $request);
|
||||
$this->appName = $appName;
|
||||
@@ -26,7 +26,7 @@ class YoutubeController extends Controller
|
||||
$this->l10n = $IL10N;
|
||||
$this->downloadDir = Helper::getDownloadDir();
|
||||
$this->dbconn = new DbHelper();
|
||||
$this->youtube = $youtube;
|
||||
$this->ytdl = $ytdl;
|
||||
$this->aria2 = $aria2;
|
||||
$this->aria2->init();
|
||||
$this->tablename = $this->dbconn->queryBuilder->getTableName("ncdownloader_info");
|
||||
@@ -37,7 +37,7 @@ class YoutubeController extends Controller
|
||||
*/
|
||||
public function Index()
|
||||
{
|
||||
$data = $this->dbconn->getYoutubeByUid($this->uid);
|
||||
$data = $this->dbconn->getYtdlByUid($this->uid);
|
||||
if (is_array($data) && count($data) < 1) {
|
||||
return [];
|
||||
}
|
||||
@@ -54,9 +54,9 @@ class YoutubeController extends Controller
|
||||
$tmp['speed'] = explode("|", $value['speed']);
|
||||
$tmp['progress'] = $value['progress'];
|
||||
|
||||
$path = $this->urlGenerator->linkToRoute('ncdownloader.Youtube.Delete');
|
||||
$path = $this->urlGenerator->linkToRoute('ncdownloader.Ytdl.Delete');
|
||||
$tmp['actions'][] = ['name' => 'delete', 'path' => $path];
|
||||
$path = $this->urlGenerator->linkToRoute('ncdownloader.Youtube.Redownload');
|
||||
$path = $this->urlGenerator->linkToRoute('ncdownloader.Ytdl.Redownload');
|
||||
$tmp['actions'][] = ['name' => 'refresh', 'path' => $path];
|
||||
|
||||
$tmp['data_gid'] = $value['gid'] ?? 0;
|
||||
@@ -64,7 +64,7 @@ class YoutubeController extends Controller
|
||||
}
|
||||
|
||||
$resp['title'] = ['filename', 'speed', 'progress', 'actions'];
|
||||
$resp['counter'] = ['youtube-dl' => count($data)];
|
||||
$resp['counter'] = ['ytdl' => count($data)];
|
||||
folderScan::sync();
|
||||
return new JSONResponse($resp);
|
||||
}
|
||||
@@ -74,12 +74,12 @@ class YoutubeController extends Controller
|
||||
*/
|
||||
public function Download()
|
||||
{
|
||||
$dlDir = $this->youtube->getDownloadDir();
|
||||
$dlDir = $this->ytdl->getDownloadDir();
|
||||
if (!is_writable($dlDir)) {
|
||||
return new JSONResponse(['error' => sprintf("%s is not writable", $dlDir)]);
|
||||
}
|
||||
$url = trim($this->request->getParam('text-input-value'));
|
||||
$yt = $this->youtube;
|
||||
$yt = $this->ytdl;
|
||||
if (in_array($this->request->getParam('extension'), $this->audio_extensions)) {
|
||||
$yt->audioOnly = true;
|
||||
$yt->audioFormat = $this->request->getParam('extension');
|
||||
@@ -87,7 +87,7 @@ class YoutubeController extends Controller
|
||||
$yt->videoFormat = $this->request->getParam('extension');
|
||||
}
|
||||
if (!$yt->isInstalled()) {
|
||||
return new JSONResponse(["error" => "Please install the latest youtube-dl or make the bundled binary file executable in ncdownloader/bin"]);
|
||||
return new JSONResponse(["error" => "Please install the latest yt-dlp or make the bundled binary file executable in ncdownloader/bin"]);
|
||||
}
|
||||
if (Helper::isGetUrlSite($url)) {
|
||||
return new JSONResponse($this->downloadUrlSite($url));
|
||||
@@ -99,7 +99,7 @@ class YoutubeController extends Controller
|
||||
}
|
||||
private function downloadUrlSite($url)
|
||||
{
|
||||
$yt = $this->youtube;
|
||||
$yt = $this->ytdl;
|
||||
if ($data = $yt->forceIPV4()->getDownloadUrl($url)) {
|
||||
return $this->_download($data['url'], $data['filename']);
|
||||
} else {
|
||||
@@ -157,16 +157,16 @@ class YoutubeController extends Controller
|
||||
if (!empty($data['link'])) {
|
||||
if (isset($data['ext'])) {
|
||||
if (in_array($data['ext'], $this->audio_extensions)) {
|
||||
$this->youtube->audioOnly = true;
|
||||
$this->youtube->audioFormat = $data['ext'];
|
||||
$this->ytdl->audioOnly = true;
|
||||
$this->ytdl->audioFormat = $data['ext'];
|
||||
} else {
|
||||
$this->youtube->audioOnly = false;
|
||||
$this->youtube->videoFormat = $data['ext'];
|
||||
$this->ytdl->audioOnly = false;
|
||||
$this->ytdl->videoFormat = $data['ext'];
|
||||
}
|
||||
}
|
||||
//$this->dbconn->deleteByGid($gid);
|
||||
$this->youtube->dbDlPath = Helper::getDownloadDir();
|
||||
$resp = $this->youtube->forceIPV4()->download($data['link']);
|
||||
$this->ytdl->dbDlPath = Helper::getDownloadDir();
|
||||
$resp = $this->ytdl->forceIPV4()->download($data['link']);
|
||||
folderScan::sync();
|
||||
return new JSONResponse($resp);
|
||||
}
|
||||
Reference in New Issue
Block a user