Fixes #5967 -- Hide bitrate for lossless streams.

This commit is contained in:
Buster Neece 2022-12-27 07:59:53 -06:00
parent 0408efb656
commit a6641d5a4f
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
7 changed files with 47 additions and 28 deletions

View File

@ -33,9 +33,8 @@
</template>
<template #cell(enable_autodj)="row">
<template v-if="row.item.enable_autodj">
{{ $gettext('Enabled') }}
-
{{ row.item.autodj_bitrate }}kbps {{ upper(row.item.autodj_format) }}
{{ $gettext('Enabled') }} -
{{ showFormatAndBitrate(row.item.autodj_format, row.item.autodj_bitrate) }}
</template>
<template v-else>
{{ $gettext('Disabled') }}
@ -70,6 +69,7 @@ import {ref} from "vue";
import {useSweetAlert} from "~/vendor/sweetalert";
import {useNotify} from "~/vendor/bootstrapVue";
import {useAxios} from "~/vendor/axios";
import showFormatAndBitrate from "~/functions/showFormatAndBitrate";
const props = defineProps({
...mayNeedRestartProps,
@ -90,14 +90,6 @@ const fields = [
{key: 'actions', label: $gettext('Actions'), sortable: false, class: 'shrink'}
];
const upper = (data) => {
let upper = [];
data.split(' ').forEach((word) => {
upper.push(word.toUpperCase());
});
return upper.join(' ');
};
const datatable = ref(); // DataTable
const relist = () => {

View File

@ -27,9 +27,8 @@
</template>
<template #cell(enable_autodj)="row">
<template v-if="row.item.enable_autodj">
{{ $gettext('Enabled') }} - {{ row.item.autodj_bitrate }}kbps {{
upper(row.item.autodj_format)
}}
{{ $gettext('Enabled') }} -
{{ showFormatAndBitrate(row.item.autodj_format, row.item.autodj_bitrate) }}
</template>
<template v-else>
{{ $gettext('Disabled') }}
@ -64,6 +63,7 @@ import {ref} from "vue";
import {useSweetAlert} from "~/vendor/sweetalert";
import {useNotify} from "~/vendor/bootstrapVue";
import {useAxios} from "~/vendor/axios";
import showFormatAndBitrate from "~/functions/showFormatAndBitrate";
const props = defineProps({
...mayNeedRestartProps,
@ -78,18 +78,6 @@ const fields = [
{key: 'actions', label: $gettext('Actions'), sortable: false, class: 'shrink'}
];
const upper = (data) => {
if (!data) {
return '';
}
let upper = [];
data.split(' ').forEach((word) => {
upper.push(word.toUpperCase());
});
return upper.join(' ');
};
const datatable = ref(); // DataTable
const relist = () => {

View File

@ -0,0 +1,9 @@
import strtoupper from "~/functions/strtoupper";
export default function showFormatAndBitrate(format, bitrate) {
if (format === 'flac') {
return strtoupper(format);
}
return bitrate + 'kbps ' + strtoupper(format);
}

View File

@ -0,0 +1,11 @@
export default function strtoupper(data) {
if (!data) {
return '';
}
let upper = [];
data.split(' ').forEach((word) => {
upper.push(word.toUpperCase());
});
return upper.join(' ');
};

View File

@ -182,7 +182,11 @@ class StationMount implements
}
if ($this->enable_autodj) {
return $this->name . ' (' . $this->autodj_bitrate . 'kbps ' . strtoupper($this->autodj_format ?? '') . ')';
$format = $this->getAutodjFormatEnum();
return (null !== $format)
? $this->name . ' (' . $format->formatBitrate($this->autodj_bitrate) . ')'
: $this->name;
}
return $this->name;

View File

@ -426,7 +426,10 @@ class StationRemote implements
}
if ($this->enable_autodj) {
return $this->autodj_bitrate . 'kbps ' . strtoupper($this->autodj_format ?? '');
$format = $this->getAutodjFormatEnum();
if (null !== $format) {
return $format->formatBitrate($this->autodj_bitrate);
}
}
return Utilities\Strings::truncateUrl($this->url);

View File

@ -23,6 +23,18 @@ enum StreamFormats: string
};
}
public function formatBitrate(?int $bitrate): string
{
if (null === $bitrate) {
return strtoupper($this->value);
}
return match ($this) {
self::Flac => 'FLAC',
default => $bitrate . 'kbps ' . strtoupper($this->value)
};
}
public function sendIcyMetadata(): bool
{
return match ($this) {