diff --git a/classes/Controller/FrontController.php b/classes/Controller/FrontController.php index 0bb6110..21cd8a9 100644 --- a/classes/Controller/FrontController.php +++ b/classes/Controller/FrontController.php @@ -13,6 +13,7 @@ use Alltube\Locale; use Alltube\Middleware\CspMiddleware; use Exception; use Slim\Http\StatusCode; +use stdClass; use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer; use Throwable; use Psr\Container\ContainerInterface; @@ -175,6 +176,47 @@ class FrontController extends BaseController ] ); } + + $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); + } + + /** @var stdClass $format */ + foreach ($this->video->getJson()->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, @@ -184,6 +226,7 @@ class FrontController extends BaseController 'title' => $title, 'description' => $description, 'defaultFormat' => $this->defaultFormat, + 'formats' => $formats ] ); diff --git a/templates/info.tpl b/templates/info.tpl index 51474eb..d315588 100644 --- a/templates/info.tpl +++ b/templates/info.tpl @@ -23,57 +23,13 @@ {/if} {if isset($video->formats) && count($video->formats) > 1}

- + {* + To make the default generic formats translatable: + {t}Best{/t} + {t}Remux best video with best audio{/t} + {t}Worst{/t} + *} + {html_options name='format' options=$formats selected=$defaultFormat id="format" class="formats monospace"}

{/if} @@ -86,11 +42,8 @@ {if $config->convertAdvanced} - + {html_options name='customFormat' values=$config->convertAdvancedFormats output=$config->convertAdvancedFormats + title="{t}Custom format{/t}" name="customFormat" aria-label="{t}Format to convert to{/t}"} {t}with{/t}