Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Rewrite config #272

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- new `YoutubeDownloader\Config\TransformationConfig` for a BC friendly configuraion

### Changed

- Moved configuration `$config['ThumbnailImageMode']` to `$config['gui']['ThumbnailImageMode']`
- Moved configuration `$config['VideoLinkMode']` to `$config['gui']['VideoLinkMode']`
- Moved configuration `$config['showBrowserExtensions']` to `$config['gui']['showBrowserExtensions']`

### Deprecated

- `YoutubeDownloader\Config` will be removed in 0.8, use `YoutubeDownloader\Config\TransformationConfig` instead

### Removed

- **Breaking:** `YoutubeDownloader\Provider\Youtube\Provider::createFromConfigAndToolkit()` was removed, use `YoutubeDownloader\Provider\Youtube\Provider::createFromOptions()` instead
Expand Down
286 changes: 137 additions & 149 deletions config/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,160 +6,148 @@
* Instead copy this file to `config/custom.php` and make your changes there!
*/

return [
/*
* Debug mode
* WARNING: This outputs debug information while processing.
* This could leak sensitive server data to the browser.
* Enable only if needed.
*
* true => debug mode on
* false => debug mode off
*/
'debug' => false,
/**
* Debug mode
* WARNING: This outputs debug information while processing.
* This could leak sensitive server data to the browser.
* Enable only if needed.
*
* true => debug mode on
* false => debug mode off
*/
$config['debug'] = false;

/*
* Enable the YouTube signature decipher function
* WARNING: This downloads javascript code from a 3rd party server and interprets it!
* This MAY harm your server, if the 3rd party server delivers malicious code!
*
* false => decipher is disabled
* true => decipher is enabled
*/
'enable_youtube_decipher_signature' => false,
/*
* Enable the YouTube signature decipher function
* WARNING: This downloads javascript code from a 3rd party server and interprets it!
* This MAY harm your server, if the 3rd party server delivers malicious code!
*
* false => decipher is disabled
* true => decipher is enabled
*/
$config['enable_youtube_decipher_signature'] = false;

/*
* Thumbnail Image Configuration
*
* 0 => don't show thumbnail image
* 1 => show thumbnail image directly from YouTube
* 2 => show thumbnail image by proxy from this server
*/
'ThumbnailImageMode' => 2,
/*
* Thumbnail Image Configuration
*
* 'none' => don't show thumbnail image
* 'direct' => show thumbnail image directly from YouTube
* 'proxy' => show thumbnail image by proxy from this server
*/
$config['gui']['ThumbnailImageMode'] = 'proxy';

/*
* Video Download Link Configuration
* 'direct' => show only direct download link
* 'proxy' => show only by proxy download link
* 'both' => show both direct and by proxy download links
*/
'VideoLinkMode' => 'both',

/*
* Caching mode. If normal proxy mode won't work, this makes a copy of the file on the
* webserver and downloads it from there
* false => proxying works by 'streaming' the file through the server
* true => proxying generates a temporary copy of the file on the server
*/
'localCache' => false,
/*
* Video Download Link Configuration
* 'direct' => show only direct download link
* 'proxy' => show only by proxy download link
* 'both' => show both direct and by proxy download links
*/
$config['gui']['VideoLinkMode'] = 'both';

/*
* MP3 Download Link Configuration
*
* Basic method for converting Youtube Video or Audio to .mp3
* require server processing for running ffmpeg and aria2, also you may need to edit php "max_execution_time"
*
* FFMPEG for converting video or audio to .mp3
* Install: https://ffmpeg.org/download.html
*
* ARIA2 command line downloader with multi connection, using single connection (ffmpeg or curl) server download from youtube limited to 56KBps
* install: https://github.com/aria2/aria2/releases
*
*/
'MP3Enable' => false, // enable or disable media conversion and download to mp3
'MP3ConvertVideo' => false, // 'false' download adaptive audio only to save bandwidth.
// 'true' failover to video download if adaptive audio format not available
'MP3Quality' => '128k', // 'number(k)' (64k, 80k, 96k, 112k, 128k, 160k, 192k) or 'high': bitrate quality of converted mp3
// set to 'high' to get and set highest quality
// info: highest Youtube audio bitrate is 160k, higher than that is maybe useless
'MP3TempDir' => realpath(__DIR__ . '/../cache/'), // temporary download location for media
'ffmpegPath' => 'C:\Program Files (x86)\ffmpeg\ffmpeg.exe', // ffmpeg location path
'aria2Path' => 'C:\cygwin\bin\aria2c.exe', // aria2 location path, @deprecated since 0.6, to be removed in 0.7
/*
* show links for install browser extensions?
*
* true or false
*/
$config['gui']['showBrowserExtensions'] = true;

/*
* show links for install browser extensions?
*
* true or false
*/
'showBrowserExtensions' => true,
/*
* MP3 Download Link Configuration
*
* Basic method for converting Youtube Video or Audio to .mp3
* require server processing for running ffmpeg and aria2, also you may need to edit php "max_execution_time"
*
* FFMPEG for converting video or audio to .mp3
* Install: https://ffmpeg.org/download.html
*
* ARIA2 command line downloader with multi connection, using single connection (ffmpeg or curl) server download from youtube limited to 56KBps
* install: https://github.com/aria2/aria2/releases
*/
$config['MP3Enable'] = false; // enable or disable media conversion and download to mp3
$config['MP3ConvertVideo'] = false; // 'false' download adaptive audio only to save bandwidth.
// 'true' failover to video download if adaptive audio format not available
$config['MP3Quality'] = '128k'; // 'number(k)' (64k, 80k, 96k, 112k, 128k, 160k, 192k) or 'high': bitrate quality of converted mp3
// set to 'high' to get and set highest quality
// info: highest Youtube audio bitrate is 160k, higher than that is maybe useless
$config['MP3TempDir'] = realpath(__DIR__ . '/../cache/'); // temporary download location for media
$config['ffmpegPath'] = 'C:\Program Files (x86)\ffmpeg\ffmpeg.exe'; // ffmpeg location path
$config['aria2Path'] = 'C:\cygwin\bin\aria2c.exe'; // aria2 location path, @deprecated since 0.6, to be removed in 0.7

/*
* Multiple IPs
*
* You can enable this option if you are having problems with youtube IP limit / IP ban.
* This option will work only if the IP you add are available for the server.
* That means you have to buy some additionnal public IPs and assign these new static IPs to the server.
* This should work only if you have a dedicated server...
*
*
* Example of adding additional IPs to Ubuntu server 14.04 LTS
* !!!! Be very careful, you may block yourself !!!!
* !!!! If you are connecting to your server remotly by ssh. You would do this only if you know what you do !!!!
* !!!! This is only an example with a specific dedicated server (ovh.net) !!!!
*
* For this example, the main IP on the server is 123.456.789.001
* We want to add additionnal IPs 789.456.123.001 and 789.456.123.002
*
* Edit /etc/network/interfaces and put something like this:
*
* # The loopback network interface
* auto lo
* iface lo inet loopback
*
* # The Main server IP:
* auto eth0
* iface eth0 inet static
* address 123.456.789.001
* netmask 255.255.255.0
* network 123.456.789.0
* broadcast 123.456.789.255
* gateway 123.456.789.254
*
* # Additionnal IP: 789.456.123.001
* auto eth0:0
* iface eth0:0 inet static
* address 789.456.123.001
* netmask 255.255.255.255
* broadcast 789.456.123.001
* gateway 123.456.789.254
*
* # Additionnal IP: 789.456.123.002
* auto eth0:1
* iface eth0:0 inet static
* address 789.456.123.002
* netmask 255.255.255.255
* broadcast 789.456.123.002
* gateway 123.456.789.254
*
* # Additionnal IP xxx.xxx.xxx.xxx
* auto eth0:2
* iface eth0:2 inet static
* (...)
*
* and so on for each IP you want to add....
*
*
* Reboot your server
* If you are having trouble and cannot connect anymore over ssh to your server,
* that means your new network configuration has errors...
* So be very careful before applying your configuration.
* Try it first on a local dev server before messing up with your pro server.
*
*
*/
'multipleIPs' => false, // enable multiple IPs support to bypass Youtube IP limit? true or false
'IPs' => [
//'xxx.xxx.xxx.xxx',
//'xxx.xxx.xxx.xxx',
// add as many ips as you want (they must be available in the server conf (ex: /etc/network/interfaces fro ubuntu/debian)
],
/*
* Multiple IPs
*
* You can enable this option if you are having problems with youtube IP limit / IP ban.
* This option will work only if the IP you add are available for the server.
* That means you have to buy some additionnal public IPs and assign these new static IPs to the server.
* This should work only if you have a dedicated server...
*
* Example of adding additional IPs to Ubuntu server 14.04 LTS
* !!!! Be very careful, you may block yourself !!!!
* !!!! If you are connecting to your server remotly by ssh. You would do this only if you know what you do !!!!
* !!!! This is only an example with a specific dedicated server (ovh.net) !!!!
*
* For this example, the main IP on the server is 123.456.789.001
* We want to add additionnal IPs 789.456.123.001 and 789.456.123.002
*
* Edit /etc/network/interfaces and put something like this:
*
* # The loopback network interface
* auto lo
* iface lo inet loopback
*
* # The Main server IP:
* auto eth0
* iface eth0 inet static
* address 123.456.789.001
* netmask 255.255.255.0
* network 123.456.789.0
* broadcast 123.456.789.255
* gateway 123.456.789.254
*
* # Additionnal IP: 789.456.123.001
* auto eth0:0
* iface eth0:0 inet static
* address 789.456.123.001
* netmask 255.255.255.255
* broadcast 789.456.123.001
* gateway 123.456.789.254
*
* # Additionnal IP: 789.456.123.002
* auto eth0:1
* iface eth0:0 inet static
* address 789.456.123.002
* netmask 255.255.255.255
* broadcast 789.456.123.002
* gateway 123.456.789.254
*
* # Additionnal IP xxx.xxx.xxx.xxx
* auto eth0:2
* iface eth0:2 inet static
* (...)
*
* and so on for each IP you want to add....
*
* Reboot your server
* If you are having trouble and cannot connect anymore over ssh to your server,
* that means your new network configuration has errors...
* So be very careful before applying your configuration.
* Try it first on a local dev server before messing up with your pro server.
*/
$config['multipleIPs'] = false; // enable multiple IPs support to bypass Youtube IP limit? true or false

/*
* Set your default timezone
*
* e.g. Asia/Tehran or America/New_York
*
* more examples: http://php.net/manual/en/timezones.php
*/
'default_timezone' => 'UTC',
// add as many ips as you want (they must be available in the server conf (ex: /etc/network/interfaces fro ubuntu/debian)
$config['IPs'] = [
//'xxx.xxx.xxx.xxx',
//'xxx.xxx.xxx.xxx',
];

/*
* Set your default timezone
*
* e.g. Asia/Tehran or America/New_York
*
* more examples: http://php.net/manual/en/timezones.php
*/
$config['default_timezone'] = 'UTC';

return $config;
8 changes: 5 additions & 3 deletions src/Application/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace YoutubeDownloader\Application;

use Exception;
use YoutubeDownloader\Config;
use YoutubeDownloader\Config\Config;
use YoutubeDownloader\VideoInfo\VideoInfo;

/**
Expand Down Expand Up @@ -55,14 +55,16 @@ public function execute()

// Fetch and serve
if ($url) {
$gui_config = $config->get('gui');

// prevent unauthorized download
if ($config->get('VideoLinkMode') === 'direct' and !isset($_GET['getmp3'])) {
if ($gui_config['VideoLinkMode'] === 'direct' and !isset($_GET['getmp3'])) {
$this->responseWithErrorMessage(
'VideoLinkMode: proxy download not enabled'
);
}

if ($config->get('VideoLinkMode') !== 'direct'
if ($gui_config['VideoLinkMode'] !== 'direct'
and ! isset($_GET['getmp3'])
and ! preg_match('@https://[^\.]+\.googlevideo.com/@', $url)
) {
Expand Down
4 changes: 3 additions & 1 deletion src/Application/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public function execute()
$config = $this->get('config');
$template = $this->get('template');

$gui_config = $config->get('gui');

echo $template->render('index.php', [
'app_version' => $this->getAppVersion(),
'showBrowserExtensions' => ($this->isUseragentChrome($_SERVER['HTTP_USER_AGENT']) and $config->get('showBrowserExtensions')),
'showBrowserExtensions' => ($this->isUseragentChrome($_SERVER['HTTP_USER_AGENT']) and $gui_config['showBrowserExtensions']),
]);
}
}