moved settings button to bottom and made it collapsible;use nc's built-in filepicker to set download and torrents folders;fixed issues of youtube-dl filenames exceeding the maximum length

This commit is contained in:
huangjx
2022-02-16 21:15:37 +08:00
parent e458da86aa
commit 5c05ce5e8b
10 changed files with 70 additions and 19 deletions

View File

@@ -33,6 +33,7 @@ class MainController extends Controller
OC_Util::setupFS();
$this->aria2 = $aria2;
$this->aria2->init();
$this->urlGenerator = \OC::$server->getURLGenerator();
$this->dbconn = new DbHelper();
$this->counters = new Counters($aria2, $this->dbconn, $UserId);
}
@@ -51,7 +52,9 @@ class MainController extends Controller
$params['aria2_installed'] = $this->aria2->isInstalled();
$params['youtube_installed'] = (bool) Helper::findBinaryPath('youtube-dl');
$params['counter'] = $this->counters->getCounters();
$params['settings_url'] = $this->urlGenerator->linkToRoute("settings.PersonalSettings.index", ['section' => 'ncdownloader']);
$params['admin_settings_url'] = $this->urlGenerator->linkToRoute("settings.AdminSettings.index", ['section' => 'ncdownloader']);
$params['is_admin'] = \OC_User::isAdminUser($this->uid);
$response = new TemplateResponse($this->appName, 'Index', $params);
return $response;

View File

@@ -9,6 +9,7 @@ class Helper
{
public const DOWNLOADTYPE = ['ARIA2' => 1, 'YOUTUBE-DL' => 2, 'OTHERS' => 3];
public const STATUS = ['ACTIVE' => 1, 'PAUSED' => 2, 'COMPLETE' => 3, 'WAITING' => 4, 'ERROR' => 5];
const MAXLEN = 255;
public static function isUrl($URL)
{
@@ -41,7 +42,7 @@ class Helper
public static function isGetUrlSite($url)
{
$host = parse_url($url, PHP_URL_HOST);
$sites = ['twitter.com', 'www.twitter.com'];
//$sites = ['twitter.com', 'www.twitter.com'];
return (bool) (in_array($host, $sites));
}
public static function parseUrl($url)
@@ -66,10 +67,11 @@ class Helper
public static function getFilename($url)
{
if (self::isMagnet($url)) {
return self::parseUrl($url)['dn'];
$filename = self::parseUrl($url)['dn'];
} else {
return self::getUrlPath($url);
$filename = self::getUrlPath($url);
}
return substr($filename, 0, self::MAXLEN);
}
public static function formatBytes($size, $precision = 2)
{

View File

@@ -15,7 +15,7 @@ class Youtube
private $options = [];
private $downloadDir;
private $timeout = 60 * 60 * 10; //10 hours
private $outTpl = "%(id)s-%(title)s.%(ext)s";
private $outTpl = "%(id)s-%(title).64s.%(ext)s";
private $defaultDir = "/tmp/downloads";
private $env = [];
@@ -66,7 +66,7 @@ class Youtube
if (Helper::ffmpegInstalled()) {
$this->addOption('--prefer-ffmpeg');
$this->addOption('--add-metadata');
$this->setOption('--metadata-from-title', "%(artist)s-%(title)s");
$this->setOption('--metadata-from-title', "%(artist)s-%(title).64s");
$this->addOption('--extract-audio');
}
$pos = strrpos($this->outTpl, '.');