feat(Media player widget): expands on Direct Play and Transcoding badges (#6489)
This commit is contained in:
1 parent
27ca058088
commit
49314533bf
6 files changed
+126
-21
No files matched your search
@@ -41,7 +41,11 @@ export interface StreamSession {
|
|||||||
audioCodec: string | null;
|
audioCodec: string | null;
|
||||||
videoCodec: string | null;
|
videoCodec: string | null;
|
||||||
};
|
};
|
||||||
|
isVideoDirect: boolean;
|
||||||
|
isAudioDirect: boolean;
|
||||||
|
containerChanged: boolean;
|
||||||
};
|
};
|
||||||
|
bitrateKbps: number | null;
|
||||||
} | null;
|
} | null;
|
||||||
} | null;
|
} | null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ export class JellyfinIntegration extends Integration implements IMediaServerInte
|
|||||||
if (sessionInfo.NowPlayingItem) {
|
if (sessionInfo.NowPlayingItem) {
|
||||||
const positionMs = ticksToMs(sessionInfo.PlayState?.PositionTicks);
|
const positionMs = ticksToMs(sessionInfo.PlayState?.PositionTicks);
|
||||||
const durationMs = ticksToMs(sessionInfo.NowPlayingItem.RunTimeTicks);
|
const durationMs = ticksToMs(sessionInfo.NowPlayingItem.RunTimeTicks);
|
||||||
|
const bitrateBps =
|
||||||
|
sessionInfo.TranscodingInfo?.Bitrate ?? sessionInfo.NowPlayingItem.MediaSources?.[0]?.Bitrate ?? null;
|
||||||
|
const bitrateKbps = bitrateBps !== null ? Math.round(bitrateBps / 1000) : null;
|
||||||
|
|
||||||
currentlyPlaying = {
|
currentlyPlaying = {
|
||||||
type: convertJellyfinType(sessionInfo.NowPlayingItem.Type),
|
type: convertJellyfinType(sessionInfo.NowPlayingItem.Type),
|
||||||
@@ -98,7 +101,11 @@ export class JellyfinIntegration extends Integration implements IMediaServerInte
|
|||||||
videoCodec: sessionInfo.TranscodingInfo?.VideoCodec ?? null,
|
videoCodec: sessionInfo.TranscodingInfo?.VideoCodec ?? null,
|
||||||
},
|
},
|
||||||
container: sessionInfo.TranscodingInfo?.Container ?? null,
|
container: sessionInfo.TranscodingInfo?.Container ?? null,
|
||||||
|
isVideoDirect: sessionInfo.TranscodingInfo?.IsVideoDirect ?? true,
|
||||||
|
isAudioDirect: sessionInfo.TranscodingInfo?.IsAudioDirect ?? true,
|
||||||
|
containerChanged: sessionInfo.PlayState?.PlayMethod === "DirectStream",
|
||||||
},
|
},
|
||||||
|
bitrateKbps,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ function parseResolution(
|
|||||||
return parsedWidth !== null && parsedHeight !== null ? { width: parsedWidth, height: parsedHeight } : null;
|
return parsedWidth !== null && parsedHeight !== null ? { width: parsedWidth, height: parsedHeight } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isStreamDirect(decision: string | undefined): boolean {
|
||||||
|
// Plex reports "transcode" when a stream is re-encoded. "copy" (remuxed
|
||||||
|
// without re-encoding) and an absent decision both count as direct.
|
||||||
|
return decision !== "transcode";
|
||||||
|
}
|
||||||
|
|
||||||
export class PlexIntegration extends Integration implements IMediaServerIntegration, IMediaReleasesIntegration {
|
export class PlexIntegration extends Integration implements IMediaServerIntegration, IMediaReleasesIntegration {
|
||||||
public async getCurrentSessionsAsync(_options: CurrentSessionsInput): Promise<StreamSession[]> {
|
public async getCurrentSessionsAsync(_options: CurrentSessionsInput): Promise<StreamSession[]> {
|
||||||
const token = super.getSecretValue("apiKey");
|
const token = super.getSecretValue("apiKey");
|
||||||
@@ -87,6 +93,16 @@ export class PlexIntegration extends Integration implements IMediaServerIntegrat
|
|||||||
const videoStream = streams.find((stream) => stream.$.streamType === "1");
|
const videoStream = streams.find((stream) => stream.$.streamType === "1");
|
||||||
const audioStream = streams.find((stream) => stream.$.streamType === "2");
|
const audioStream = streams.find((stream) => stream.$.streamType === "2");
|
||||||
|
|
||||||
|
const isVideoDirect = isStreamDirect(transcodeElement?.$.videoDecision);
|
||||||
|
const isAudioDirect = isStreamDirect(transcodeElement?.$.audioDecision);
|
||||||
|
const containerChanged = Boolean(
|
||||||
|
transcodeElement?.$.container &&
|
||||||
|
mediaInfoElement?.$.container &&
|
||||||
|
transcodeElement.$.container !== mediaInfoElement.$.container,
|
||||||
|
);
|
||||||
|
const bitrateKbps =
|
||||||
|
parseOptionalNumber(sessionElement?.$.bandwidth) ?? parseOptionalNumber(mediaInfoElement?.$.bitrate);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sessionId: sessionElement?.$.id ?? "unknown",
|
sessionId: sessionElement?.$.id ?? "unknown",
|
||||||
sessionName: `${playerElement.$.product} (${playerElement.$.title})`,
|
sessionName: `${playerElement.$.product} (${playerElement.$.title})`,
|
||||||
@@ -124,7 +140,11 @@ export class PlexIntegration extends Integration implements IMediaServerIntegrat
|
|||||||
audioCodec: transcodeElement?.$.audioCodec ?? null,
|
audioCodec: transcodeElement?.$.audioCodec ?? null,
|
||||||
videoCodec: transcodeElement?.$.videoCodec ?? null,
|
videoCodec: transcodeElement?.$.videoCodec ?? null,
|
||||||
},
|
},
|
||||||
|
isVideoDirect,
|
||||||
|
isAudioDirect,
|
||||||
|
containerChanged,
|
||||||
},
|
},
|
||||||
|
bitrateKbps,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2736,8 +2736,20 @@
|
|||||||
"showOnlyPlaying": {
|
"showOnlyPlaying": {
|
||||||
"label": "Show only currently playing",
|
"label": "Show only currently playing",
|
||||||
"description": "Disabling this will not work for plex"
|
"description": "Disabling this will not work for plex"
|
||||||
|
},
|
||||||
|
"showBitrate": {
|
||||||
|
"label": "Show bitrate",
|
||||||
|
"description": "Show the current playback bitrate next to the location"
|
||||||
|
},
|
||||||
|
"showLocation": {
|
||||||
|
"label": "Show location",
|
||||||
|
"description": "Show whether the stream is on your LAN or WAN"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"footer": {
|
||||||
|
"streams": "{count, plural, one {# active stream} other {# active streams}}",
|
||||||
|
"totalBitrate": "Total: {bitrate}"
|
||||||
|
},
|
||||||
"items": {
|
"items": {
|
||||||
"currentlyPlaying": "Currently playing",
|
"currentlyPlaying": "Currently playing",
|
||||||
"user": "User",
|
"user": "User",
|
||||||
@@ -2745,6 +2757,9 @@
|
|||||||
"id": "Id",
|
"id": "Id",
|
||||||
"status": "Status",
|
"status": "Status",
|
||||||
"directPlay": "Direct play",
|
"directPlay": "Direct play",
|
||||||
|
"directStream": "Direct stream",
|
||||||
|
"transcodeVideo": "Transcoding video",
|
||||||
|
"transcodeAudio": "Transcoding audio",
|
||||||
"transcoding": "Transcoding",
|
"transcoding": "Transcoding",
|
||||||
"paused": "Paused",
|
"paused": "Paused",
|
||||||
"remaining": "{minutes} min left",
|
"remaining": "{minutes} min left",
|
||||||
|
|||||||
@@ -26,6 +26,35 @@ import { useTranslatedMantineReactTable } from "@homarr/ui/hooks";
|
|||||||
|
|
||||||
import type { WidgetComponentProps } from "../definition";
|
import type { WidgetComponentProps } from "../definition";
|
||||||
|
|
||||||
|
type TranscodingDecision = NonNullable<
|
||||||
|
NonNullable<StreamSession["currentlyPlaying"]>["metadata"]
|
||||||
|
>["transcoding"];
|
||||||
|
|
||||||
|
type PlaybackStatus = "directPlay" | "directStream" | "transcodeVideo" | "transcodeAudio" | "transcoding";
|
||||||
|
|
||||||
|
function getPlaybackStatus(transcoding: TranscodingDecision | undefined): PlaybackStatus {
|
||||||
|
if (!transcoding) return "directPlay";
|
||||||
|
const { isVideoDirect, isAudioDirect, containerChanged } = transcoding;
|
||||||
|
|
||||||
|
if (isVideoDirect && isAudioDirect) return containerChanged ? "directStream" : "directPlay";
|
||||||
|
if (!isVideoDirect && isAudioDirect) return "transcodeVideo";
|
||||||
|
if (isVideoDirect && !isAudioDirect) return "transcodeAudio";
|
||||||
|
return "transcoding";
|
||||||
|
}
|
||||||
|
|
||||||
|
const playbackStatusColorMap = {
|
||||||
|
directPlay: "green",
|
||||||
|
directStream: "teal",
|
||||||
|
transcodeVideo: "orange",
|
||||||
|
transcodeAudio: "yellow",
|
||||||
|
transcoding: "red",
|
||||||
|
} satisfies Record<PlaybackStatus, string>;
|
||||||
|
|
||||||
|
function formatBitrate(bitrateKbps: number | null | undefined): string | null {
|
||||||
|
if (!bitrateKbps || bitrateKbps <= 0) return null;
|
||||||
|
return bitrateKbps >= 1000 ? `${(bitrateKbps / 1000).toFixed(1)} Mbps` : `${Math.round(bitrateKbps)} kbps`;
|
||||||
|
}
|
||||||
|
|
||||||
export default function MediaServerWidget({ options, integrationIds }: WidgetComponentProps<"mediaServer">) {
|
export default function MediaServerWidget({ options, integrationIds }: WidgetComponentProps<"mediaServer">) {
|
||||||
const { data: currentStreams = [] } = clientApi.widget.mediaServer.getCurrentStreams.useQuery({
|
const { data: currentStreams = [] } = clientApi.widget.mediaServer.getCurrentStreams.useQuery({
|
||||||
integrationIds,
|
integrationIds,
|
||||||
@@ -122,23 +151,30 @@ export default function MediaServerWidget({ options, integrationIds }: WidgetCom
|
|||||||
const currentlyPlaying = row.original.currentlyPlaying;
|
const currentlyPlaying = row.original.currentlyPlaying;
|
||||||
if (!currentlyPlaying) return null;
|
if (!currentlyPlaying) return null;
|
||||||
|
|
||||||
const isTranscoding = Boolean(
|
const status = getPlaybackStatus(currentlyPlaying.metadata?.transcoding);
|
||||||
currentlyPlaying.metadata?.transcoding.target.videoCodec ??
|
const bitrateLabel = formatBitrate(currentlyPlaying.metadata?.bitrateKbps);
|
||||||
currentlyPlaying.metadata?.transcoding.target.audioCodec ??
|
|
||||||
currentlyPlaying.metadata?.transcoding.container,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={4} align="flex-start">
|
<Stack gap={4} align="flex-start">
|
||||||
<Badge size="xs" variant="light" color={isTranscoding ? "orange" : "green"}>
|
<Badge size="xs" variant="light" color={playbackStatusColorMap[status]}>
|
||||||
{isTranscoding ? t("items.transcoding") : t("items.directPlay")}
|
{t(`items.${status}` as never)}
|
||||||
</Badge>
|
</Badge>
|
||||||
{currentlyPlaying.location && (
|
{(currentlyPlaying.location ?? bitrateLabel) && (
|
||||||
<Group gap={4} align="center">
|
<Group gap={4} align="center" justify="space-between" wrap="nowrap" w="100%">
|
||||||
{currentlyPlaying.location === "lan" ? <IconWifi size={12} /> : <IconWorld size={12} />}
|
<Group gap={4} align="center">
|
||||||
<Text size="10px" c="dimmed" tt="uppercase">
|
{currentlyPlaying.location &&
|
||||||
{currentlyPlaying.location}
|
(currentlyPlaying.location === "lan" ? <IconWifi size={12} /> : <IconWorld size={12} />)}
|
||||||
</Text>
|
{currentlyPlaying.location && (
|
||||||
|
<Text size="10px" c="dimmed" tt="uppercase">
|
||||||
|
{currentlyPlaying.location}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
{bitrateLabel && (
|
||||||
|
<Text size="10px" c="dimmed">
|
||||||
|
{bitrateLabel}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -238,6 +274,12 @@ export default function MediaServerWidget({ options, integrationIds }: WidgetCom
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const totalBitrateKbps = flatSessions.reduce(
|
||||||
|
(sum, session) => sum + (session.currentlyPlaying?.metadata?.bitrateKbps ?? 0),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
const totalBitrateLabel = options.showBitrate ? formatBitrate(totalBitrateKbps) : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={0} h="100%" display="flex">
|
<Stack gap={0} h="100%" display="flex">
|
||||||
<MantineReactTable table={table} />
|
<MantineReactTable table={table} />
|
||||||
@@ -246,19 +288,34 @@ export default function MediaServerWidget({ options, integrationIds }: WidgetCom
|
|||||||
h={30}
|
h={30}
|
||||||
px="xs"
|
px="xs"
|
||||||
pr="md"
|
pr="md"
|
||||||
justify="flex-end"
|
justify="space-between"
|
||||||
style={{
|
style={{
|
||||||
borderTop: "1px solid var(--border-color)",
|
borderTop: "1px solid var(--border-color)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{uniqueIntegrations.map((integration) => (
|
<Group gap={4} wrap="nowrap">
|
||||||
<Group key={integration.integrationKind} gap="xs" align="center">
|
<IconVideo size={16} style={{ flexShrink: 0 }} />
|
||||||
<Avatar className="media-server-icon" src={integration.integrationIcon} radius={"xs"} size="xs" />
|
<Text size="sm" style={{ whiteSpace: "nowrap" }}>
|
||||||
<Text className="media-server-name" size="sm">
|
{(t as unknown as (key: string, params?: { count: number }) => string)("footer.streams", {
|
||||||
{integration.integrationName}
|
count: flatSessions.length,
|
||||||
|
})}
|
||||||
|
</Text>
|
||||||
|
{totalBitrateLabel && (
|
||||||
|
<Text size="sm" c="dimmed" style={{ whiteSpace: "nowrap" }}>
|
||||||
|
{t("footer.totalBitrate", { bitrate: totalBitrateLabel })}
|
||||||
</Text>
|
</Text>
|
||||||
</Group>
|
)}
|
||||||
))}
|
</Group>
|
||||||
|
<Group gap="xs">
|
||||||
|
{uniqueIntegrations.map((integration) => (
|
||||||
|
<Group key={integration.integrationKind} gap="xs" align="center">
|
||||||
|
<Avatar className="media-server-icon" src={integration.integrationIcon} radius={"xs"} size="xs" />
|
||||||
|
<Text className="media-server-name" size="sm">
|
||||||
|
{integration.integrationName}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
))}
|
||||||
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ export const { componentLoader, definition } = createWidgetDefinition("mediaServ
|
|||||||
createOptions() {
|
createOptions() {
|
||||||
return optionsBuilder.from((factory) => ({
|
return optionsBuilder.from((factory) => ({
|
||||||
showOnlyPlaying: factory.switch({ defaultValue: true, withDescription: true }),
|
showOnlyPlaying: factory.switch({ defaultValue: true, withDescription: true }),
|
||||||
|
showBitrate: factory.switch({ defaultValue: true, withDescription: true }),
|
||||||
|
showLocation: factory.switch({ defaultValue: true, withDescription: true }),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
supportedIntegrations: getIntegrationKindsByCategory("mediaService"),
|
supportedIntegrations: getIntegrationKindsByCategory("mediaService"),
|
||||||
|
|||||||
Reference in new issue
Block a user