diff --git a/public/locales/en/common.json b/public/locales/en/common.json index a9d6ed34..db5ffe46 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -72,7 +72,11 @@ "playing": "Playing", "transcoding": "Transcoding", "bitrate": "Bitrate", - "no_active": "No Active Streams" + "no_active": "No Active Streams", + "movies": "Movies", + "series": "Series", + "episodes": "Episodes", + "songs": "Songs" }, "flood": { "download": "Download", diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js index 49401ee6..317c0f3c 100644 --- a/src/utils/config/service-helpers.js +++ b/src/utils/config/service-helpers.js @@ -247,7 +247,9 @@ export function cleanServiceGroups(groups) { namespace, // kubernetes widget app, podSelector, - wan // opnsense widget + wan, // opnsense widget, + enableBlocks, // emby/jellyfin + enableNowPlaying } = cleanedService.widget; const fieldsList = typeof fields === 'string' ? JSON.parse(fields) : fields; @@ -278,6 +280,10 @@ export function cleanServiceGroups(groups) { if (type === "opnsense") { if (wan) cleanedService.widget.wan = wan; } + if (type === "emby" || type === "jellyfin") { + if (enableBlocks) cleanedService.widget.enableBlocks = enableBlocks === 'true'; + if (enableNowPlaying) cleanedService.widget.enableNowPlaying = enableNowPlaying === 'true'; + } } return cleanedService; diff --git a/src/widgets/emby/component.jsx b/src/widgets/emby/component.jsx index a61cd7aa..3f70a79d 100644 --- a/src/widgets/emby/component.jsx +++ b/src/widgets/emby/component.jsx @@ -2,6 +2,7 @@ import { useTranslation } from "next-i18next"; import { BsVolumeMuteFill, BsFillPlayFill, BsPauseFill, BsCpu, BsFillCpuFill } from "react-icons/bs"; import { MdOutlineSmartDisplay } from "react-icons/md"; +import Block from "components/services/widget/block"; import Container from "components/services/widget/container"; import { formatProxyUrlWithSegments } from "utils/proxy/api-helpers"; import useWidgetAPI from "utils/proxy/use-widget-api"; @@ -148,6 +149,33 @@ function SessionEntry({ playCommand, session }) { ); } +function CountBlocks({ service, countData }) { + const { t } = useTranslation(); + // allows filtering + // eslint-disable-next-line no-param-reassign + if (service.widget?.type === 'jellyfin') service.widget.type = 'emby' + + if (!countData) { + return ( + + + + + + + ) + } + + return ( + + + + + + + ) +} + export default function Component({ service }) { const { t } = useTranslation(); @@ -161,6 +189,12 @@ export default function Component({ service }) { refreshInterval: 5000, }); + const { + data: countData, + error: countError, + } = useWidgetAPI(widget, "Count", { + refreshInterval: 60000,}); + async function handlePlayCommand(session, command) { const url = formatProxyUrlWithSegments(widget, "PlayControl", { sessionId: session.Id, @@ -171,69 +205,93 @@ export default function Component({ service }) { }); } - if (sessionsError) { - return ; + if (sessionsError || countError) { + return ; } - if (!sessionsData) { + const enableBlocks = service.widget?.enableBlocks + const enableNowPlaying = service.widget?.enableNowPlaying ?? true + + if (!sessionsData || !countData) { return ( -
+ <> + {enableBlocks && } + {enableNowPlaying &&
-
-
-
+
} + ); } - const playing = sessionsData - .filter((session) => session?.NowPlayingItem) - .sort((a, b) => { - if (a.PlayState.PositionTicks > b.PlayState.PositionTicks) { - return 1; - } - if (a.PlayState.PositionTicks < b.PlayState.PositionTicks) { - return -1; - } - return 0; - }); - - if (playing.length === 0) { + if (enableNowPlaying) { + const playing = sessionsData + .filter((session) => session?.NowPlayingItem) + .sort((a, b) => { + if (a.PlayState.PositionTicks > b.PlayState.PositionTicks) { + return 1; + } + if (a.PlayState.PositionTicks < b.PlayState.PositionTicks) { + return -1; + } + return 0; + }); + + if (playing.length === 0) { + return ( + <> + {enableBlocks && } +
+
+ {t("emby.no_active")} +
+
+ - +
+
+ + ); + } + + if (playing.length === 1) { + const session = playing[0]; + return ( + <> + {enableBlocks && } +
+ handlePlayCommand(currentSession, command)} + session={session} + /> +
+ + ); + } + + if (playing.length === -1) return ( + <> + {enableBlocks && }
-
- {t("emby.no_active")} -
-
- - -
+ {playing.map((session) => ( + handlePlayCommand(currentSession, command)} + session={session} + /> + ))}
+ ); } - if (playing.length === 1) { - const session = playing[0]; + if (enableBlocks) { return ( -
- handlePlayCommand(currentSession, command)} - session={session} - /> -
- ); + + ) } - - return ( -
- {playing.map((session) => ( - handlePlayCommand(currentSession, command)} - session={session} - /> - ))} -
- ); } diff --git a/src/widgets/emby/widget.js b/src/widgets/emby/widget.js index 27fc749b..bbf13a30 100644 --- a/src/widgets/emby/widget.js +++ b/src/widgets/emby/widget.js @@ -8,6 +8,15 @@ const widget = { Sessions: { endpoint: "Sessions", }, + Count: { + endpoint: "Items/Counts", + segments: [ + "MovieCount", + "SeriesCount", + "EpisodeCount", + "SongCount" + ] + }, PlayControl: { method: "POST", endpoint: "Sessions/{sessionId}/Playing/{command}",