From 263801677aecb829b33454f8f0c0287a74c77c7b Mon Sep 17 00:00:00 2001 From: Dinesh Reddy J Date: Sun, 12 Mar 2023 21:57:13 +0530 Subject: [PATCH 1/3] Added Jellyfin Widget to show number of movies,Series, Episodes songs #264 --- src/widgets/emby/component.jsx | 63 +++++++++++++++++++++++++++++++--- src/widgets/emby/widget.js | 9 +++++ 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/src/widgets/emby/component.jsx b/src/widgets/emby/component.jsx index a61cd7aa7..e7d65a347 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"; @@ -161,18 +162,45 @@ 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, command, }); await fetch(url).then(() => { - sessionMutate(); + sessionMutate; }); } - if (sessionsError) { - return ; + if (sessionsError || countError) { + return ; + } + + if (!sessionsData && countData) { + return ( + <> + + + + + + +
+
+ - +
+
+ - +
+
+ + ); } if (!sessionsData) { @@ -200,8 +228,15 @@ export default function Component({ service }) { return 0; }); - if (playing.length === 0) { + if (playing.length === 0 && countData) { return ( + <> + + + + + +
{t("emby.no_active")} @@ -210,22 +245,39 @@ export default function Component({ service }) { -
+ ); } - if (playing.length === 1) { + if (playing.length === 1 && countData) { const session = playing[0]; return ( + <> + + + + + +
handlePlayCommand(currentSession, command)} session={session} />
+ ); } + if (countData && playing.length === -1) return ( + <> + + + + + +
{playing.map((session) => ( ))}
+ ); } diff --git a/src/widgets/emby/widget.js b/src/widgets/emby/widget.js index 27fc749b0..bbf13a302 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}", From 29c7a51b04fafbeb11eca46abad7114a6d94b6b6 Mon Sep 17 00:00:00 2001 From: Dinesh Reddy J Date: Sun, 12 Mar 2023 22:11:15 +0530 Subject: [PATCH 2/3] modified: src/widgets/emby/component.jsx --- src/widgets/emby/component.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/emby/component.jsx b/src/widgets/emby/component.jsx index e7d65a347..a8d4f6b26 100644 --- a/src/widgets/emby/component.jsx +++ b/src/widgets/emby/component.jsx @@ -174,7 +174,7 @@ export default function Component({ service }) { command, }); await fetch(url).then(() => { - sessionMutate; + sessionMutate(); }); } From eaf7ba608b5f9707950ec5d7f16fbcd58e84d099 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 12 Mar 2023 16:50:28 -0700 Subject: [PATCH 3/3] Fix blocks for emby/jellyfin, support enable/disable --- public/locales/en/common.json | 6 +- src/utils/config/service-helpers.js | 8 +- src/widgets/emby/component.jsx | 173 ++++++++++++++-------------- 3 files changed, 101 insertions(+), 86 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index a9d6ed34c..db5ffe46b 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 49401ee63..317c0f3c3 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 a8d4f6b26..3f70a79d6 100644 --- a/src/widgets/emby/component.jsx +++ b/src/widgets/emby/component.jsx @@ -149,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(); @@ -179,114 +206,92 @@ export default function Component({ service }) { } if (sessionsError || countError) { - return ; + return ; } - if (!sessionsData && countData) { + const enableBlocks = service.widget?.enableBlocks + const enableNowPlaying = service.widget?.enableNowPlaying ?? true + + if (!sessionsData || !countData) { return ( <> - - - - - - -
+ {enableBlocks && } + {enableNowPlaying &&
-
-
-
+
} ); } - if (!sessionsData) { - return ( -
-
- - + 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} + />
-
- ); - } - - 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 && countData) { + + ); + } + + if (playing.length === -1) return ( <> - - - - - - + {enableBlocks && }
-
- {t("emby.no_active")} -
-
- - -
+ {playing.map((session) => ( + handlePlayCommand(currentSession, command)} + session={session} + /> + ))}
); } - if (playing.length === 1 && countData) { - const session = playing[0]; + if (enableBlocks) { return ( - <> - - - - - - -
- handlePlayCommand(currentSession, command)} - session={session} - /> -
- - ); + + ) } - - if (countData && playing.length === -1) - return ( - <> - - - - - - -
- {playing.map((session) => ( - handlePlayCommand(currentSession, command)} - session={session} - /> - ))} -
- - ); }