Simplify overly complicated format selection template
This commit is contained in:
parent
d9ba01f017
commit
27439c7e14
2 changed files with 52 additions and 56 deletions
|
@ -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
|
||||
]
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue