From 2cf90bad96e7ceb0db1b19226cbc57c8f6c24786 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Mon, 2 Jan 2017 11:23:35 +0100 Subject: [PATCH 01/13] Add heroku-buildpack-php to dev dependencies (see #86) --- composer.json | 3 ++- composer.lock | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f88ac97..eb602b7 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "phpunit/phpunit": "~5.7.2", "ffmpeg/ffmpeg": "dev-release", "rg3/youtube-dl": "~2016.12.22", - "rudloff/rtmpdump-bin": "~2.3" + "rudloff/rtmpdump-bin": "~2.3", + "heroku/heroku-buildpack-php": "*" }, "extra": { "paas": { diff --git a/composer.lock b/composer.lock index 13215e8..660f855 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "cbf8089486d9ab0599ff3d7c22f045a7", + "content-hash": "91e14c843bc92c4d5af1ec7abcddf15a", "packages": [ { "name": "aura/session", @@ -784,6 +784,50 @@ ], "type": "library" }, + { + "name": "heroku/heroku-buildpack-php", + "version": "v117", + "source": { + "type": "git", + "url": "https://github.com/heroku/heroku-buildpack-php.git", + "reference": "960199a978308c75926fd9bb4775f7113bf1d777" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/heroku/heroku-buildpack-php/zipball/960199a978308c75926fd9bb4775f7113bf1d777", + "reference": "960199a978308c75926fd9bb4775f7113bf1d777", + "shasum": "" + }, + "bin": [ + "bin/heroku-hhvm-apache2", + "bin/heroku-hhvm-nginx", + "bin/heroku-php-apache2", + "bin/heroku-php-nginx" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "David Zuelke", + "email": "dz@heroku.com" + } + ], + "description": "Toolkit for starting a PHP application locally, with or without foreman, using the same config for PHP/HHVM and Apache2/Nginx as on Heroku", + "homepage": "https://github.com/heroku/heroku-buildpack-php", + "keywords": [ + "apache", + "apache2", + "foreman", + "heroku", + "hhvm", + "nginx", + "php" + ], + "time": "2016-12-09T19:37:38+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.5.5", From dd539c57f8911427568fa64cbaf72eb1da3de9b8 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Mon, 2 Jan 2017 23:08:51 +0100 Subject: [PATCH 02/13] Simplify test data provider --- tests/VideoDownloadTest.php | 47 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index 58624d8..8af3275 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -76,15 +76,16 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase /** * Test getURL function. * - * @param string $url URL - * @param string $format Format - * @param string $filename Filename - * @param string $domain Domain + * @param string $url URL + * @param string $format Format + * @param string $filename Filename + * @param string $extension File extension + * @param string $domain Domain * * @return void * @dataProvider urlProvider */ - public function testGetURL($url, $format, $filename, $domain) + public function testGetURL($url, $format, $filename, $extension, $domain) { $videoURL = $this->download->getURL($url, $format); $this->assertContains($domain, $videoURL); @@ -146,35 +147,34 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase return [ [ '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', - "It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp3", ], [ 'https://www.youtube.com/watch?v=RJJ6FCAXvKg', 22, "'Heart Attack' - Demi Lovato ". - '(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp4', + '(Sam Tsui & Against The Current)-RJJ6FCAXvKg', + 'mp4', 'googlevideo.com', - "'Heart Attack' - Demi Lovato ". - '(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp3', ], [ 'https://vimeo.com/24195442', null, - 'Carving the Mountains-24195442.mp4', + 'Carving the Mountains-24195442', + 'mp4', 'vimeocdn.com', - 'Carving the Mountains-24195442.mp3', ], [ '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', - 'Leonard Cohen, Kaleidoscope - BBC Radio 4-b039d07m.mp3', ], [ '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', - 'GRIP sucht den Sommerkönig-folge-203-0.mp3', ], ]; } @@ -228,17 +228,18 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase /** * Test getFilename function. * - * @param string $url URL - * @param string $format Format - * @param string $filename Filename + * @param string $url URL + * @param string $format Format + * @param string $filename Filename + * @param string $extension File extension * * @return void * @dataProvider urlProvider */ - public function testGetFilename($url, $format, $filename) + public function testGetFilename($url, $format, $filename, $extension) { $videoFilename = $this->download->getFilename($url, $format); - $this->assertEquals($videoFilename, $filename); + $this->assertEquals($videoFilename, $filename.'.'.$extension); } /** @@ -267,10 +268,10 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase * @return void * @dataProvider urlProvider */ - public function testGetAudioFilename($url, $format, $filename, $domain, $audioFilename) + public function testGetAudioFilename($url, $format, $filename) { $videoFilename = $this->download->getAudioFilename($url, $format); - $this->assertEquals($videoFilename, $audioFilename); + $this->assertEquals($videoFilename, $filename.'.mp3'); } /** From d6f851f46953347d56fc534415f93108631021bf Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 3 Jan 2017 14:26:15 +0100 Subject: [PATCH 03/13] 0.7.1 release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c2a8d92..ea7dba8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "alltube", "description": "HTML GUI for youtube-dl", - "version": "0.7.0", + "version": "0.7.1", "author": "Pierre Rudloff", "bugs": "https://github.com/Rudloff/alltube/issues", "dependencies": { From 649b8e5351437727683dc350cb138599795b2e54 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 8 Jan 2017 23:51:14 +0100 Subject: [PATCH 04/13] Remove unused redirects --- .htaccess | 3 --- 1 file changed, 3 deletions(-) diff --git a/.htaccess b/.htaccess index 8ccd69c..5b53e93 100644 --- a/.htaccess +++ b/.htaccess @@ -21,7 +21,4 @@ RewriteRule ^(.*)$ https://www.alltubedownload.net/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] -Redirect permanent /api.php /video -Redirect permanent /extractors.php /extractors - AddOutputFilterByType DEFLATE text/css text/html application/javascript font/truetype From 52ae6eaefff26607dd0fa3c4903820108f74d5c2 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Mon, 9 Jan 2017 00:05:49 +0100 Subject: [PATCH 05/13] Add ifmodule conditions in .htaccess --- .htaccess | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.htaccess b/.htaccess index 5b53e93..32a41b4 100644 --- a/.htaccess +++ b/.htaccess @@ -1,5 +1,7 @@ -AddType application/x-web-app-manifest+json .webapp -Addtype font/truetype .ttf + + AddType application/x-web-app-manifest+json .webapp + Addtype font/truetype .ttf + ExpiresActive On @@ -21,4 +23,6 @@ RewriteRule ^(.*)$ https://www.alltubedownload.net/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] -AddOutputFilterByType DEFLATE text/css text/html application/javascript font/truetype + + AddOutputFilterByType DEFLATE text/css text/html application/javascript font/truetype + From 4562c888599265d048df614977872341c76c952b Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 10 Jan 2017 23:09:57 +0100 Subject: [PATCH 06/13] youtube-dl update --- composer.json | 6 +++--- composer.lock | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index eb602b7..3d91719 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "squizlabs/php_codesniffer": "~2.7.0", "phpunit/phpunit": "~5.7.2", "ffmpeg/ffmpeg": "dev-release", - "rg3/youtube-dl": "~2016.12.22", + "rg3/youtube-dl": "~2017.01.10", "rudloff/rtmpdump-bin": "~2.3", "heroku/heroku-buildpack-php": "*" }, @@ -35,10 +35,10 @@ "type": "package", "package": { "name": "rg3/youtube-dl", - "version": "2016.12.22", + "version": "2017.01.10", "dist": { "type": "zip", - "url": "https://github.com/rg3/youtube-dl/archive/2016.12.22.zip" + "url": "https://github.com/rg3/youtube-dl/archive/2017.01.10.zip" } } }, diff --git a/composer.lock b/composer.lock index 660f855..f9f96e3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "91e14c843bc92c4d5af1ec7abcddf15a", + "content-hash": "16268cc5135ed42aedf75446f4e39bd7", "packages": [ { "name": "aura/session", @@ -1466,10 +1466,10 @@ }, { "name": "rg3/youtube-dl", - "version": "2016.12.22", + "version": "2017.01.10", "dist": { "type": "zip", - "url": "https://github.com/rg3/youtube-dl/archive/2016.12.22.zip", + "url": "https://github.com/rg3/youtube-dl/archive/2017.01.10.zip", "reference": null, "shasum": null }, From 9f112c15b9948a548a297b077c2ff2a2b4a3c3ed Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 10 Jan 2017 23:37:29 +0100 Subject: [PATCH 07/13] Add an uglyUrls option that disables URL rewriting (fixes #88) --- classes/Config.php | 6 +++ classes/UglyRouter.php | 60 ++++++++++++++++++++++++ config.example.yml | 1 + controllers/FrontController.php | 1 + index.php | 6 +++ templates/index.tpl | 3 ++ templates/video.tpl | 3 ++ tests/UglyRouterTest.php | 82 +++++++++++++++++++++++++++++++++ 8 files changed, 162 insertions(+) create mode 100644 classes/UglyRouter.php create mode 100644 tests/UglyRouterTest.php diff --git a/classes/Config.php b/classes/Config.php index c57c848..a66955c 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -75,6 +75,12 @@ class Config */ public $curl_params = []; + /** + * Disable URL rewriting. + * @var boolean + */ + public $uglyUrls = false; + /** * YAML config file path. * diff --git a/classes/UglyRouter.php b/classes/UglyRouter.php new file mode 100644 index 0000000..a81471b --- /dev/null +++ b/classes/UglyRouter.php @@ -0,0 +1,60 @@ +getUri()->getQuery(), $args); + $uri = '/'; + if (isset($args['page'])) { + $uri .= $args['page']; + } + + return $this->createDispatcher()->dispatch( + $request->getMethod(), + $uri + ); + } + + /** + * Build the path for a named route including the base path + * + * @param string $name Route name + * @param array $data Named argument replacement data + * @param array $queryParams Optional query string parameters + * + * @return string + * + * @throws \RuntimeException If named route does not exist + * @throws \InvalidArgumentException If required data not provided + */ + public function pathFor($name, array $data = [], array $queryParams = []) + { + $url = str_replace('/', '/?page=', $this->relativePathFor($name, $data, $queryParams)); + + if ($this->basePath) { + $url = $this->basePath . $url; + } + + return $url; + } +} diff --git a/config.example.yml b/config.example.yml index ca03f0b..7fb80ef 100644 --- a/config.example.yml +++ b/config.example.yml @@ -11,3 +11,4 @@ convert: false avconv: vendor/bin/ffmpeg rtmpdump: vendor/bin/rtmpdump curl: /usr/bin/curl +uglyUrls: false diff --git a/controllers/FrontController.php b/controllers/FrontController.php index d42aebc..c4421fe 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -85,6 +85,7 @@ class FrontController 'index.tpl', [ 'convert' => $this->config->convert, + 'uglyUrls' => $this->config->uglyUrls, 'class' => 'index', 'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.', ] diff --git a/index.php b/index.php index 6db8190..feca012 100644 --- a/index.php +++ b/index.php @@ -2,6 +2,8 @@ require_once __DIR__.'/vendor/autoload.php'; use Alltube\Controller\FrontController; +use Alltube\Config; +use Alltube\UglyRouter; if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) { header('Location: '.str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI'])); @@ -10,6 +12,10 @@ if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.ph $app = new \Slim\App(); $container = $app->getContainer(); +$config = Config::getInstance(); +if ($config->uglyUrls) { + $container['router'] = new UglyRouter(); +} $container['view'] = function ($c) { $view = new \Slim\Views\Smarty(__DIR__.'/templates/'); diff --git a/templates/index.tpl b/templates/index.tpl index 93f44eb..66eb1ab 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -12,6 +12,9 @@ + {if uglyUrls} + + {/if}
{if $convert}
diff --git a/templates/video.tpl b/templates/video.tpl index 6f11251..678ffbd 100644 --- a/templates/video.tpl +++ b/templates/video.tpl @@ -24,6 +24,9 @@

+ {if uglyUrls} + + {/if}