mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-01 21:13:39 +01:00
redesigned media streaming widgets
This commit is contained in:
parent
53149df5f1
commit
bd2b28a7ac
@ -39,12 +39,14 @@
|
|||||||
"emby": {
|
"emby": {
|
||||||
"playing": "Playing",
|
"playing": "Playing",
|
||||||
"transcoding": "Transcoding",
|
"transcoding": "Transcoding",
|
||||||
"bitrate": "Bitrate"
|
"bitrate": "Bitrate",
|
||||||
|
"no_active": "No Active Streams"
|
||||||
},
|
},
|
||||||
"tautulli": {
|
"tautulli": {
|
||||||
"playing": "Playing",
|
"playing": "Playing",
|
||||||
"transcoding": "Transcoding",
|
"transcoding": "Transcoding",
|
||||||
"bitrate": "Bitrate"
|
"bitrate": "Bitrate",
|
||||||
|
"no_active": "No Active Streams"
|
||||||
},
|
},
|
||||||
"nzbget": {
|
"nzbget": {
|
||||||
"rate": "Rate",
|
"rate": "Rate",
|
||||||
|
@ -1,17 +1,148 @@
|
|||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { BsVolumeMuteFill, BsFillPlayFill, BsPauseFill } from "react-icons/bs";
|
||||||
|
|
||||||
import Widget from "../widget";
|
import Widget from "../widget";
|
||||||
import Block from "../block";
|
|
||||||
|
|
||||||
import { formatApiUrl } from "utils/api-helpers";
|
import { formatApiUrl } from "utils/api-helpers";
|
||||||
|
|
||||||
|
function ticksToTime(ticks) {
|
||||||
|
const milliseconds = ticks / 10000;
|
||||||
|
const seconds = Math.floor((milliseconds / 1000) % 60);
|
||||||
|
const minutes = Math.floor((milliseconds / (1000 * 60)) % 60);
|
||||||
|
const hours = Math.floor((milliseconds / (1000 * 60 * 60)) % 24);
|
||||||
|
return { hours, minutes, seconds };
|
||||||
|
}
|
||||||
|
|
||||||
|
function ticksToString(ticks) {
|
||||||
|
const { hours, minutes, seconds } = ticksToTime(ticks);
|
||||||
|
const parts = [];
|
||||||
|
if (hours > 0) {
|
||||||
|
parts.push(hours);
|
||||||
|
}
|
||||||
|
parts.push(minutes);
|
||||||
|
parts.push(seconds);
|
||||||
|
|
||||||
|
return parts.map((part) => part.toString().padStart(2, "0")).join(":");
|
||||||
|
}
|
||||||
|
|
||||||
|
function SingleSessionEntry({ playCommand, session }) {
|
||||||
|
const {
|
||||||
|
NowPlayingItem: { Name, SeriesName, RunTimeTicks },
|
||||||
|
PlayState: { PositionTicks, IsPaused, IsMuted },
|
||||||
|
} = session;
|
||||||
|
const percent = (PositionTicks / RunTimeTicks) * 100;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="text-theme-700 dark:text-theme-200 relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1 flex">
|
||||||
|
<div className="text-xs z-10 self-center ml-2">
|
||||||
|
<span>
|
||||||
|
{Name}
|
||||||
|
{SeriesName && ` - ${SeriesName}`}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="grow" />
|
||||||
|
<div className="self-center text-xs flex justify-end mr-1">{IsMuted && <BsVolumeMuteFill />}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-theme-700 dark:text-theme-200 relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1 flex">
|
||||||
|
<div
|
||||||
|
className="absolute h-5 rounded-md bg-theme-200 dark:bg-theme-900/40 z-0"
|
||||||
|
style={{
|
||||||
|
width: `${percent}%`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="text-xs z-10 self-center ml-1">
|
||||||
|
{IsPaused && (
|
||||||
|
<BsFillPlayFill
|
||||||
|
onClick={() => {
|
||||||
|
playCommand(session, "Unpause");
|
||||||
|
}}
|
||||||
|
className="inline-block w-4 h-4 cursor-pointer -mt-[1px] mr-1 opacity-80"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{!IsPaused && (
|
||||||
|
<BsPauseFill
|
||||||
|
onClick={() => {
|
||||||
|
playCommand(session, "Pause");
|
||||||
|
}}
|
||||||
|
className="inline-block w-4 h-4 cursor-pointer -mt-[1px] mr-1 opacity-80"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="grow " />
|
||||||
|
<div className="self-center text-xs flex justify-end mr-2">{ticksToString(PositionTicks)}</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SessionEntry({ playCommand, session }) {
|
||||||
|
const {
|
||||||
|
NowPlayingItem: { Name, SeriesName, RunTimeTicks },
|
||||||
|
PlayState: { PositionTicks, IsPaused, IsMuted },
|
||||||
|
} = session;
|
||||||
|
const percent = (PositionTicks / RunTimeTicks) * 100;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="text-theme-700 dark:text-theme-200 relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1 flex">
|
||||||
|
<div
|
||||||
|
className="absolute h-5 rounded-md bg-theme-200 dark:bg-theme-900/40 z-0"
|
||||||
|
style={{
|
||||||
|
width: `${percent}%`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="text-xs z-10 self-center ml-1">
|
||||||
|
{IsPaused && (
|
||||||
|
<BsFillPlayFill
|
||||||
|
onClick={() => {
|
||||||
|
playCommand(session, "Unpause");
|
||||||
|
}}
|
||||||
|
className="inline-block w-4 h-4 cursor-pointer -mt-[1px] mr-1 opacity-80"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{!IsPaused && (
|
||||||
|
<BsPauseFill
|
||||||
|
onClick={() => {
|
||||||
|
playCommand(session, "Pause");
|
||||||
|
}}
|
||||||
|
className="inline-block w-4 h-4 cursor-pointer -mt-[1px] mr-1 opacity-80"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<span>
|
||||||
|
{Name}
|
||||||
|
{SeriesName && ` - ${SeriesName}`}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="grow " />
|
||||||
|
<div className="self-center text-xs flex justify-end mr-1">{IsMuted && <BsVolumeMuteFill />}</div>
|
||||||
|
<div className="self-center text-xs flex justify-end mr-2">{ticksToString(PositionTicks)}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function Emby({ service }) {
|
export default function Emby({ service }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const config = service.widget;
|
const config = service.widget;
|
||||||
|
|
||||||
const { data: sessionsData, error: sessionsError } = useSWR(formatApiUrl(config, "Sessions"));
|
const {
|
||||||
|
data: sessionsData,
|
||||||
|
error: sessionsError,
|
||||||
|
mutate: sessionMutate,
|
||||||
|
} = useSWR(formatApiUrl(config, "Sessions"), {
|
||||||
|
refreshInterval: 5000,
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handlePlayCommand(session, command) {
|
||||||
|
const url = formatApiUrl(config, `Sessions/${session.Id}/Playing/${command}`);
|
||||||
|
await fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
}).then(() => {
|
||||||
|
sessionMutate();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (sessionsError) {
|
if (sessionsError) {
|
||||||
return <Widget error={t("widget.api_error")} />;
|
return <Widget error={t("widget.api_error")} />;
|
||||||
@ -19,26 +150,63 @@ export default function Emby({ service }) {
|
|||||||
|
|
||||||
if (!sessionsData) {
|
if (!sessionsData) {
|
||||||
return (
|
return (
|
||||||
<Widget>
|
<div className="flex flex-col pb-1">
|
||||||
<Block label={t("emby.playing")} />
|
<div className="text-theme-700 dark:text-theme-200 text-xs relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1">
|
||||||
<Block label={t("emby.transcoding")} />
|
<span className="absolute left-2 text-xs mt-[2px]">-</span>
|
||||||
<Block label={t("emby.bitrate")} />
|
</div>
|
||||||
</Widget>
|
<div className="text-theme-700 dark:text-theme-200 text-xs relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1">
|
||||||
|
<span className="absolute left-2 text-xs mt-[2px]">-</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const playing = sessionsData.filter((session) => session?.NowPlayingItem);
|
const playing = sessionsData
|
||||||
const transcoding = sessionsData.filter(
|
.filter((session) => session?.NowPlayingItem)
|
||||||
(session) => session?.PlayState && session.PlayState.PlayMethod === "Transcode"
|
.sort((a, b) => {
|
||||||
);
|
if (a.PlayState.PositionTicks > b.PlayState.PositionTicks) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (a.PlayState.PositionTicks < b.PlayState.PositionTicks) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
const bitrate = playing.reduce((acc, session) => acc + session.NowPlayingItem.Bitrate, 0);
|
if (playing.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col pb-1">
|
||||||
|
<div className="text-theme-700 dark:text-theme-200 text-xs relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1">
|
||||||
|
<span className="absolute left-2 text-xs mt-[2px]">{t("emby.no_active")}</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-theme-700 dark:text-theme-200 text-xs relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1">
|
||||||
|
<span className="absolute left-2 text-xs mt-[2px]">-</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playing.length === 1) {
|
||||||
|
const session = playing[0];
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col pb-1">
|
||||||
|
<SingleSessionEntry
|
||||||
|
playCommand={(currentSession, command) => handlePlayCommand(currentSession, command)}
|
||||||
|
session={session}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Widget>
|
<div className="flex flex-col pb-1">
|
||||||
<Block label={t("emby.playing")} value={playing.length} />
|
{playing.map((session) => (
|
||||||
<Block label={t("emby.transcoding")} value={transcoding.length} />
|
<SessionEntry
|
||||||
<Block label={t("emby.bitrate")} value={t("common.bitrate", { value: bitrate })} />
|
key={session.Id}
|
||||||
</Widget>
|
playCommand={(currentSession, command) => handlePlayCommand(currentSession, command)}
|
||||||
|
session={session}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,48 +1,5 @@
|
|||||||
import useSWR from "swr";
|
import Emby from "./emby";
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
import Widget from "../widget";
|
|
||||||
import Block from "../block";
|
|
||||||
|
|
||||||
import { formatApiUrl } from "utils/api-helpers";
|
|
||||||
|
|
||||||
export default function Jellyfin({ service }) {
|
export default function Jellyfin({ service }) {
|
||||||
const { t } = useTranslation();
|
return <Emby service={service} />;
|
||||||
|
|
||||||
const config = service.widget;
|
|
||||||
|
|
||||||
const { data: sessionsData, error: sessionsError } = useSWR(formatApiUrl(config, "Sessions"));
|
|
||||||
|
|
||||||
if (sessionsError) {
|
|
||||||
return <Widget error={t("widget.api_error")} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sessionsData) {
|
|
||||||
return (
|
|
||||||
<Widget>
|
|
||||||
<Block label={t("emby.playing")} />
|
|
||||||
<Block label={t("emby.transcoding")} />
|
|
||||||
<Block label={t("emby.bitrate")} />
|
|
||||||
</Widget>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const playing = sessionsData.filter((session) => session?.NowPlayingItem);
|
|
||||||
const transcoding = sessionsData.filter(
|
|
||||||
(session) => session?.PlayState && session.PlayState.PlayMethod === "Transcode"
|
|
||||||
);
|
|
||||||
|
|
||||||
const bitrate = playing.reduce(
|
|
||||||
(acc, session) =>
|
|
||||||
acc + session.NowPlayingQueueFullItems[0].MediaSources.reduce((acb, source) => acb + source.Bitrate, 0),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Widget>
|
|
||||||
<Block label={t("emby.playing")} value={playing.length} />
|
|
||||||
<Block label={t("emby.transcoding")} value={transcoding.length} />
|
|
||||||
<Block label={t("emby.bitrate")} value={t("common.bitrate", { value: bitrate })} />
|
|
||||||
</Widget>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,157 @@
|
|||||||
|
/* eslint-disable camelcase */
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { BsFillPlayFill, BsPauseFill } from "react-icons/bs";
|
||||||
|
|
||||||
import Widget from "../widget";
|
import Widget from "../widget";
|
||||||
import Block from "../block";
|
|
||||||
|
|
||||||
import { formatApiUrl } from "utils/api-helpers";
|
import { formatApiUrl } from "utils/api-helpers";
|
||||||
|
|
||||||
|
function millisecondsToTime(milliseconds) {
|
||||||
|
const seconds = Math.floor((milliseconds / 1000) % 60);
|
||||||
|
const minutes = Math.floor((milliseconds / (1000 * 60)) % 60);
|
||||||
|
const hours = Math.floor((milliseconds / (1000 * 60 * 60)) % 24);
|
||||||
|
return { hours, minutes, seconds };
|
||||||
|
}
|
||||||
|
|
||||||
|
function millisecondsToString(milliseconds) {
|
||||||
|
const { hours, minutes, seconds } = millisecondsToTime(milliseconds);
|
||||||
|
const parts = [];
|
||||||
|
if (hours > 0) {
|
||||||
|
parts.push(hours);
|
||||||
|
}
|
||||||
|
parts.push(minutes);
|
||||||
|
parts.push(seconds);
|
||||||
|
|
||||||
|
return parts.map((part) => part.toString().padStart(2, "0")).join(":");
|
||||||
|
}
|
||||||
|
|
||||||
|
function SingleSessionEntry({ session }) {
|
||||||
|
const { full_title, duration, view_offset, progress_percent, state, year, grandparent_year } = session;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="text-theme-700 dark:text-theme-200 relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1 flex">
|
||||||
|
<div className="text-xs z-10 self-center ml-2">
|
||||||
|
<span>{full_title}</span>
|
||||||
|
</div>
|
||||||
|
<div className="grow" />
|
||||||
|
<div className="self-center text-xs flex justify-end mr-2">{year || grandparent_year}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-theme-700 dark:text-theme-200 relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1 flex">
|
||||||
|
<div
|
||||||
|
className="absolute h-5 rounded-md bg-theme-200 dark:bg-theme-900/40 z-0"
|
||||||
|
style={{
|
||||||
|
width: `${progress_percent}%`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="text-xs z-10 self-center ml-1">
|
||||||
|
{state === "paused" && (
|
||||||
|
<BsFillPlayFill className="inline-block w-4 h-4 cursor-pointer -mt-[1px] mr-1 opacity-80" />
|
||||||
|
)}
|
||||||
|
{state !== "paused" && (
|
||||||
|
<BsPauseFill className="inline-block w-4 h-4 cursor-pointer -mt-[1px] mr-1 opacity-80" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="grow " />
|
||||||
|
<div className="self-center text-xs flex justify-end mr-2">
|
||||||
|
{millisecondsToString(view_offset)} / {millisecondsToString(duration)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SessionEntry({ session }) {
|
||||||
|
const { full_title, view_offset, progress_percent, state } = session;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="text-theme-700 dark:text-theme-200 relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1 flex">
|
||||||
|
<div
|
||||||
|
className="absolute h-5 rounded-md bg-theme-200 dark:bg-theme-900/40 z-0"
|
||||||
|
style={{
|
||||||
|
width: `${progress_percent}%`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="text-xs z-10 self-center ml-1">
|
||||||
|
{state === "paused" && (
|
||||||
|
<BsFillPlayFill className="inline-block w-4 h-4 cursor-pointer -mt-[1px] mr-1 opacity-80" />
|
||||||
|
)}
|
||||||
|
{state !== "paused" && (
|
||||||
|
<BsPauseFill className="inline-block w-4 h-4 cursor-pointer -mt-[1px] mr-1 opacity-80" />
|
||||||
|
)}
|
||||||
|
<span>{full_title}</span>
|
||||||
|
</div>
|
||||||
|
<div className="grow " />
|
||||||
|
<div className="self-center text-xs flex justify-end mr-2">{millisecondsToString(view_offset)}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function Tautulli({ service }) {
|
export default function Tautulli({ service }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const config = service.widget;
|
const config = service.widget;
|
||||||
|
|
||||||
const { data: statsData, error: statsError } = useSWR(formatApiUrl(config, "get_activity"));
|
const { data: activityData, error: activityError } = useSWR(formatApiUrl(config, "get_activity"), {
|
||||||
|
refreshInterval: 5000,
|
||||||
|
});
|
||||||
|
|
||||||
if (statsError) {
|
if (activityError) {
|
||||||
return <Widget error={t("widget.api_error")} />;
|
return <Widget error={t("widget.api_error")} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!statsData) {
|
if (!activityData) {
|
||||||
return (
|
return (
|
||||||
<Widget>
|
<div className="flex flex-col pb-1">
|
||||||
<Block label={t("tautulli.playing")} />
|
<div className="text-theme-700 dark:text-theme-200 text-xs relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1">
|
||||||
<Block label={t("tautulli.transcoding")} />
|
<span className="absolute left-2 text-xs mt-[2px]">-</span>
|
||||||
<Block label={t("tautulli.bitrate")} />
|
</div>
|
||||||
</Widget>
|
<div className="text-theme-700 dark:text-theme-200 text-xs relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1">
|
||||||
|
<span className="absolute left-2 text-xs mt-[2px]">-</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = statsData.response;
|
const playing = activityData.response.data.sessions.sort((a, b) => {
|
||||||
|
if (a.view_offset > b.view_offset) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (a.view_offset < b.view_offset) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (playing.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col pb-1">
|
||||||
|
<div className="text-theme-700 dark:text-theme-200 text-xs relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1">
|
||||||
|
<span className="absolute left-2 text-xs mt-[2px]">{t("tautulli.no_active")}</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-theme-700 dark:text-theme-200 text-xs relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1">
|
||||||
|
<span className="absolute left-2 text-xs mt-[2px]">-</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playing.length === 1) {
|
||||||
|
const session = playing[0];
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col pb-1">
|
||||||
|
<SingleSessionEntry session={session} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Widget>
|
<div className="flex flex-col pb-1">
|
||||||
<Block label={t("tautulli.playing")} value={data.stream_count} />
|
{playing.map((session) => (
|
||||||
<Block label={t("tautulli.transcoding")} value={data.stream_count_transcode} />
|
<SessionEntry key={session.Id} session={session} />
|
||||||
<Block label={t("tautulli.bitrate")} value={t("common.bitrate", { value: data.total_bandwidth })} />
|
))}
|
||||||
</Widget>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user