diff --git a/classes/Config.php b/classes/Config.php index 7d33665..208e85b 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -1,74 +1,90 @@ file != $yamlfile) { - self::$instance = new Config($yamlfile); + self::$instance = new self($yamlfile); } + return self::$instance; } /** - * Destroy singleton instance + * Destroy singleton instance. + * * @return void */ public static function destroyInstance() diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index 5023a20..e497113 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -1,21 +1,19 @@ procBuilder = new ProcessBuilder(); $this->procBuilder->setPrefix( array_merge( - array($this->config->python, $this->config->youtubedl), + [$this->config->python, $this->config->youtubedl], $this->config->params ) ); } /** - * List all extractors + * List all extractors. * * @return string[] Extractors * */ public function listExtractors() { $this->procBuilder->setArguments( - array( - '--list-extractors' - ) + [ + '--list-extractors', + ] ); $process = $this->procBuilder->getProcess(); $process->run(); + 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 $format Format to use for the video @@ -57,10 +56,10 @@ class VideoDownload public function getJSON($url, $format = null) { $this->procBuilder->setArguments( - array( + [ '--dump-json', - $url - ) + $url, + ] ); if (isset($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 $format Format to use for the video @@ -85,10 +84,10 @@ class VideoDownload public function getURL($url, $format = null) { $this->procBuilder->setArguments( - array( + [ '--get-url', - $url - ) + $url, + ] ); if (isset($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 $format Format to use for the video @@ -113,10 +112,10 @@ class VideoDownload public function getFilename($url, $format = null) { $this->procBuilder->setArguments( - array( + [ '--get-filename', - $url - ) + $url, + ] ); if (isset($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 $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 $format Format to use for the video @@ -172,14 +171,14 @@ class VideoDownload $video->http_headers->{'User-Agent'} ); $avconvProc = ProcessBuilder::create( - array( + [ $this->config->avconv, '-v', 'quiet', '-i', '-', '-f', 'mp3', '-vn', - 'pipe:1' - ) + 'pipe:1', + ] ); if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') { @@ -187,13 +186,13 @@ class VideoDownload throw(new \Exception('Can\'t find rtmpdump')); } $builder = new ProcessBuilder( - array( + [ $this->config->rtmpdump, '-q', '-r', $video->url, - '--pageUrl', $video->webpage_url - ) + '--pageUrl', $video->webpage_url, + ] ); if (isset($video->player_url)) { $builder->add('--swfVfy'); @@ -226,19 +225,20 @@ class VideoDownload $chain = new Chain( ProcessBuilder::create( array_merge( - array( + [ $this->config->curl, '--silent', '--location', '--user-agent', $video->http_headers->{'User-Agent'}, - $video->url - ), + $video->url, + ], $this->config->curl_params ) ) ); $chain->add('|', $avconvProc); } + return popen($chain->getProcess()->getCommandLine(), 'r'); } } diff --git a/composer.json b/composer.json index c2884a9..7350def 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "type": "project", "require": { "smarty/smarty": "~3.1.29", - "rg3/youtube-dl": "~2016.08.12", + "rg3/youtube-dl": "~2016.09.08", "slim/slim": "~3.5.0", "mathmarques/smarty-view": "~1.1.0", "symfony/yaml": "~3.1.0", @@ -33,11 +33,11 @@ "type": "package", "package": { "name": "rg3/youtube-dl", - "version": "2016.08.12", + "version": "2016.09.08", "source": { "url": "https://github.com/rg3/youtube-dl.git", "type": "git", - "reference": "2016.08.12" + "reference": "2016.09.08" } } }, diff --git a/composer.lock b/composer.lock index 965e802..d782024 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "85ec531cf9a73084ab531e5b781f8844", - "content-hash": "054a8bdbb08cfac744d4b28965fb6f17", + "hash": "a0f80c6bc52ec374622802fb83f64122", + "content-hash": "8d944e2e3dfabcc3c311c954932321f1", "packages": [ { "name": "container-interop/container-interop", @@ -176,16 +176,16 @@ }, { "name": "mathmarques/smarty-view", - "version": "1.1.0", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/mathmarques/Smarty-View.git", - "reference": "66f4d28c564c0363eda18d3f5b85a4241b1c4ad1" + "reference": "c8f8501a0be4c290e1165fcb9e5064952ef6969d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mathmarques/Smarty-View/zipball/66f4d28c564c0363eda18d3f5b85a4241b1c4ad1", - "reference": "66f4d28c564c0363eda18d3f5b85a4241b1c4ad1", + "url": "https://api.github.com/repos/mathmarques/Smarty-View/zipball/c8f8501a0be4c290e1165fcb9e5064952ef6969d", + "reference": "c8f8501a0be4c290e1165fcb9e5064952ef6969d", "shasum": "" }, "require": { @@ -222,7 +222,7 @@ "template", "view" ], - "time": "2016-03-31 00:41:59" + "time": "2016-08-25 19:04:49" }, { "name": "nikic/fast-route", @@ -401,11 +401,11 @@ }, { "name": "rg3/youtube-dl", - "version": "2016.08.12", + "version": "2016.09.08", "source": { "type": "git", "url": "https://github.com/rg3/youtube-dl.git", - "reference": "2016.08.12" + "reference": "2016.09.08" }, "type": "library" }, @@ -605,16 +605,16 @@ }, { "name": "symfony/process", - "version": "v3.1.3", + "version": "v3.1.4", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "04c2dfaae4ec56a5c677b0c69fac34637d815758" + "reference": "e64e93041c80e77197ace5ab9385dedb5a143697" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/04c2dfaae4ec56a5c677b0c69fac34637d815758", - "reference": "04c2dfaae4ec56a5c677b0c69fac34637d815758", + "url": "https://api.github.com/repos/symfony/process/zipball/e64e93041c80e77197ace5ab9385dedb5a143697", + "reference": "e64e93041c80e77197ace5ab9385dedb5a143697", "shasum": "" }, "require": { @@ -650,20 +650,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-07-28 11:13:48" + "time": "2016-08-16 14:58:24" }, { "name": "symfony/yaml", - "version": "v3.1.3", + "version": "v3.1.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "1819adf2066880c7967df7180f4f662b6f0567ac" + "reference": "f291ed25eb1435bddbe8a96caaef16469c2a092d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/1819adf2066880c7967df7180f4f662b6f0567ac", - "reference": "1819adf2066880c7967df7180f4f662b6f0567ac", + "url": "https://api.github.com/repos/symfony/yaml/zipball/f291ed25eb1435bddbe8a96caaef16469c2a092d", + "reference": "f291ed25eb1435bddbe8a96caaef16469c2a092d", "shasum": "" }, "require": { @@ -699,7 +699,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-07-17 14:02:08" + "time": "2016-09-02 02:12:52" } ], "packages-dev": [ @@ -759,16 +759,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.5.1", + "version": "1.5.2", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "a8773992b362b58498eed24bf85005f363c34771" + "reference": "da8529775f14f4fdae33f916eb0cf65f6afbddbc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/a8773992b362b58498eed24bf85005f363c34771", - "reference": "a8773992b362b58498eed24bf85005f363c34771", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/da8529775f14f4fdae33f916eb0cf65f6afbddbc", + "reference": "da8529775f14f4fdae33f916eb0cf65f6afbddbc", "shasum": "" }, "require": { @@ -797,7 +797,7 @@ "object", "object graph" ], - "time": "2015-11-20 12:04:31" + "time": "2016-09-06 16:07:05" }, { "name": "phpdocumentor/reflection-common", @@ -1253,16 +1253,16 @@ }, { "name": "phpunit/phpunit", - "version": "5.5.2", + "version": "5.5.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "46ec2d1522ae8c9a12aca6b7650e0be78bbb0502" + "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/46ec2d1522ae8c9a12aca6b7650e0be78bbb0502", - "reference": "46ec2d1522ae8c9a12aca6b7650e0be78bbb0502", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3e6e88e56c912133de6e99b87728cca7ed70c5f5", + "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5", "shasum": "" }, "require": { @@ -1327,20 +1327,20 @@ "testing", "xunit" ], - "time": "2016-08-18 11:10:44" + "time": "2016-08-26 07:11:44" }, { "name": "phpunit/phpunit-mock-objects", - "version": "3.2.4", + "version": "3.2.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "4e83390f64e7ce04fcaec2ce95cd72823b431d19" + "reference": "546898a2c0c356ef2891b39dd7d07f5d82c8ed0a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/4e83390f64e7ce04fcaec2ce95cd72823b431d19", - "reference": "4e83390f64e7ce04fcaec2ce95cd72823b431d19", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/546898a2c0c356ef2891b39dd7d07f5d82c8ed0a", + "reference": "546898a2c0c356ef2891b39dd7d07f5d82c8ed0a", "shasum": "" }, "require": { @@ -1386,7 +1386,7 @@ "mock", "xunit" ], - "time": "2016-08-17 09:33:51" + "time": "2016-09-06 16:07:45" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -2040,16 +2040,16 @@ }, { "name": "symfony/var-dumper", - "version": "v3.1.3", + "version": "v3.1.4", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "076235b750137518408f1bc17a8e69b43211836a" + "reference": "62ee73706c421654a4c840028954510277f7dfc8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/076235b750137518408f1bc17a8e69b43211836a", - "reference": "076235b750137518408f1bc17a8e69b43211836a", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/62ee73706c421654a4c840028954510277f7dfc8", + "reference": "62ee73706c421654a4c840028954510277f7dfc8", "shasum": "" }, "require": { @@ -2099,7 +2099,7 @@ "debug", "dump" ], - "time": "2016-07-26 08:04:17" + "time": "2016-08-31 09:05:42" }, { "name": "webmozart/assert", diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 177e636..2348db8 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -1,41 +1,45 @@ container->view->render( $response, 'index.tpl', - array( - 'convert'=>$this->config->convert, - 'class'=>'index', - 'description'=>'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.' - ) + [ + 'convert' => $this->config->convert, + 'class' => 'index', + '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 Response $response PSR-7 response @@ -79,18 +83,18 @@ class FrontController $this->container->view->render( $response, 'extractors.tpl', - array( - 'extractors'=>$this->download->listExtractors(), - 'class'=>'extractors', - 'title'=>'Supported websites', - 'description' - =>'List of all supported websites from which Alltube Download can extract video or audio files' - ) + [ + 'extractors' => $this->download->listExtractors(), + 'class' => 'extractors', + 'title' => 'Supported websites', + 'description' => '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 Response $response PSR-7 response @@ -101,36 +105,38 @@ class FrontController { $params = $request->getQueryParams(); $this->config = Config::getInstance(); - if (isset($params["url"])) { + if (isset($params['url'])) { if (isset($params['audio'])) { try { - $url = $this->download->getURL($params["url"], 'mp3[protocol^=http]'); + $url = $this->download->getURL($params['url'], 'mp3[protocol^=http]'); + return $response->withRedirect($url); } catch (\Exception $e) { $response = $response->withHeader( 'Content-Disposition', 'attachment; filename="'. - $this->download->getAudioFilename($params["url"], 'bestaudio/best').'"' + $this->download->getAudioFilename($params['url'], 'bestaudio/best').'"' ); $response = $response->withHeader('Content-Type', 'audio/mpeg'); 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)); } + return $response; } } else { - $video = $this->download->getJSON($params["url"]); + $video = $this->download->getJSON($params['url']); $this->container->view->render( $response, 'video.tpl', - array( - 'video'=>$video, - 'class'=>'video', - 'title'=>$video->title, - 'description'=>'Download "'.$video->title.'" from '.$video->extractor_key - ) + [ + 'video' => $video, + 'class' => 'video', + 'title' => $video->title, + 'description' => 'Download "'.$video->title.'" from '.$video->extractor_key, + ] ); } } else { @@ -139,10 +145,12 @@ class FrontController } /** - * Display an error page - * @param Request $request PSR-7 request - * @param Response $response PSR-7 response - * @param \Exception $exception Error to display + * Display an error page. + * + * @param Request $request PSR-7 request + * @param Response $response PSR-7 response + * @param \Exception $exception Error to display + * * @return Response HTTP response */ public function error(Request $request, Response $response, \Exception $exception) @@ -150,17 +158,18 @@ class FrontController $this->container->view->render( $response, 'error.tpl', - array( - 'errors'=>$exception->getMessage(), - 'class'=>'video', - 'title'=>'Error' - ) + [ + 'errors' => $exception->getMessage(), + 'class' => 'video', + 'title' => 'Error', + ] ); + return $response->withStatus(500); } /** - * Redirect to video file + * Redirect to video file. * * @param Request $request PSR-7 request * @param Response $response PSR-7 response @@ -170,19 +179,21 @@ class FrontController public function redirect(Request $request, Response $response) { $params = $request->getQueryParams(); - if (isset($params["url"])) { + if (isset($params['url'])) { try { - $url = $this->download->getURL($params["url"], $params["format"]); + $url = $this->download->getURL($params['url'], $params['format']); + return $response->withRedirect($url); } catch (\Exception $e) { $response->getBody()->write($e->getMessage()); + 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 Response $response PSR-7 response @@ -192,13 +203,14 @@ class FrontController public function json(Request $request, Response $response) { $params = $request->getQueryParams(); - if (isset($params["url"])) { + if (isset($params['url'])) { try { - $video = $this->download->getJSON($params["url"]); + $video = $this->download->getJSON($params['url']); + return $response->withJson($video); } catch (\Exception $e) { return $response->withJson( - array('success'=>false, 'error'=>$e->getMessage()) + ['success' => false, 'error' => $e->getMessage()] ); } } diff --git a/index.php b/index.php index 60026bf..0653081 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ get( '/', - array($controller, 'index') + [$controller, 'index'] )->setName('index'); $app->get( '/extractors', - array($controller, 'extractors') + [$controller, 'extractors'] )->setName('extractors'); $app->get( '/video', - array($controller, 'video') + [$controller, 'video'] )->setName('video'); $app->get( '/redirect', - array($controller, 'redirect') + [$controller, 'redirect'] )->setName('redirect'); $app->get( '/json', - array($controller, 'json') + [$controller, 'json'] ); $app->run(); diff --git a/package.json b/package.json index fcaf214..894e62f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "alltube", "description": "HTML GUI for youtube-dl", - "version": "0.5.0", + "version": "0.5.2", "author": "Pierre Rudloff", "bugs": "https://github.com/Rudloff/alltube/issues", "dependencies": { diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 8ea8e84..9e7e1d8 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -1,26 +1,33 @@ config = Config::getInstance('config_test.yml'); } /** - * Test the getInstance function + * Test the getInstance function. * * @return void */ @@ -35,6 +42,11 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $this->assertInternalType('string', $this->config->rtmpdump); } + /** + * Test the getInstance function with the CONVERT environment variable. + * + * @return void + */ public function testGetInstanceWithEnv() { putenv('CONVERT=1'); diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index c0ce2d7..8e5d705 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -1,24 +1,25 @@