Applied fixes from StyleCI
This commit is contained in:
parent
6df1eccb9e
commit
13c3366e9d
6 changed files with 203 additions and 178 deletions
|
@ -1,78 +1,88 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Config class
|
* Config class.
|
||||||
*/
|
*/
|
||||||
namespace Alltube;
|
namespace Alltube;
|
||||||
|
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage config parameters
|
* Manage config parameters.
|
||||||
*/
|
*/
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Singleton instance
|
* Singleton instance.
|
||||||
|
*
|
||||||
* @var Config
|
* @var Config
|
||||||
*/
|
*/
|
||||||
private static $instance;
|
private static $instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* youtube-dl binary path
|
* youtube-dl binary path.
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py';
|
public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* python binary path
|
* python binary path.
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $python = '/usr/bin/python';
|
public $python = '/usr/bin/python';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* youtube-dl parameters
|
* youtube-dl parameters.
|
||||||
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $params = array('--no-playlist', '--no-warnings', '-f best[protocol^=http]', '--playlist-end', 1);
|
public $params = ['--no-playlist', '--no-warnings', '-f best[protocol^=http]', '--playlist-end', 1];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable audio conversion
|
* Enable audio conversion.
|
||||||
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $convert = false;
|
public $convert = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* avconv or ffmpeg binary path
|
* avconv or ffmpeg binary path.
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $avconv = 'vendor/bin/ffmpeg';
|
public $avconv = 'vendor/bin/ffmpeg';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rtmpdump binary path
|
* rtmpdump binary path.
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $rtmpdump = 'vendor/bin/rtmpdump';
|
public $rtmpdump = 'vendor/bin/rtmpdump';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* curl binary path
|
* curl binary path.
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $curl = '/usr/bin/curl';
|
public $curl = '/usr/bin/curl';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* curl parameters
|
* curl parameters.
|
||||||
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $curl_params = array();
|
public $curl_params = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YAML config file path
|
* YAML config file path.
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $file;
|
private $file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config constructor
|
* Config constructor.
|
||||||
*
|
*
|
||||||
* @param string $yamlfile YAML config file path
|
* @param string $yamlfile YAML config file path
|
||||||
*/
|
*/
|
||||||
|
@ -95,7 +105,7 @@ class Config
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get singleton instance
|
* Get singleton instance.
|
||||||
*
|
*
|
||||||
* @param string $yamlfile YAML config file name
|
* @param string $yamlfile YAML config file name
|
||||||
*
|
*
|
||||||
|
@ -105,13 +115,15 @@ class Config
|
||||||
{
|
{
|
||||||
$yamlfile = __DIR__.'/../'.$yamlfile;
|
$yamlfile = __DIR__.'/../'.$yamlfile;
|
||||||
if (is_null(self::$instance) || self::$instance->file != $yamlfile) {
|
if (is_null(self::$instance) || self::$instance->file != $yamlfile) {
|
||||||
self::$instance = new Config($yamlfile);
|
self::$instance = new self($yamlfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy singleton instance
|
* Destroy singleton instance.
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function destroyInstance()
|
public static function destroyInstance()
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* VideoDownload class
|
* VideoDownload class.
|
||||||
*/
|
*/
|
||||||
namespace Alltube;
|
namespace Alltube;
|
||||||
|
|
||||||
use Symfony\Component\Process\Process;
|
|
||||||
use Symfony\Component\Process\ProcessBuilder;
|
|
||||||
use Chain\Chain;
|
use Chain\Chain;
|
||||||
|
use Symfony\Component\Process\ProcessBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract info about videos
|
* Extract info about videos.
|
||||||
*/
|
*/
|
||||||
class VideoDownload
|
class VideoDownload
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VideoDownload constructor
|
* VideoDownload constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -23,31 +21,32 @@ class VideoDownload
|
||||||
$this->procBuilder = new ProcessBuilder();
|
$this->procBuilder = new ProcessBuilder();
|
||||||
$this->procBuilder->setPrefix(
|
$this->procBuilder->setPrefix(
|
||||||
array_merge(
|
array_merge(
|
||||||
array($this->config->python, $this->config->youtubedl),
|
[$this->config->python, $this->config->youtubedl],
|
||||||
$this->config->params
|
$this->config->params
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all extractors
|
* List all extractors.
|
||||||
*
|
*
|
||||||
* @return string[] Extractors
|
* @return string[] Extractors
|
||||||
* */
|
* */
|
||||||
public function listExtractors()
|
public function listExtractors()
|
||||||
{
|
{
|
||||||
$this->procBuilder->setArguments(
|
$this->procBuilder->setArguments(
|
||||||
array(
|
[
|
||||||
'--list-extractors'
|
'--list-extractors',
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
$process = $this->procBuilder->getProcess();
|
$process = $this->procBuilder->getProcess();
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
return explode(PHP_EOL, trim($process->getOutput()));
|
return explode(PHP_EOL, trim($process->getOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all information about a video
|
* Get all information about a video.
|
||||||
*
|
*
|
||||||
* @param string $url URL of page
|
* @param string $url URL of page
|
||||||
* @param string $format Format to use for the video
|
* @param string $format Format to use for the video
|
||||||
|
@ -57,10 +56,10 @@ class VideoDownload
|
||||||
public function getJSON($url, $format = null)
|
public function getJSON($url, $format = null)
|
||||||
{
|
{
|
||||||
$this->procBuilder->setArguments(
|
$this->procBuilder->setArguments(
|
||||||
array(
|
[
|
||||||
'--dump-json',
|
'--dump-json',
|
||||||
$url
|
$url,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
if (isset($format)) {
|
if (isset($format)) {
|
||||||
$this->procBuilder->add('-f '.$format);
|
$this->procBuilder->add('-f '.$format);
|
||||||
|
@ -75,7 +74,7 @@ class VideoDownload
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get URL of video from URL of page
|
* Get URL of video from URL of page.
|
||||||
*
|
*
|
||||||
* @param string $url URL of page
|
* @param string $url URL of page
|
||||||
* @param string $format Format to use for the video
|
* @param string $format Format to use for the video
|
||||||
|
@ -85,10 +84,10 @@ class VideoDownload
|
||||||
public function getURL($url, $format = null)
|
public function getURL($url, $format = null)
|
||||||
{
|
{
|
||||||
$this->procBuilder->setArguments(
|
$this->procBuilder->setArguments(
|
||||||
array(
|
[
|
||||||
'--get-url',
|
'--get-url',
|
||||||
$url
|
$url,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
if (isset($format)) {
|
if (isset($format)) {
|
||||||
$this->procBuilder->add('-f '.$format);
|
$this->procBuilder->add('-f '.$format);
|
||||||
|
@ -103,7 +102,7 @@ class VideoDownload
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get filename of video file from URL of page
|
* Get filename of video file from URL of page.
|
||||||
*
|
*
|
||||||
* @param string $url URL of page
|
* @param string $url URL of page
|
||||||
* @param string $format Format to use for the video
|
* @param string $format Format to use for the video
|
||||||
|
@ -113,10 +112,10 @@ class VideoDownload
|
||||||
public function getFilename($url, $format = null)
|
public function getFilename($url, $format = null)
|
||||||
{
|
{
|
||||||
$this->procBuilder->setArguments(
|
$this->procBuilder->setArguments(
|
||||||
array(
|
[
|
||||||
'--get-filename',
|
'--get-filename',
|
||||||
$url
|
$url,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
if (isset($format)) {
|
if (isset($format)) {
|
||||||
$this->procBuilder->add('-f '.$format);
|
$this->procBuilder->add('-f '.$format);
|
||||||
|
@ -131,7 +130,7 @@ class VideoDownload
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get filename of audio from URL of page
|
* Get filename of audio from URL of page.
|
||||||
*
|
*
|
||||||
* @param string $url URL of page
|
* @param string $url URL of page
|
||||||
* @param string $format Format to use for the video
|
* @param string $format Format to use for the video
|
||||||
|
@ -151,7 +150,7 @@ class VideoDownload
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get audio stream of converted video
|
* Get audio stream of converted video.
|
||||||
*
|
*
|
||||||
* @param string $url URL of page
|
* @param string $url URL of page
|
||||||
* @param string $format Format to use for the video
|
* @param string $format Format to use for the video
|
||||||
|
@ -172,14 +171,14 @@ class VideoDownload
|
||||||
$video->http_headers->{'User-Agent'}
|
$video->http_headers->{'User-Agent'}
|
||||||
);
|
);
|
||||||
$avconvProc = ProcessBuilder::create(
|
$avconvProc = ProcessBuilder::create(
|
||||||
array(
|
[
|
||||||
$this->config->avconv,
|
$this->config->avconv,
|
||||||
'-v', 'quiet',
|
'-v', 'quiet',
|
||||||
'-i', '-',
|
'-i', '-',
|
||||||
'-f', 'mp3',
|
'-f', 'mp3',
|
||||||
'-vn',
|
'-vn',
|
||||||
'pipe:1'
|
'pipe:1',
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') {
|
if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') {
|
||||||
|
@ -187,13 +186,13 @@ class VideoDownload
|
||||||
throw(new \Exception('Can\'t find rtmpdump'));
|
throw(new \Exception('Can\'t find rtmpdump'));
|
||||||
}
|
}
|
||||||
$builder = new ProcessBuilder(
|
$builder = new ProcessBuilder(
|
||||||
array(
|
[
|
||||||
$this->config->rtmpdump,
|
$this->config->rtmpdump,
|
||||||
'-q',
|
'-q',
|
||||||
'-r',
|
'-r',
|
||||||
$video->url,
|
$video->url,
|
||||||
'--pageUrl', $video->webpage_url
|
'--pageUrl', $video->webpage_url,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
if (isset($video->player_url)) {
|
if (isset($video->player_url)) {
|
||||||
$builder->add('--swfVfy');
|
$builder->add('--swfVfy');
|
||||||
|
@ -226,19 +225,20 @@ class VideoDownload
|
||||||
$chain = new Chain(
|
$chain = new Chain(
|
||||||
ProcessBuilder::create(
|
ProcessBuilder::create(
|
||||||
array_merge(
|
array_merge(
|
||||||
array(
|
[
|
||||||
$this->config->curl,
|
$this->config->curl,
|
||||||
'--silent',
|
'--silent',
|
||||||
'--location',
|
'--location',
|
||||||
'--user-agent', $video->http_headers->{'User-Agent'},
|
'--user-agent', $video->http_headers->{'User-Agent'},
|
||||||
$video->url
|
$video->url,
|
||||||
),
|
],
|
||||||
$this->config->curl_params
|
$this->config->curl_params
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$chain->add('|', $avconvProc);
|
$chain->add('|', $avconvProc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return popen($chain->getProcess()->getCommandLine(), 'r');
|
return popen($chain->getProcess()->getCommandLine(), 'r');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,41 +1,45 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* FrontController class
|
* FrontController class.
|
||||||
*/
|
*/
|
||||||
namespace Alltube\Controller;
|
namespace Alltube\Controller;
|
||||||
|
|
||||||
use Alltube\VideoDownload;
|
|
||||||
use Alltube\Config;
|
use Alltube\Config;
|
||||||
use Slim\Http\Stream;
|
use Alltube\VideoDownload;
|
||||||
|
use Slim\Container;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
use Slim\Container;
|
use Slim\Http\Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main controller
|
* Main controller.
|
||||||
*/
|
*/
|
||||||
class FrontController
|
class FrontController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Config instance
|
* Config instance.
|
||||||
|
*
|
||||||
* @var Config
|
* @var Config
|
||||||
*/
|
*/
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VideoDownload instance
|
* VideoDownload instance.
|
||||||
|
*
|
||||||
* @var VideoDownload
|
* @var VideoDownload
|
||||||
*/
|
*/
|
||||||
private $download;
|
private $download;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slim dependency container
|
* Slim dependency container.
|
||||||
|
*
|
||||||
* @var Container
|
* @var Container
|
||||||
*/
|
*/
|
||||||
private $container;
|
private $container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FrontController constructor
|
* FrontController constructor.
|
||||||
|
*
|
||||||
* @param Container $container Slim dependency container
|
* @param Container $container Slim dependency container
|
||||||
*/
|
*/
|
||||||
public function __construct(Container $container)
|
public function __construct(Container $container)
|
||||||
|
@ -46,7 +50,7 @@ class FrontController
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display index page
|
* Display index page.
|
||||||
*
|
*
|
||||||
* @param Request $request PSR-7 request
|
* @param Request $request PSR-7 request
|
||||||
* @param Response $response PSR-7 response
|
* @param Response $response PSR-7 response
|
||||||
|
@ -58,16 +62,16 @@ class FrontController
|
||||||
$this->container->view->render(
|
$this->container->view->render(
|
||||||
$response,
|
$response,
|
||||||
'index.tpl',
|
'index.tpl',
|
||||||
array(
|
[
|
||||||
'convert' => $this->config->convert,
|
'convert' => $this->config->convert,
|
||||||
'class' => 'index',
|
'class' => 'index',
|
||||||
'description'=>'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.'
|
'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.',
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a list of extractors
|
* Display a list of extractors.
|
||||||
*
|
*
|
||||||
* @param Request $request PSR-7 request
|
* @param Request $request PSR-7 request
|
||||||
* @param Response $response PSR-7 response
|
* @param Response $response PSR-7 response
|
||||||
|
@ -79,18 +83,17 @@ class FrontController
|
||||||
$this->container->view->render(
|
$this->container->view->render(
|
||||||
$response,
|
$response,
|
||||||
'extractors.tpl',
|
'extractors.tpl',
|
||||||
array(
|
[
|
||||||
'extractors' => $this->download->listExtractors(),
|
'extractors' => $this->download->listExtractors(),
|
||||||
'class' => 'extractors',
|
'class' => 'extractors',
|
||||||
'title' => 'Supported websites',
|
'title' => 'Supported websites',
|
||||||
'description'
|
'description' => 'List of all supported websites from which Alltube Download can extract video or audio files',
|
||||||
=>'List of all supported websites from which Alltube Download can extract video or audio files'
|
]
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dislay information about the video
|
* Dislay information about the video.
|
||||||
*
|
*
|
||||||
* @param Request $request PSR-7 request
|
* @param Request $request PSR-7 request
|
||||||
* @param Response $response PSR-7 response
|
* @param Response $response PSR-7 response
|
||||||
|
@ -101,36 +104,38 @@ class FrontController
|
||||||
{
|
{
|
||||||
$params = $request->getQueryParams();
|
$params = $request->getQueryParams();
|
||||||
$this->config = Config::getInstance();
|
$this->config = Config::getInstance();
|
||||||
if (isset($params["url"])) {
|
if (isset($params['url'])) {
|
||||||
if (isset($params['audio'])) {
|
if (isset($params['audio'])) {
|
||||||
try {
|
try {
|
||||||
$url = $this->download->getURL($params["url"], 'mp3[protocol^=http]');
|
$url = $this->download->getURL($params['url'], 'mp3[protocol^=http]');
|
||||||
|
|
||||||
return $response->withRedirect($url);
|
return $response->withRedirect($url);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$response = $response->withHeader(
|
$response = $response->withHeader(
|
||||||
'Content-Disposition',
|
'Content-Disposition',
|
||||||
'attachment; filename="'.
|
'attachment; filename="'.
|
||||||
$this->download->getAudioFilename($params["url"], 'bestaudio/best').'"'
|
$this->download->getAudioFilename($params['url'], 'bestaudio/best').'"'
|
||||||
);
|
);
|
||||||
$response = $response->withHeader('Content-Type', 'audio/mpeg');
|
$response = $response->withHeader('Content-Type', 'audio/mpeg');
|
||||||
|
|
||||||
if ($request->isGet()) {
|
if ($request->isGet()) {
|
||||||
$process = $this->download->getAudioStream($params["url"], 'bestaudio/best');
|
$process = $this->download->getAudioStream($params['url'], 'bestaudio/best');
|
||||||
$response = $response->withBody(new Stream($process));
|
$response = $response->withBody(new Stream($process));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$video = $this->download->getJSON($params["url"]);
|
$video = $this->download->getJSON($params['url']);
|
||||||
$this->container->view->render(
|
$this->container->view->render(
|
||||||
$response,
|
$response,
|
||||||
'video.tpl',
|
'video.tpl',
|
||||||
array(
|
[
|
||||||
'video' => $video,
|
'video' => $video,
|
||||||
'class' => 'video',
|
'class' => 'video',
|
||||||
'title' => $video->title,
|
'title' => $video->title,
|
||||||
'description'=>'Download "'.$video->title.'" from '.$video->extractor_key
|
'description' => 'Download "'.$video->title.'" from '.$video->extractor_key,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -139,10 +144,12 @@ class FrontController
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display an error page
|
* Display an error page.
|
||||||
|
*
|
||||||
* @param Request $request PSR-7 request
|
* @param Request $request PSR-7 request
|
||||||
* @param Response $response PSR-7 response
|
* @param Response $response PSR-7 response
|
||||||
* @param \Exception $exception Error to display
|
* @param \Exception $exception Error to display
|
||||||
|
*
|
||||||
* @return Response HTTP response
|
* @return Response HTTP response
|
||||||
*/
|
*/
|
||||||
public function error(Request $request, Response $response, \Exception $exception)
|
public function error(Request $request, Response $response, \Exception $exception)
|
||||||
|
@ -150,17 +157,18 @@ class FrontController
|
||||||
$this->container->view->render(
|
$this->container->view->render(
|
||||||
$response,
|
$response,
|
||||||
'error.tpl',
|
'error.tpl',
|
||||||
array(
|
[
|
||||||
'errors' => $exception->getMessage(),
|
'errors' => $exception->getMessage(),
|
||||||
'class' => 'video',
|
'class' => 'video',
|
||||||
'title'=>'Error'
|
'title' => 'Error',
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return $response->withStatus(500);
|
return $response->withStatus(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirect to video file
|
* Redirect to video file.
|
||||||
*
|
*
|
||||||
* @param Request $request PSR-7 request
|
* @param Request $request PSR-7 request
|
||||||
* @param Response $response PSR-7 response
|
* @param Response $response PSR-7 response
|
||||||
|
@ -170,19 +178,21 @@ class FrontController
|
||||||
public function redirect(Request $request, Response $response)
|
public function redirect(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
$params = $request->getQueryParams();
|
$params = $request->getQueryParams();
|
||||||
if (isset($params["url"])) {
|
if (isset($params['url'])) {
|
||||||
try {
|
try {
|
||||||
$url = $this->download->getURL($params["url"], $params["format"]);
|
$url = $this->download->getURL($params['url'], $params['format']);
|
||||||
|
|
||||||
return $response->withRedirect($url);
|
return $response->withRedirect($url);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$response->getBody()->write($e->getMessage());
|
$response->getBody()->write($e->getMessage());
|
||||||
|
|
||||||
return $response->withHeader('Content-Type', 'text/plain');
|
return $response->withHeader('Content-Type', 'text/plain');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output JSON info about the video
|
* Output JSON info about the video.
|
||||||
*
|
*
|
||||||
* @param Request $request PSR-7 request
|
* @param Request $request PSR-7 request
|
||||||
* @param Response $response PSR-7 response
|
* @param Response $response PSR-7 response
|
||||||
|
@ -192,13 +202,14 @@ class FrontController
|
||||||
public function json(Request $request, Response $response)
|
public function json(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
$params = $request->getQueryParams();
|
$params = $request->getQueryParams();
|
||||||
if (isset($params["url"])) {
|
if (isset($params['url'])) {
|
||||||
try {
|
try {
|
||||||
$video = $this->download->getJSON($params["url"]);
|
$video = $this->download->getJSON($params['url']);
|
||||||
|
|
||||||
return $response->withJson($video);
|
return $response->withJson($video);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $response->withJson(
|
return $response->withJson(
|
||||||
array('success'=>false, 'error'=>$e->getMessage())
|
['success' => false, 'error' => $e->getMessage()]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
index.php
14
index.php
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once __DIR__.'/vendor/autoload.php';
|
require_once __DIR__.'/vendor/autoload.php';
|
||||||
use Alltube\VideoDownload;
|
|
||||||
use Alltube\Controller\FrontController;
|
use Alltube\Controller\FrontController;
|
||||||
|
|
||||||
if (strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
|
if (strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
|
||||||
|
@ -22,26 +22,26 @@ $container['view'] = function ($c) {
|
||||||
|
|
||||||
$controller = new FrontController($container);
|
$controller = new FrontController($container);
|
||||||
|
|
||||||
$container['errorHandler'] = array($controller, 'error');
|
$container['errorHandler'] = [$controller, 'error'];
|
||||||
|
|
||||||
$app->get(
|
$app->get(
|
||||||
'/',
|
'/',
|
||||||
array($controller, 'index')
|
[$controller, 'index']
|
||||||
)->setName('index');
|
)->setName('index');
|
||||||
$app->get(
|
$app->get(
|
||||||
'/extractors',
|
'/extractors',
|
||||||
array($controller, 'extractors')
|
[$controller, 'extractors']
|
||||||
)->setName('extractors');
|
)->setName('extractors');
|
||||||
$app->get(
|
$app->get(
|
||||||
'/video',
|
'/video',
|
||||||
array($controller, 'video')
|
[$controller, 'video']
|
||||||
)->setName('video');
|
)->setName('video');
|
||||||
$app->get(
|
$app->get(
|
||||||
'/redirect',
|
'/redirect',
|
||||||
array($controller, 'redirect')
|
[$controller, 'redirect']
|
||||||
)->setName('redirect');
|
)->setName('redirect');
|
||||||
$app->get(
|
$app->get(
|
||||||
'/json',
|
'/json',
|
||||||
array($controller, 'json')
|
[$controller, 'json']
|
||||||
);
|
);
|
||||||
$app->run();
|
$app->run();
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* ConfigTest class
|
* ConfigTest class.
|
||||||
*/
|
*/
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Config;
|
use Alltube\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the Config class
|
* Unit tests for the Config class.
|
||||||
*/
|
*/
|
||||||
class ConfigTest extends \PHPUnit_Framework_TestCase
|
class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config class instance
|
* Config class instance.
|
||||||
|
*
|
||||||
* @var Config
|
* @var Config
|
||||||
*/
|
*/
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare tests
|
* Prepare tests.
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the getInstance function
|
* Test the getInstance function.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -43,7 +43,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the getInstance function with the CONVERT environment variable
|
* Test the getInstance function with the CONVERT environment variable.
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetInstanceWithEnv()
|
public function testGetInstanceWithEnv()
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* VideoDownloadTest class
|
* VideoDownloadTest class.
|
||||||
*/
|
*/
|
||||||
namespace Alltube\Test;
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\VideoDownload;
|
use Alltube\VideoDownload;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the VideoDownload class
|
* Unit tests for the VideoDownload class.
|
||||||
*/
|
*/
|
||||||
class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* VideoDownload instance
|
* VideoDownload instance.
|
||||||
|
*
|
||||||
* @var VideoDownload
|
* @var VideoDownload
|
||||||
*/
|
*/
|
||||||
private $download;
|
private $download;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize properties used by test
|
* Initialize properties used by test.
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
|
@ -26,7 +27,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy properties after test
|
* Destroy properties after test.
|
||||||
*/
|
*/
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
|
@ -34,7 +35,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test listExtractors function
|
* Test listExtractors function.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -45,7 +46,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getURL function
|
* Test getURL function.
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param string $format Format
|
* @param string $format Format
|
||||||
|
@ -62,7 +63,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getURL function errors
|
* Test getURL function errors.
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
*
|
*
|
||||||
|
@ -76,62 +77,62 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides URLs for tests
|
* Provides URLs for tests.
|
||||||
*
|
*
|
||||||
* @return array[]
|
* @return array[]
|
||||||
*/
|
*/
|
||||||
public function urlProvider()
|
public function urlProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array(
|
[
|
||||||
'https://www.youtube.com/watch?v=M7IpKCZ47pU', null,
|
'https://www.youtube.com/watch?v=M7IpKCZ47pU', null,
|
||||||
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp4",
|
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp4",
|
||||||
'googlevideo.com',
|
'googlevideo.com',
|
||||||
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp3"
|
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp3",
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'https://www.youtube.com/watch?v=RJJ6FCAXvKg', 22,
|
'https://www.youtube.com/watch?v=RJJ6FCAXvKg', 22,
|
||||||
"'Heart Attack' - Demi Lovato ".
|
"'Heart Attack' - Demi Lovato ".
|
||||||
"(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp4",
|
'(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp4',
|
||||||
'googlevideo.com',
|
'googlevideo.com',
|
||||||
"'Heart Attack' - Demi Lovato ".
|
"'Heart Attack' - Demi Lovato ".
|
||||||
"(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp3"
|
'(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp3',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'https://vimeo.com/24195442', null,
|
'https://vimeo.com/24195442', null,
|
||||||
"Carving the Mountains-24195442.mp4",
|
'Carving the Mountains-24195442.mp4',
|
||||||
'vimeocdn.com',
|
'vimeocdn.com',
|
||||||
"Carving the Mountains-24195442.mp3"
|
'Carving the Mountains-24195442.mp3',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'http://www.bbc.co.uk/programmes/b039g8p7', 'bestaudio/best',
|
'http://www.bbc.co.uk/programmes/b039g8p7', 'bestaudio/best',
|
||||||
"Leonard Cohen, Kaleidoscope - BBC Radio 4-b039d07m.flv",
|
'Leonard Cohen, Kaleidoscope - BBC Radio 4-b039d07m.flv',
|
||||||
'bbcodspdns.fcod.llnwd.net',
|
'bbcodspdns.fcod.llnwd.net',
|
||||||
"Leonard Cohen, Kaleidoscope - BBC Radio 4-b039d07m.mp3"
|
'Leonard Cohen, Kaleidoscope - BBC Radio 4-b039d07m.mp3',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0', 'bestaudio/best',
|
'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0', 'bestaudio/best',
|
||||||
"GRIP sucht den Sommerkönig-folge-203-0.f4v",
|
'GRIP sucht den Sommerkönig-folge-203-0.f4v',
|
||||||
'edgefcs.net',
|
'edgefcs.net',
|
||||||
"GRIP sucht den Sommerkönig-folge-203-0.mp3"
|
'GRIP sucht den Sommerkönig-folge-203-0.mp3',
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides incorrect URLs for tests
|
* Provides incorrect URLs for tests.
|
||||||
*
|
*
|
||||||
* @return array[]
|
* @return array[]
|
||||||
*/
|
*/
|
||||||
public function errorUrlProvider()
|
public function errorUrlProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('http://example.com/video')
|
['http://example.com/video'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getJSON function
|
* Test getJSON function.
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param string $format Format
|
* @param string $format Format
|
||||||
|
@ -151,7 +152,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getJSON function errors
|
* Test getJSON function errors.
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
*
|
*
|
||||||
|
@ -165,7 +166,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getFilename function
|
* Test getFilename function.
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param string $format Format
|
* @param string $format Format
|
||||||
|
@ -181,7 +182,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getFilename function errors
|
* Test getFilename function errors.
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
*
|
*
|
||||||
|
@ -195,7 +196,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getAudioFilename function
|
* Test getAudioFilename function.
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param string $format Format
|
* @param string $format Format
|
||||||
|
@ -213,7 +214,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getAudioStream function
|
* Test getAudioStream function.
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param string $format Format
|
* @param string $format Format
|
||||||
|
@ -229,7 +230,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getAudioStream function without avconv
|
* Test getAudioStream function without avconv.
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param string $format Format
|
* @param string $format Format
|
||||||
|
@ -246,7 +247,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test getAudioStream function without curl or rtmpdump
|
* Test getAudioStream function without curl or rtmpdump.
|
||||||
*
|
*
|
||||||
* @param string $url URL
|
* @param string $url URL
|
||||||
* @param string $format Format
|
* @param string $format Format
|
||||||
|
|
Loading…
Reference in a new issue