Skip to content

Commit

Permalink
Merge branch 'master' into add-referrer-useragent
Browse files Browse the repository at this point in the history
  • Loading branch information
e-alfred authored Sep 19, 2017
2 parents 45e418b + 31b40d0 commit f1962ea
Show file tree
Hide file tree
Showing 24 changed files with 3,001 additions and 2,996 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# ocDownloader
ocDownloader is an AGPL-licensed application for [Nextcloud](https://nextcloud.com) which allows you to download files from HTTP(S)/FTP(S)/Youtube/Bittorrent using the ARIA2 download manager/Curl and youtube-dl.

***I'm looking for maintainers and translators, every kind of support (especially pull requests) is highly welcome***

***If you are interested in translating, visit to [ocDownloader Transifex Project](https://www.transifex.com/projects/p/ocdownloader)***
***I'm looking for maintainers and translators, every kind of support (especially pull requests) is highly welcome***.

## Companion apps/extensions for Firefox/Chrome/Opera/Vivaldi and Windows

Webextension plugin for both Firefox-based and Chromium-based browsers: https://github.com/e-alfred/ocDownloader_ChromeExtension
Webextension addon for both Firefox-based and Chromium-based browsers: https://github.com/e-alfred/ocDownloader_ChromeExtension

Jetpack/PMKit addon for Firefox <=56 and Palemoon: https://github.com/e-alfred/ocdownloader_FFAddon

UWP Windows 8.1/10 app: https://github.com/e-alfred/ocDownloader_WindowsDesktop

Expand Down Expand Up @@ -46,7 +46,7 @@ If you have problems with Curl, the log files are saved to the /tmp folder on yo
- The download total size
- The current downloaded size
- The speed
- The PID of the PHP process which downloads your file (this allow to stop the download while it is in progress)
- The PID of the PHP process which downloads your file (this allows to pause/restart the download while it is in progress)

## Translators
- Polish : Andrzej Kaczmarczyk
Expand All @@ -64,6 +64,7 @@ If you have problems with Curl, the log files are saved to the /tmp folder on yo
## Authors
e-alfred
Nibbels
Loki3000
(formerly) Xavier Beurois

## Releases notes
Expand Down
183 changes: 85 additions & 98 deletions SERVER/fallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,108 +12,95 @@

class OCD
{
private static $CurlHandler = null;
private static $ProgressFile = null;
private static $CHInfo = null;
private static $PFHandle = null;
public static function Load ($GID, $URI, $OPTIONS)
private static $CurlHandler = null;
private static $ProgressFile = null;
private static $CHInfo = null;
private static $PFHandle = null;
public static function load($GID, $URI, $OPTIONS)
{
self::$ProgressFile = '/tmp/' . $GID . '.curl';
self::$PFHandle = fopen (self::$ProgressFile, 'w+');

self::$CurlHandler = curl_init ();

$DestFile = fopen (rtrim ($OPTIONS['dir'], '/') . '/' . $OPTIONS['out'], 'w+');
self::$ProgressFile = '/tmp/' . $GID . '.curl';
self::$PFHandle = fopen(self::$ProgressFile, 'w+');

curl_setopt_array (self::$CurlHandler, Array (
CURLOPT_FILE => $DestFile,
CURLOPT_URL => $URI
));
self::CurlSetBasicOptions ();
self::CurlSetAdvancedOptions ($OPTIONS);

curl_exec (self::$CurlHandler);
curl_close (self::$CurlHandler);
fclose ($DestFile);
self::$CurlHandler = curl_init();

$DestFile = fopen(rtrim($OPTIONS['dir'], '/') . '/' . $OPTIONS['out'], 'w+');

curl_setopt_array(self::$CurlHandler, array(
CURLOPT_FILE => $DestFile,
CURLOPT_URL => $URI
));
self::curlSetBasicOptions();
self::curlSetAdvancedOptions($OPTIONS);

curl_exec(self::$CurlHandler);
curl_close(self::$CurlHandler);
fclose($DestFile);
}

private static function writeProgress($DownloadStatus = 0)
{
if (self::$CHInfo['download_content_length'] != -1 && is_resource(self::$PFHandle)) {
$State = $DownloadStatus == 0 ? 'active' :($DownloadStatus == 1 ? 'complete' : 'error');
$Downloaded = $DownloadStatus == 2 ? 0 : self::$CHInfo['size_download'];
$Size = $DownloadStatus == 2 ? 0 : self::$CHInfo['download_content_length'];
$Speed = $DownloadStatus == 2 ? 0 : self::$CHInfo['speed_download'];

if (($PID = getmypid()) === false) {
$PID = 0;
}

fwrite(self::$PFHandle, $State . ';' . $Downloaded . ';' . $Size . ';' . $Speed . ';' . $PID . "\n");
}
}

private static function WriteProgress ($DownloadStatus = 0)
{
if (self::$CHInfo['download_content_length'] != -1 && is_resource (self::$PFHandle))
{
$State = $DownloadStatus == 0 ? 'active' : ($DownloadStatus == 1 ? 'complete' : 'error');
$Downloaded = $DownloadStatus == 2 ? 0 : self::$CHInfo['size_download'];
$Size = $DownloadStatus == 2 ? 0 : self::$CHInfo['download_content_length'];
$Speed = $DownloadStatus == 2 ? 0 : self::$CHInfo['speed_download'];

if (($PID = getmypid ()) === false)
{
$PID = 0;
}

fwrite (self::$PFHandle, $State . ';' . $Downloaded . ';' . $Size . ';' . $Speed . ';' . $PID . "\n");
}
}

private static function CurlSetBasicOptions ()
{
// Basic options
curl_setopt_array (self::$CurlHandler, Array (

private static function curlSetBasicOptions()
{
// Basic options
curl_setopt_array(self::$CurlHandler, array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 20,
CURLOPT_NOPROGRESS => false,
CURLOPT_PROGRESSFUNCTION => function ($Resource, $TotalDL, $Downloaded, $UpSize, $Uploaded)
{
self::$CHInfo = curl_getinfo (self::$CurlHandler);

if (self::$CHInfo['size_download'] == self::$CHInfo['download_content_length'] && self::$CHInfo['http_code'] == 200)
{
self::WriteProgress (1);
if (is_resource (self::$PFHandle))
{
fclose (self::$PFHandle);
}
}
else
{
self::WriteProgress ();
}
},
CURLOPT_MAXREDIRS => 20,
CURLOPT_NOPROGRESS => false,
CURLOPT_PROGRESSFUNCTION => function ($Resource, $TotalDL, $Downloaded, $UpSize, $Uploaded) {
self::$CHInfo = curl_getinfo(self::$CurlHandler);

if (self::$CHInfo['size_download'] == self::$CHInfo['download_content_length'] && self::$CHInfo['http_code'] == 200) {
self::writeProgress(1);
if (is_resource(self::$PFHandle)) {
fclose(self::$PFHandle);
}
} else {
self::writeProgress();
}
},
));
}

private static function CurlSetAdvancedOptions ($OPTIONS)
{
if (isset ($OPTIONS['http-user']) && isset ($OPTIONS['http-passwd']))
{
curl_setopt (self::$CurlHandler, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt (self::$CurlHandler, CURLOPT_USERPWD, $OPTIONS['http-user'] . ':' . $OPTIONS['http-passwd']);
}
if (isset ($OPTIONS['ftp-user']) && isset ($OPTIONS['ftp-passwd']))
{
curl_setopt (self::$CurlHandler, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt (self::$CurlHandler, CURLOPT_USERPWD, $OPTIONS['ftp-user'] . ':' . $OPTIONS['ftp-passwd']);
}
if (isset ($OPTIONS['ftp-pasv']))
{
curl_setopt (self::$CurlHandler, CURLOPT_FTP_USE_EPSV, $OPTIONS['ftp-pasv']);
}
if (isset ($OPTIONS['all-proxy']))
{
curl_setopt (self::$CurlHandler, CURLOPT_PROXY, $OPTIONS['all-proxy']);
if (isset ($OPTIONS['all-proxy-user']) && isset ($OPTIONS['all-proxy-passwd']))
{
curl_setopt (self::$CurlHandler, CURLOPT_PROXYUSERPWD, $OPTIONS['all-proxy-user'] . ':' . $OPTIONS['all-proxy-passwd']);
}
}
if (isset ($OPTIONS['max-download-limit']))
{
$OPTIONS['max-download-limit'] = (rtrim ($OPTIONS['max-download-limit'], 'K')) * 1024;
curl_setopt (self::$CurlHandler, CURLOPT_MAX_RECV_SPEED_LARGE, $OPTIONS['max-download-limit']);
}
}
}

private static function curlSetAdvancedOptions($OPTIONS)
{
if (isset($OPTIONS['http-user']) && isset($OPTIONS['http-passwd'])) {
curl_setopt(self::$CurlHandler, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt(self::$CurlHandler, CURLOPT_USERPWD, $OPTIONS['http-user'] . ':' . $OPTIONS['http-passwd']);
}
if (isset($OPTIONS['ftp-user']) && isset($OPTIONS['ftp-passwd'])) {
curl_setopt(self::$CurlHandler, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt(self::$CurlHandler, CURLOPT_USERPWD, $OPTIONS['ftp-user'] . ':' . $OPTIONS['ftp-passwd']);
}
if (isset($OPTIONS['ftp-pasv'])) {
curl_setopt(self::$CurlHandler, CURLOPT_FTP_USE_EPSV, $OPTIONS['ftp-pasv']);
}
if (isset($OPTIONS['all-proxy'])) {
curl_setopt(self::$CurlHandler, CURLOPT_PROXY, $OPTIONS['all-proxy']);
if (isset($OPTIONS['all-proxy-user']) && isset($OPTIONS['all-proxy-passwd'])) {
curl_setopt(self::$CurlHandler, CURLOPT_PROXYUSERPWD, $OPTIONS['all-proxy-user'] . ':' . $OPTIONS['all-proxy-passwd']);
}
}
if (isset($OPTIONS['max-download-limit'])) {
$OPTIONS['max-download-limit'] =(rtrim($OPTIONS['max-download-limit'], 'K')) * 1024;
curl_setopt(self::$CurlHandler, CURLOPT_MAX_RECV_SPEED_LARGE, $OPTIONS['max-download-limit']);
}
}
}

set_time_limit (0);
OCD::Load ($argv[1], urldecode ($argv[2]), json_decode (urldecode ($argv[3]), true, 512, JSON_HEX_APOS | JSON_HEX_QUOT));
set_time_limit(0);
OCD::load($argv[1], urldecode($argv[2]), json_decode(urldecode($argv[3]), true, 512, JSON_HEX_APOS | JSON_HEX_QUOT));
15 changes: 7 additions & 8 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@

namespace OCA\ocDownloader\AppInfo;

$l = \OC::$server->getL10N ('ocdownloader');
$g = \OC::$server->getURLGenerator ();
$l = \OC::$server->getL10N('ocdownloader');
$g = \OC::$server->getURLGenerator();

\OCP\App::addNavigationEntry
([
\OCP\App::addNavigationEntry([
'id' => 'ocdownloader',
'order' => 10,
'href' => $g->linkToRoute ('ocdownloader.Index.Add'),
'icon' => $g->imagePath ('ocdownloader', 'ocdownloader.svg'),
'href' => $g->linkToRoute('ocdownloader.Index.Add'),
'icon' => $g->imagePath('ocdownloader', 'ocdownloader.svg'),
'name' => 'ocDownloader'
]);

\OCP\App::registerAdmin ('ocdownloader', 'settings/admin');
\OCP\App::registerPersonal ('ocdownloader', 'settings/personal');
\OCP\App::registerAdmin('ocdownloader', 'settings/admin');
\OCP\App::registerPersonal('ocdownloader', 'settings/personal');
Loading

0 comments on commit f1962ea

Please sign in to comment.