From c6d8668e69bc98ee068c9f0dc1e262f3e2570a77 Mon Sep 17 00:00:00 2001 From: Ben Phelps Date: Fri, 9 Sep 2022 11:42:08 +0300 Subject: [PATCH] fix jellyfin integration --- .../services/widgets/service/jellyfin.jsx | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/components/services/widgets/service/jellyfin.jsx b/src/components/services/widgets/service/jellyfin.jsx index 03a8840ab..9a713ea14 100644 --- a/src/components/services/widgets/service/jellyfin.jsx +++ b/src/components/services/widgets/service/jellyfin.jsx @@ -1,6 +1,50 @@ -import Emby from "./emby"; +import useSWR from "swr"; +import { useTranslation } from "react-i18next"; + +import Widget from "../widget"; +import Block from "../block"; + +import { formatApiUrl } from "utils/api-helpers"; -// Jellyfin and Emby share the same API, so proxy the Emby widget to Jellyfin. export default function Jellyfin({ service }) { - return ; + const { t } = useTranslation(); + + const config = service.widget; + + const { data: sessionsData, error: sessionsError } = useSWR(formatApiUrl(config, "Sessions")); + + if (sessionsError) { + return ; + } + + if (!sessionsData) { + return ( + + + + + + ); + } + + console.log(sessionsData); + + 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 ( + + + + + + ); }