From 912aa99054d0936e4adff8343f952cd17141ea4e Mon Sep 17 00:00:00 2001 From: genuineparts Date: Thu, 1 May 2025 12:38:49 +0200 Subject: [PATCH] Merged some fixes from private.coffee --- classes/Controller/DownloadController.php | 21 ++++++++++++++++----- classes/Middleware/CspMiddleware.php | 1 + templates/info.tpl | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/classes/Controller/DownloadController.php b/classes/Controller/DownloadController.php index dece054..35400e5 100644 --- a/classes/Controller/DownloadController.php +++ b/classes/Controller/DownloadController.php @@ -44,7 +44,13 @@ class DownloadController extends BaseController { $url = $this->getVideoPageUrl($request); - $this->video = $this->downloader->getVideo($url, $this->getFormat($request), $this->getPassword($request)); + $format = $this->getFormat($request); + + if ($this->config->remux && $request->getQueryParam('remux')) { + $this->video = $this->downloader->getVideo($url, $format . "+bestaudio", $this->getPassword($request)); + } else { + $this->video = $this->downloader->getVideo($url, $format, $this->getPassword($request)); + } try { if ($this->config->convert && $request->getQueryParam('audio')) { @@ -106,6 +112,8 @@ class DownloadController extends BaseController $to = $request->getQueryParam('to'); } + assert((is_string($from) || is_null($from)) && (is_string($to) || is_null($to))); + $response = $response->withHeader( 'Content-Disposition', 'attachment; filename="' . @@ -270,12 +278,12 @@ class DownloadController extends BaseController $videoUrls = $this->video->getUrl(); } catch (EmptyUrlException $e) { /* - If this happens it is probably a playlist - so it will either be handled by getStream() or throw an exception anyway. + * If this happens it is probably a playlist + * so it will either be handled by getStream() or throw an exception anyway. */ $videoUrls = []; } - if (count($videoUrls) > 1) { + if (count($videoUrls) > 1 && !isset($this->video->entries)) { return $this->getRemuxStream($request, $response); } elseif ($this->config->stream && (isset($this->video->entries) || $request->getQueryParam('stream'))) { return $this->getStream($request, $response); @@ -305,6 +313,9 @@ class DownloadController extends BaseController */ private function getConvertedResponse(Request $request, Response $response): Response { + assert(is_string($request->getQueryParam('customFormat'))); + assert(is_int($request->getQueryParam('customBitrate'))); + $response = $response->withHeader( 'Content-Disposition', 'attachment; filename="' . @@ -316,7 +327,7 @@ class DownloadController extends BaseController $process = $this->downloader->getConvertedStream( $this->video, $request->getQueryParam('customBitrate'), - $request->getQueryParam('customFormat') + $request->getQueryParam('customFormat') ); $response = $response->withBody(new Stream($process)); } diff --git a/classes/Middleware/CspMiddleware.php b/classes/Middleware/CspMiddleware.php index 3fa21cd..8934e85 100644 --- a/classes/Middleware/CspMiddleware.php +++ b/classes/Middleware/CspMiddleware.php @@ -41,6 +41,7 @@ class CspMiddleware ->addDirective('font-src', ['self' => true]) ->addDirective('style-src', ['self' => true]) ->addDirective('manifest-src', ['self' => true]) + ->addDirective('img-src', ['self' => true]) ->addDirective('base-uri', []) ->addDirective('frame-ancestors', []) ->addSource('form-action', '*') diff --git a/templates/info.tpl b/templates/info.tpl index d315588..18febfc 100644 --- a/templates/info.tpl +++ b/templates/info.tpl @@ -32,6 +32,10 @@ {html_options name='format' options=$formats selected=$defaultFormat id="format" class="formats monospace"}

+ + +
+
{/if} {if $config->stream} stream !== 'ask'}checked{/if} name="stream" id="stream"/>