Skip to content

Commit

Permalink
Merge pull request #1 from e-alfred/master
Browse files Browse the repository at this point in the history
pulling e-alfreds changes
  • Loading branch information
Nibbels authored Aug 28, 2017
2 parents bc236bb + 8d9d6c9 commit 8bfe35c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 38 deletions.
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,35 @@ Webextension plugin for both Firefox-based and Chromium-based browsers: https://
UWP Windows 8.1/10 app: https://github.com/e-alfred/ocDownloader_WindowsDesktop

## ARIA2 installation
Please visit : [OCDownloader: Requirements for Debian-based systems](https://web.archive.org/web/20160912231334/https://wiki.sgc-univ.net/index.php/OCDownloader:Requirements_(Linux_Debian_-_JESSIE))
Everything you need to install ARIA2 and to run aria2c as a daemon !
To install Aria2 on Debian/Ubuntu use the following command:

## Other articles
To download Youtube videos, you have to install youtube-dl. For Ubuntu, you can use this repository: [Webupd8 PPA](https://launchpad.net/~nilarimogard/+archive/ubuntu/webupd8)
`apt-get install aria2 curl php-curl`

After that, you have to run Aria2 on every boot with the same user that your webserver is running:

`sudo -u www-data aria2c --enable-rpc --rpc-allow-origin-all -c -D --log=/var/log/aria2.log --check-certificate=false --save-session=/var/www/aria2c.sess --save-session-interval=2 --continue=true --input-file=/var/www/aria2c.sess --rpc-save-upload-metadata=true --force-save=true`

You have to enable the RPC interface and save the session file of Aria2, otherwise your old downloads won't be listed after you restart Aria2. The file in the example is stored in /var/www/aria2c.sess, but you can put it anywhere as long as the user running your webserver can access/write to it.

You can find the documentation of Aria2 [here](https://aria2.github.io/manual/en/html/index.html)

## Youtube-dl installation
To download Youtube videos, you have to install youtube-dl. For Ubuntu, you can use this repository and follow the instructions there: [Webupd8 PPA](https://launchpad.net/~nilarimogard/+archive/ubuntu/webupd8)

For other distributions, you can [install youtube-dl manually](https://rg3.github.io/youtube-dl/download.html) *Note : You have to install Python on your server. This a requierement for youtube-dl.*

Aria2 fallback : [OCDownloader: Aria2 fallback using CURL directly (Requirements)](https://web.archive.org/web/20160912225929/https://wiki.sgc-univ.net/index.php/OCDownloader:Aria2_fallback_using_CURL_directly_(Requirements))
After installing youtube-dl, you have to set the right path to your youtube-dl executeable in the admin settings of ocDownloader.

## Using Curl instead of Aria2
If you don't have aria2 available on your server, you can use curl which is directly integrated into PHP. This allows you to make HTTP(S) and FTP(S) downloads (BitTorrent is not supported by Curl) To run this, you have to install the corresponding PHP curl module. Afterwards, you have to make sure that fallback.sh and fallback.php in the /SERVER directory are executeable by your webserver user (chmod 740 should be sufficient).

Log files are saved to the /tmp folder on your server with these semicolon-seperated values:

## CURL installation hint
The File SERVER/fallback.sh still needs chmod 740. This is no perfect solution but seems to work.
- The status
- 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)

## Translators
- Polish : Andrzej Kaczmarczyk
Expand Down
1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<licence>AGPL</licence>
<author>Xavier Beurois</author>
<author>e-alfred</author>
<author>Nibbels</author>
<website>https://github.com/e-alfred/ocdownloader</website>
<bugs>https://github.com/e-alfred/ocdownloader/issues</bugs>
<repository type="git">https://github.com/e-alfred/ocdownloader.git</repository>
Expand Down
62 changes: 31 additions & 31 deletions controller/ytdownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ class YTDownloader extends Controller
private $L10N = null;
private $AllowProtocolYT = null;
private $MaxDownloadSpeed = null;

public function __construct ($AppName, IRequest $Request, $CurrentUID, IL10N $L10N)
{
parent::__construct ($AppName, $Request);

if (strcmp (Config::getSystemValue ('dbtype'), 'pgsql') == 0)
{
$this->DbType = 1;
}

$this->CurrentUID = $CurrentUID;

$Settings = new Settings ();
$Settings->SetKey ('YTDLBinary');
$YTDLBinary = $Settings->GetValue ();

$this->YTDLBinary = '/usr/local/bin/youtube-dl'; // default path
if (!is_null ($YTDLBinary))
{
$this->YTDLBinary = $YTDLBinary;
}

$Settings->SetKey ('ProxyAddress');
$this->ProxyAddress = $Settings->GetValue ();
$Settings->SetKey ('ProxyPort');
Expand All @@ -77,26 +77,26 @@ public function __construct ($AppName, IRequest $Request, $CurrentUID, IL10N $L1
$Settings->SetKey ('AllowProtocolYT');
$this->AllowProtocolYT = $Settings->GetValue ();
$this->AllowProtocolYT = is_null ($this->AllowProtocolYT) ? true : strcmp ($this->AllowProtocolYT, 'Y') == 0;

$Settings->SetTable ('personal');
$Settings->SetUID ($this->CurrentUID);
$Settings->SetKey ('DownloadsFolder');
$this->DownloadsFolder = $Settings->GetValue ();

$this->DownloadsFolder = '/' . (is_null ($this->DownloadsFolder) ? 'Downloads' : $this->DownloadsFolder);
$this->AbsoluteDownloadsFolder = \OC\Files\Filesystem::getLocalFolder ($this->DownloadsFolder);

$this->L10N = $L10N;
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function Add ()
{
\OCP\JSON::setContentTypeHeader ('application/json');

if (isset ($_POST['FILE']) && strlen ($_POST['FILE']) > 0 && Tools::CheckURL ($_POST['FILE']) && isset ($_POST['OPTIONS']))
{
try
Expand All @@ -105,27 +105,27 @@ public function Add ()
{
throw new \Exception ((string)$this->L10N->t ('You are not allowed to use the YouTube protocol'));
}

$YouTube = new YouTube ($this->YTDLBinary, $_POST['FILE']);

if (!is_null ($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536)
{
$YouTube->SetProxy ($this->ProxyAddress, $this->ProxyPort);
}

if (isset ($_POST['OPTIONS']['YTForceIPv4']) && strcmp ($_POST['OPTIONS']['YTForceIPv4'], 'false') == 0)
{
$YouTube->SetForceIPv4 (false);
}

// Extract Audio YES
if (isset ($_POST['OPTIONS']['YTExtractAudio']) && strcmp ($_POST['OPTIONS']['YTExtractAudio'], 'true') == 0)
{
$VideoData = $YouTube->GetVideoData (true);
if (!isset ($VideoData['AUDIO']) || !isset ($VideoData['FULLNAME']))
{
return new JSONResponse (Array (
'ERROR' => true,
'ERROR' => true,
'MESSAGE' => (string)$this->L10N->t ('Unable to retrieve true YouTube audio URL')
));
}
Expand All @@ -137,19 +137,19 @@ public function Add ()
if (!isset ($VideoData['VIDEO']) || !isset ($VideoData['FULLNAME']))
{
return new JSONResponse (Array (
'ERROR' => true,
'ERROR' => true,
'MESSAGE' => (string)$this->L10N->t ('Unable to retrieve true YouTube video URL')
));
}
$DL = Array ('URL' => $VideoData['VIDEO'], 'FILENAME' => Tools::CleanString ($VideoData['FULLNAME']), 'TYPE' => 'YT Video');
}

// If target file exists, create a new one
if (\OC\Files\Filesystem::file_exists ($this->DownloadsFolder . '/' . $DL['FILENAME']))
{
$DL['FILENAME'] = time () . '_' . $DL['FILENAME'];
}

// Create the target file if the downloader is ARIA2
if ($this->WhichDownloader == 0)
{
Expand All @@ -162,7 +162,7 @@ public function Add ()
\OC\Files\Filesystem::mkdir ($this->DownloadsFolder);
}
}

$OPTIONS = Array ('dir' => $this->AbsoluteDownloadsFolder, 'out' => $DL['FILENAME']);
if (!is_null ($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536)
{
Expand All @@ -177,17 +177,17 @@ public function Add ()
{
$OPTIONS['max-download-limit'] = $this->MaxDownloadSpeed . 'K';
}

$AddURI = ($this->WhichDownloader == 0 ? Aria2::AddUri (Array ($DL['URL']), Array ('Params' => $OPTIONS)) : CURL::AddUri ($DL['URL'], $OPTIONS));

if (isset ($AddURI['result']) && !is_null ($AddURI['result']))
{
$SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)';
if ($this->DbType == 1)
{
$SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)';
}

$Query = \OCP\DB::prepare ($SQL);
$Result = $Query->execute (Array (
$this->CurrentUID,
Expand All @@ -197,21 +197,21 @@ public function Add ()
1,
time()
));

sleep (1);
$Status = Aria2::TellStatus ($AddURI['result']);

$Progress = 0;
if ($Status['result']['totalLength'] > 0)
{
$Progress = $Status['result']['completedLength'] / $Status['result']['totalLength'];
}

$ProgressString = Tools::GetProgressString ($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress);

return new JSONResponse (Array (
'ERROR' => false,
'MESSAGE' => (string)$this->L10N->t ('Download started'),
'ERROR' => false,
'MESSAGE' => (string)$this->L10N->t ('Download started'),
'GID' => $AddURI['result'],
'PROGRESSVAL' => round((($Progress) * 100), 2) . '%',
'PROGRESS' => is_null ($ProgressString) ? (string)$this->L10N->t ('N/A') : $ProgressString,
Expand All @@ -226,7 +226,7 @@ public function Add ()
else
{
return new JSONResponse (Array (
'ERROR' => true,
'ERROR' => true,
'MESSAGE' => (string)$this->L10N->t ('Returned GID is null ! Is Aria2c running as a daemon ?')
));
}
Expand All @@ -241,4 +241,4 @@ public function Add ()
return new JSONResponse (Array ('ERROR' => true, 'MESSAGE' => (string)$this->L10N->t ('Please check the URL you\'ve just provided')));
}
}
}
}

0 comments on commit 8bfe35c

Please sign in to comment.