Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release-0.7.2-beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudloff committed Jan 10, 2017
2 parents b3fe973 + 3a1d0c4 commit c8e8cac
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 16 deletions.
13 changes: 7 additions & 6 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
AddType application/x-web-app-manifest+json .webapp
Addtype font/truetype .ttf
<ifmodule mod_expires.c>
AddType application/x-web-app-manifest+json .webapp
Addtype font/truetype .ttf
</ifmodule>

<ifmodule mod_expires.c>
ExpiresActive On
Expand All @@ -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
<ifmodule mod_filter.c>
AddOutputFilterByType DEFLATE text/css text/html application/javascript font/truetype
</ifmodule>
7 changes: 7 additions & 0 deletions classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class Config
*/
public $curl_params = [];

/**
* Disable URL rewriting.
*
* @var bool
*/
public $uglyUrls = false;

/**
* YAML config file path.
*
Expand Down
61 changes: 61 additions & 0 deletions classes/UglyRouter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* UglyRouter class.
*/

namespace Alltube;

use Psr\Http\Message\ServerRequestInterface;
use Slim\Router;

/**
* Extend Slim's router class in order to disable URL rewriting.
*/
class UglyRouter extends Router
{
/**
* Dispatch router for HTTP request.
*
* @param ServerRequestInterface $request The current HTTP request object
*
* @return array
*
* @link https://github.com/nikic/FastRoute/blob/master/src/Dispatcher.php
*/
public function dispatch(ServerRequestInterface $request)
{
parse_str($request->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;
}
}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
},
Expand All @@ -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"
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ convert: false
avconv: vendor/bin/ffmpeg
rtmpdump: vendor/bin/rtmpdump
curl: /usr/bin/curl
uglyUrls: false
7 changes: 4 additions & 3 deletions controllers/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ public function index(Request $request, Response $response)
$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.',
]
);
}
Expand Down
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

require_once __DIR__.'/vendor/autoload.php';
use Alltube\Config;
use Alltube\Controller\FrontController;
use Alltube\UglyRouter;

if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
header('Location: '.str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI']));
Expand All @@ -10,6 +12,10 @@

$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/');

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alltube",
"description": "HTML GUI for youtube-dl",
"version": "0.7.1",
"version": "0.7.2-beta",
"author": "Pierre Rudloff",
"bugs": "https://github.com/Rudloff/alltube/issues",
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions templates/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<input class="URLinput" type="url" name="url" id="url"
required autofocus placeholder="http://example.com/video" />
</span>
{if uglyUrls}
<input type="hidden" name="page" value="video" />
{/if}
<input class="downloadBtn" type="submit" value="Download" /><br/>
{if $convert}
<div class="mp3">
Expand Down
3 changes: 3 additions & 0 deletions templates/video.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<h3><label for="format">Available formats:</label></h3>
<form action="{path_for name="redirect"}">
<input type="hidden" name="url" value="{$video->webpage_url}" />
{if uglyUrls}
<input type="hidden" name="page" value="redirect" />
{/if}
<select name="format" id="format" class="formats monospace">
<optgroup label="Generic formats">
<option value="best[protocol^=http]">
Expand Down
84 changes: 84 additions & 0 deletions tests/UglyRouterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* UglyRouterTest class.
*/

namespace Alltube\Test;

use Alltube\UglyRouter;
use Slim\Http\Environment;
use Slim\Http\Headers;
use Slim\Http\Request;
use Slim\Http\Stream;
use Slim\Http\Uri;

/**
* Unit tests for the UglyRouter class.
*/
class UglyRouterTest extends \PHPUnit_Framework_TestCase
{
/**
* UglyRouter instance.
*
* @var UglyRouter
*/
private $router;

/**
* Prepare tests.
*/
protected function setUp()
{
$this->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', [], [])
);
}
}

0 comments on commit c8e8cac

Please sign in to comment.