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/3.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudloff committed Oct 16, 2022
2 parents 3b6b1f0 + 1031ad1 commit 36a91c8
Show file tree
Hide file tree
Showing 64 changed files with 1,914 additions and 1,244 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Tests
on:
- push
- pull_request
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
php-version:
- '7.3'
- '7.4'
steps:
- uses: actions/checkout@v2
- name: Use PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer
- run: composer install --no-progress
- run: composer check-platform-reqs
- run: composer lint
- run: composer test
3 changes: 0 additions & 3 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ FileETag None
<ifmodule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} ^alltube\.herokuapp\.com$ [NC]
RewriteRule ^(.*)$ https://www.alltubedownload.net/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</ifmodule>
Expand Down
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AllTube Download

HTML GUI for youtube-dl ([alltubedownload.net](http://alltubedownload.net/))
HTML GUI for youtube-dl

![Screenshot](img/screenshot.png "AllTube GUI screenshot")

Expand Down Expand Up @@ -79,6 +79,7 @@ If you want to serve the application under a basepath and/or with a different in
* X-Forwarded-Host (ex. `another.domain.com`)
* X-Forwarded-Path (ex: `/alltube`)
* X-Forwarded-Port (ex: `5555`)
* X-Forwarded-Proto (ex: `https`)

### Apache

Expand Down Expand Up @@ -164,7 +165,7 @@ so that you can reuse it in your projects.
## JSON API

We also provide a JSON API that you can use like this:
[/json?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdQw4w9WgXcQ](https://alltubedownload.net/json?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdQw4w9WgXcQ)
`/json?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdQw4w9WgXcQ`

It returns a JSON object generated by youtube-dl.
You can find a list of all the properties [in the youtube-dl documentation](https://github.com/ytdl-org/youtube-dl#output-template).
Expand Down
4 changes: 1 addition & 3 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "AllTube Download",
"description": "HTML GUI for youtube-dl",
"repository": "https://github.com/Rudloff/alltube.git",
"logo": "https://alltubedownload.net/img/logo.png",
"keywords": [
"alltube",
"download",
Expand All @@ -28,6 +27,5 @@
"value": "false",
"required": false
}
},
"website": "https://alltubedownload.net/"
}
}
4 changes: 2 additions & 2 deletions classes/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct()
// Middlewares.
$this->add(new LocaleMiddleware($container));
$this->add(new CspMiddleware($container));
$this->add(new LinkHeaderMiddleware($container));
$this->add(new LinkHeaderMiddleware());
$this->add(new RouterPathMiddleware($container));

// Controllers.
Expand Down Expand Up @@ -94,7 +94,7 @@ public function __construct()

$this->any(
'/watch',
[$frontController, 'info']
[$frontController, 'watch']
);

$this->any(
Expand Down
14 changes: 7 additions & 7 deletions classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class Config
/**
* Config constructor.
*
* @param mixed[] $options Options
* @param scalar[]|scalar[][]|null[] $options Options
* @throws ConfigException
*/
public function __construct(array $options = [])
Expand Down Expand Up @@ -205,7 +205,7 @@ public static function addHttpToFormat(string $format): string
* @throws ConfigException If Python is missing
* @throws ConfigException If youtube-dl is missing
*/
private function validateOptions()
private function validateOptions(): void
{
if (!is_file($this->youtubedl)) {
throw new ConfigException("Can't find youtube-dl at " . $this->youtubedl);
Expand All @@ -222,11 +222,11 @@ private function validateOptions()
/**
* Apply the provided options.
*
* @param mixed[] $options Options
* @param scalar[]|scalar[][]|null[] $options Options
*
* @return void
*/
private function applyOptions(array $options)
private function applyOptions(array $options): void
{
foreach ($options as $option => $value) {
if (isset($this->$option) && isset($value)) {
Expand All @@ -243,7 +243,7 @@ private function applyOptions(array $options)
* @return void
* @throws ConfigException
*/
private function getEnv()
private function getEnv(): void
{
foreach (get_object_vars($this) as $prop => $value) {
try {
Expand Down Expand Up @@ -278,11 +278,11 @@ public static function fromFile(string $file): Config
/**
* Manually set some options.
*
* @param mixed[] $options Options (see `config/config.example.yml` for available options)
* @param scalar[]|scalar[][]|null[] $options Options (see `config/config.example.yml` for available options)
* @return void
* @throws ConfigException
*/
public function setOptions(array $options)
public function setOptions(array $options): void
{
$this->applyOptions($options);
$this->validateOptions();
Expand Down
4 changes: 1 addition & 3 deletions classes/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ protected function displayError(Request $request, Response $response, string $me
*/
protected function getVideoPageUrl(Request $request): string
{
$url = $request->getQueryParam('url') ?: $request->getQueryParam('v');

// Prevent SSRF attacks.
$parts = Url::validateUrl($url, new Options());
$parts = Url::validateUrl($request->getQueryParam('url'), new Options());

return $parts['url'];
}
Expand Down
5 changes: 2 additions & 3 deletions classes/Controller/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,12 @@ private function getStream(Request $request, Response $response): Response
if ($request->isGet()) {
$response = $response->withBody($body);
}
$response = $response->withHeader(

return $response->withHeader(
'Content-Disposition',
'attachment; filename="' .
$this->video->getFilename() . '"'
);

return $response;
}

/**
Expand Down
69 changes: 68 additions & 1 deletion classes/Controller/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Exception;
use Graby\HttpClient\Plugin\ServerSideRequestForgeryProtection\Exception\InvalidURLException;
use Slim\Http\StatusCode;
use Slim\Http\Uri;
use stdClass;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Throwable;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -146,7 +148,7 @@ public function password(Request $request, Response $response): Response
* @return Response HTTP response
* @throws AlltubeLibraryException
*/
private function getInfoResponse(Request $request, Response $response)
private function getInfoResponse(Request $request, Response $response): Response
{
try {
$this->video->getJson();
Expand Down Expand Up @@ -176,6 +178,50 @@ private function getInfoResponse(Request $request, Response $response)
]
);
}

$formats = [];
$genericFormatsLabel = $this->localeManager->t('Generic formats');
$detailedFormatsLabel = $this->localeManager->t('Detailed formats');

foreach ($this->config->genericFormats as $id => $genericFormat) {
$formats[$genericFormatsLabel][$id] = $this->localeManager->t($genericFormat);
}

$json = $this->video->getJson();
if (isset($json->formats)) {
/** @var stdClass $format */
foreach ($json->formats as $format) {
if ($this->config->stream || in_array($format->protocol, ['http', 'https'])) {
$formatParts = [
// File extension
$format->ext,
];

if (isset($format->width) || isset($format->height)) {
// Video dimensions
$formatParts[] = implode('x', array_filter([$format->width, $format->height]));
}

if (isset($format->filesize)) {
// File size
$formatParts[] = round($format->filesize / 1000000, 2) . ' MB';
}

if (isset($format->format_note)) {
// Format name
$formatParts[] = $format->format_note;
}

if (isset($format->format_id)) {
// Format ID
$formatParts[] = '(' . $format->format_id . ')';
}

$formats[$detailedFormatsLabel][$format->format_id] = implode(' ', $formatParts);
}
}
}

$this->view->render(
$response,
$template,
Expand All @@ -185,6 +231,7 @@ private function getInfoResponse(Request $request, Response $response)
'title' => $title,
'description' => $description,
'defaultFormat' => $this->defaultFormat,
'formats' => $formats
]
);

Expand Down Expand Up @@ -302,4 +349,24 @@ public function error(Request $request, Response $response, Throwable $error): R
return $this->displayError($request, $response, $message);
}
}

/**
* Route that mimics YouTube video URLs ("/watch?v=foo")
*
* @param Request $request
* @param Response $response
* @return Response
*/
public function watch(Request $request, Response $response): Response
{
// We build a full YouTube URL from the video ID.
$youtubeUri = Uri::createFromString('https://www.youtube.com/watch')
->withQuery(http_build_query(['v' => $request->getQueryParam('v')]));

// Then pass it to the info route.
return $response->withRedirect(
Uri::createFromString($this->router->pathFor('info'))
->withQuery(http_build_query(['url' => strval($youtubeUri)]))
);
}
}
2 changes: 1 addition & 1 deletion classes/Controller/JsonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace Alltube\Controller;

use Alltube\Library\Exception\AlltubeLibraryException;
use Exception;
use Graby\HttpClient\Plugin\ServerSideRequestForgeryProtection\Exception\InvalidURLException;
use Slim\Http\Request;
use Slim\Http\Response;
Expand All @@ -25,6 +24,7 @@ class JsonController extends BaseController
* @param Response $response PSR-7 response
*
* @return Response HTTP response
* @throws AlltubeLibraryException
*/
public function json(Request $request, Response $response): Response
{
Expand Down
5 changes: 3 additions & 2 deletions classes/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Alltube;

use Slim\Http\StatusCode;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Throwable;

Expand All @@ -17,7 +18,7 @@ class ErrorHandler
* @param Throwable $e
* @return void
*/
public static function handle(Throwable $e)
public static function handle(Throwable $e): void
{
error_log($e);

Expand All @@ -29,7 +30,7 @@ public static function handle(Throwable $e)
http_response_code($exception->getStatusCode());
die($exception->getAsString());
} else {
http_response_code(500);
http_response_code(StatusCode::HTTP_INTERNAL_SERVER_ERROR);
die('Error when starting the app: ' . htmlentities($e->getMessage()));
}
}
Expand Down
3 changes: 2 additions & 1 deletion classes/Factory/LocaleManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Alltube\Exception\DependencyException;
use Alltube\LocaleManager;
use Locale;
use Slim\Container;

/**
Expand All @@ -20,7 +21,7 @@ class LocaleManagerFactory
*/
public static function create(Container $container): LocaleManager
{
if (!class_exists('Locale')) {
if (!class_exists(Locale::class)) {
throw new DependencyException('You need to install the intl extension for PHP.');
}

Expand Down
5 changes: 3 additions & 2 deletions classes/Factory/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Consolidation\Log\LogOutputStyler;
use Slim\Container;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class LoggerFactory
Expand All @@ -23,9 +24,9 @@ public static function create(Container $container): LoggerManager
{
$config = $container->get('config');
if ($config->debug) {
$verbosity = ConsoleOutput::VERBOSITY_DEBUG;
$verbosity = OutputInterface::VERBOSITY_DEBUG;
} else {
$verbosity = ConsoleOutput::VERBOSITY_NORMAL;
$verbosity = OutputInterface::VERBOSITY_NORMAL;
}

$loggerManager = new LoggerManager();
Expand Down
3 changes: 2 additions & 1 deletion classes/Factory/SessionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Alltube\Factory;

use Aura\Session\Session;
use Aura\Session\SessionFactory as AuraSessionFactory;
use Slim\Container;

/**
Expand All @@ -23,7 +24,7 @@ class SessionFactory
*/
public static function create(Container $container): Session
{
$session_factory = new \Aura\Session\SessionFactory();
$session_factory = new AuraSessionFactory();
$session = $session_factory->newInstance($_COOKIE);

$session->setCookieParams(['httponly' => true]);
Expand Down
Loading

0 comments on commit 36a91c8

Please sign in to comment.