diff --git a/.htaccess b/.htaccess index 8ccd69c..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,7 +23,6 @@ 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 + + AddOutputFilterByType DEFLATE text/css text/html application/javascript font/truetype + diff --git a/FAQ.md b/FAQ.md index 6331183..af5eb54 100644 --- a/FAQ.md +++ b/FAQ.md @@ -12,15 +12,15 @@ You can ususally download the video by doing *File > Save to* or *ctrl + S*. You need to create a YAML file called `config.yml` at the root of your project. Here are the parameters that you can set: -* youtubedl: path to your youtube-dl binary -* python: path to your python binary -* params: an array of parameters to pass to youtube-dl -* curl_params: an array of parameters to pass to curl -* convert: true to enable audio conversion -* avconv: path to your avconv or ffmpeg binary -* rtmpdump: path to your rtmpdump binary +* `youtubedl`: path to your youtube-dl binary +* `python`: path to your python binary +* `params`: an array of parameters to pass to youtube-dl +* `curl_params`: an array of parameters to pass to curl +* `convert`: true to enable audio conversion +* `avconv`: path to your avconv or ffmpeg binary +* `rtmpdump`: path to your rtmpdump binary -See [config.example.yml](config.example.yml) for default values. +See [`config.example.yml`](config.example.yml) for default values. ## How do I enable audio conversion? @@ -71,3 +71,12 @@ You need to either: * Use a [release package](https://github.com/Rudloff/alltube/releases) * Run `npm install` (see detailed instructions in the [README](README.md#from-git)) + +## I get a 404 error on every page except the index + +This is probably because your server does not have mod_rewrite or AllowOverride is disabled. +You can work around this by adding this to your `config.yml` file: + +```yaml +uglyUrls: true +``` diff --git a/classes/Config.php b/classes/Config.php index 5921a61..0482e36 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -80,6 +80,13 @@ class Config */ public $curl_params = []; + /** + * Disable URL rewriting. + * + * @var bool + */ + public $uglyUrls = false; + /** * YAML config file path. * diff --git a/classes/UglyRouter.php b/classes/UglyRouter.php new file mode 100644 index 0000000..c574480 --- /dev/null +++ b/classes/UglyRouter.php @@ -0,0 +1,61 @@ +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 + * + * @throws \RuntimeException If named route does not exist + * @throws \InvalidArgumentException If required data not provided + * + * @return string + */ + 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/composer.json b/composer.json index 02143b6..40034db 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,9 @@ "squizlabs/php_codesniffer": "~2.7.0", "phpunit/phpunit": "~5.7.2", "ffmpeg/ffmpeg": "dev-release", - "rg3/youtube-dl": "~2016.12.22", - "rudloff/rtmpdump-bin": "~2.3" + "rg3/youtube-dl": "~2017.01.14", + "rudloff/rtmpdump-bin": "~2.3", + "heroku/heroku-buildpack-php": "*" }, "extra": { "paas": { @@ -36,10 +37,10 @@ "type": "package", "package": { "name": "rg3/youtube-dl", - "version": "2016.12.22", + "version": "2017.01.14", "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.14.zip" } } }, diff --git a/composer.lock b/composer.lock index 0393884..7bda9cb 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": "73c835f77628ac1e77dee70447711759", + "content-hash": "44b24b403652e1a7e450280e4643e37e", "packages": [ { "name": "aura/session", @@ -811,16 +811,16 @@ }, { "name": "symfony/process", - "version": "v3.2.1", + "version": "v3.2.2", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "02ea84847aad71be7e32056408bb19f3a616cdd3" + "reference": "350e810019fc52dd06ae844b6a6d382f8a0e8893" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/02ea84847aad71be7e32056408bb19f3a616cdd3", - "reference": "02ea84847aad71be7e32056408bb19f3a616cdd3", + "url": "https://api.github.com/repos/symfony/process/zipball/350e810019fc52dd06ae844b6a6d382f8a0e8893", + "reference": "350e810019fc52dd06ae844b6a6d382f8a0e8893", "shasum": "" }, "require": { @@ -856,20 +856,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-11-24T10:40:28+00:00" + "time": "2017-01-02T20:32:22+00:00" }, { "name": "symfony/yaml", - "version": "v3.2.1", + "version": "v3.2.2", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "a7095af4b97a0955f85c8989106c249fa649011f" + "reference": "50eadbd7926e31842893c957eca362b21592a97d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/a7095af4b97a0955f85c8989106c249fa649011f", - "reference": "a7095af4b97a0955f85c8989106c249fa649011f", + "url": "https://api.github.com/repos/symfony/yaml/zipball/50eadbd7926e31842893c957eca362b21592a97d", + "reference": "50eadbd7926e31842893c957eca362b21592a97d", "shasum": "" }, "require": { @@ -911,7 +911,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-12-10T10:07:06+00:00" + "time": "2017-01-03T13:51:32+00:00" } ], "packages-dev": [ @@ -983,6 +983,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", @@ -1621,10 +1665,10 @@ }, { "name": "rg3/youtube-dl", - "version": "2016.12.22", + "version": "2017.01.14", "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.14.zip", "reference": null, "shasum": null }, @@ -2282,16 +2326,16 @@ }, { "name": "symfony/var-dumper", - "version": "v3.2.1", + "version": "v3.2.2", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "f722532b0966e9b6fc631e682143c07b2cf583a0" + "reference": "b54b23f9a19b465e76fdaac0f6732410467c83b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/f722532b0966e9b6fc631e682143c07b2cf583a0", - "reference": "f722532b0966e9b6fc631e682143c07b2cf583a0", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/b54b23f9a19b465e76fdaac0f6732410467c83b2", + "reference": "b54b23f9a19b465e76fdaac0f6732410467c83b2", "shasum": "" }, "require": { @@ -2341,7 +2385,7 @@ "debug", "dump" ], - "time": "2016-12-11T14:34:22+00:00" + "time": "2017-01-03T08:53:57+00:00" }, { "name": "webmozart/assert", 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 4c88bd1..cc71335 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -80,13 +80,16 @@ class FrontController */ public function index(Request $request, Response $response) { + $uri = $request->getUri(); $this->view->render( $response, 'index.tpl', [ - 'convert' => $this->config->convert, - 'class' => 'index', - 'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.', + 'convert' => $this->config->convert, + 'uglyUrls' => $this->config->uglyUrls, + 'class' => 'index', + 'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.', + 'domain' => $uri->getScheme().'://'.$uri->getAuthority(), ] ); } diff --git a/index.php b/index.php index 6db8190..fad0bb0 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,9 @@ 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/package.json b/package.json index 7d9d123..fbb66ee 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.2-beta", "author": "Pierre Rudloff", "bugs": "https://github.com/Rudloff/alltube/issues", "dependencies": { diff --git a/templates/index.tpl b/templates/index.tpl index 93f44eb..d16f6f0 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -12,6 +12,9 @@ + {if uglyUrls} + + {/if} {if $convert} @@ -25,7 +28,7 @@ See all supported websites Drag this to your bookmarks bar: - Bookmarklet + Bookmarklet diff --git a/templates/video.tpl b/templates/video.tpl index 5ff0f96..85a4a25 100644 --- a/templates/video.tpl +++ b/templates/video.tpl @@ -24,6 +24,9 @@ Available formats: + {if uglyUrls} + + {/if} diff --git a/tests/UglyRouterTest.php b/tests/UglyRouterTest.php new file mode 100644 index 0000000..3d211c5 --- /dev/null +++ b/tests/UglyRouterTest.php @@ -0,0 +1,84 @@ +router = new UglyRouter(); + $this->router->map(['GET'], '/foo', 'print')->setName('foo'); + } + + /** + * Test the dispatch() function. + * + * @return void + */ + public function testDispatch() + { + $this->assertEquals( + [1, 'route0', []], + $this->router->dispatch( + new Request( + 'GET', + Uri::createFromString('http://example.com/?page=foo'), + Headers::createFromEnvironment(new Environment()), + [], + [], + new Stream(fopen('php://temp', 'r')) + ) + ) + ); + } + + /** + * Test the pathFor() function. + * + * @return void + */ + public function testPathFor() + { + $this->assertEquals( + '/?page=foo', + $this->router->pathFor('foo', [], []) + ); + } + + /** + * Test the pathFor() function with a base path. + * + * @return void + */ + public function testPathForWithBasePath() + { + $this->router->setBasePath('/bar'); + $this->assertEquals( + '/bar/?page=foo', + $this->router->pathFor('foo', [], []) + ); + } +} diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index 4cd580d..cdec782 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', ], ]; } @@ -246,18 +246,19 @@ 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 * @dataProvider M3uUrlProvider */ - 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); } /** @@ -287,10 +288,10 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase * @dataProvider urlProvider * @dataProvider M3uUrlProvider */ - 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'); } /**
Drag this to your bookmarks bar: