This commit is contained in:
genuineparts 2025-05-01 13:04:14 +02:00
parent 912aa99054
commit 22437918d9
4 changed files with 44 additions and 10 deletions

View file

@ -24,7 +24,7 @@ class Config
* *
* @var string * @var string
*/ */
public string $youtubedl = 'vendor/yt-dlp/yt-dlp/yt_dlp/__main__.py'; public string $youtubedl = '/usr/bin/yt-dlp';
/** /**
* python binary path. * python binary path.
@ -276,7 +276,9 @@ class Config
public static function fromFile(string $file): Config public static function fromFile(string $file): Config
{ {
if (is_file($file)) { if (is_file($file)) {
return new self(Yaml::parse(strval(file_get_contents($file)))); $yaml = Yaml::parse(strval(file_get_contents($file)));
assert(is_array($yaml));
return new self($yaml);
} else { } else {
throw new ConfigException("Can't find config file at " . $file); throw new ConfigException("Can't find config file at " . $file);
} }

View file

@ -278,8 +278,8 @@ class DownloadController extends BaseController
$videoUrls = $this->video->getUrl(); $videoUrls = $this->video->getUrl();
} catch (EmptyUrlException $e) { } catch (EmptyUrlException $e) {
/* /*
* If this happens it is probably a playlist If this happens it is probably a playlist
* so it will either be handled by getStream() or throw an exception anyway. so it will either be handled by getStream() or throw an exception anyway.
*/ */
$videoUrls = []; $videoUrls = [];
} }
@ -327,7 +327,7 @@ class DownloadController extends BaseController
$process = $this->downloader->getConvertedStream( $process = $this->downloader->getConvertedStream(
$this->video, $this->video,
$request->getQueryParam('customBitrate'), $request->getQueryParam('customBitrate'),
$request->getQueryParam('customFormat') $request->getQueryParam('customFormat')
); );
$response = $response->withBody(new Stream($process)); $response = $response->withBody(new Stream($process));
} }

View file

@ -13,6 +13,7 @@ use Alltube\Locale;
use Alltube\Middleware\CspMiddleware; use Alltube\Middleware\CspMiddleware;
use Exception; use Exception;
use Graby\HttpClient\Plugin\ServerSideRequestForgeryProtection\Exception\InvalidURLException; use Graby\HttpClient\Plugin\ServerSideRequestForgeryProtection\Exception\InvalidURLException;
use GrumPHP\Util\Str;
use Slim\Http\StatusCode; use Slim\Http\StatusCode;
use Slim\Http\Uri; use Slim\Http\Uri;
use stdClass; use stdClass;
@ -44,7 +45,12 @@ class FrontController extends BaseController
{ {
parent::__construct($container); parent::__construct($container);
$this->view = $this->container->get('view'); $view = $this->container->get('view');
assert($view instanceof Smarty);
$this->view = $view;
// Plugins
$this->view->registerPlugin('modifier', 'filter_var', 'filter_var');
} }
/** /**
@ -222,6 +228,28 @@ class FrontController extends BaseController
} }
} }
/* Fetch the thumbnail, if it exists, and add a data URI to the video object */
if (isset($this->video->thumbnail) && $this->video->thumbnail !== '') {
/* Fetch the thumbnail */
$thumbnailData = file_get_contents($this->video->thumbnail);
if ($thumbnailData !== false) {
$thumbnailData = base64_encode($thumbnailData);
/* Guess the mime type */
$thumbnailMime = 'image/jpeg';
if (strpos($this->video->thumbnail, '.png') !== false) {
$thumbnailMime = 'image/png';
} elseif (strpos($this->video->thumbnail, '.gif') !== false) {
$thumbnailMime = 'image/gif';
} elseif (strpos($this->video->thumbnail, '.webp') !== false) {
$thumbnailMime = 'image/webp';
}
$this->video->thumbnail = 'data:' . $thumbnailMime . ';base64,' . $thumbnailData;
}
}
$this->view->render( $this->view->render(
$response, $response,
$template, $template,
@ -330,7 +358,11 @@ class FrontController extends BaseController
$response = $cspMiddleware->applyHeader($response); $response = $cspMiddleware->applyHeader($response);
if ($this->config->debug) { if ($this->config->debug) {
$renderer = new HtmlErrorRenderer(true, null, null, $this->container->get('root_path')); $projectDir = $this->container->get('root_path');
assert(is_string($projectDir) || is_null($projectDir));
$renderer = new HtmlErrorRenderer(true, null, null, $projectDir);
$exception = $renderer->render($error); $exception = $renderer->render($error);
$response->getBody()->write($exception->getAsString()); $response->getBody()->write($exception->getAsString());

View file

@ -45,13 +45,13 @@ class CspMiddleware
->addDirective('base-uri', []) ->addDirective('base-uri', [])
->addDirective('frame-ancestors', []) ->addDirective('frame-ancestors', [])
->addSource('form-action', '*') ->addSource('form-action', '*')
->addSource('img-src', '*'); ->addSource('img-src', '*')
->addSource('img-src', 'data:');
if ($this->config->debug) { if ($this->config->debug) {
// So maximebf/debugbar, symfony/debug and symfony/error-handler can work. // So maximebf/debugbar, symfony/debug and symfony/error-handler can work.
$csp->setDirective('script-src', ['self' => true, 'unsafe-inline' => true]) $csp->setDirective('script-src', ['self' => true, 'unsafe-inline' => true])
->setDirective('style-src', ['self' => true, 'unsafe-inline' => true]) ->setDirective('style-src', ['self' => true, 'unsafe-inline' => true]);
->addSource('img-src', 'data:');
} }
return $csp->injectCSPHeader($response); return $csp->injectCSPHeader($response);