From cee4173077b604e3443ce5d78a7403ad89b4c8bd Mon Sep 17 00:00:00 2001 From: Don Reece Date: Thu, 3 Nov 2022 21:17:27 -0400 Subject: [PATCH] Add HDHomeRun Widget --- public/locales/en/common.json | 4 ++++ src/widgets/components.js | 1 + src/widgets/hdhomerun/component.jsx | 34 +++++++++++++++++++++++++++++ src/widgets/hdhomerun/widget.js | 21 ++++++++++++++++++ src/widgets/widgets.js | 2 ++ 5 files changed, 62 insertions(+) create mode 100644 src/widgets/hdhomerun/component.jsx create mode 100644 src/widgets/hdhomerun/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index a4b0628d..ea376069 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -309,5 +309,9 @@ "videos": "Videos", "channels": "Channels", "playlists": "Playlists" + }, + "hdhomerun": { + "channels": "Channels", + "hd": "HD" } } diff --git a/src/widgets/components.js b/src/widgets/components.js index 47502403..03d108dd 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -10,6 +10,7 @@ const components = { docker: dynamic(() => import("./docker/component")), emby: dynamic(() => import("./emby/component")), gotify: dynamic(() => import("./gotify/component")), + hdhomerun: dynamic(() => import("./hdhomerun/component")), homebridge: dynamic(() => import("./homebridge/component")), jackett: dynamic(() => import("./jackett/component")), jellyfin: dynamic(() => import("./emby/component")), diff --git a/src/widgets/hdhomerun/component.jsx b/src/widgets/hdhomerun/component.jsx new file mode 100644 index 00000000..0f6485dd --- /dev/null +++ b/src/widgets/hdhomerun/component.jsx @@ -0,0 +1,34 @@ +import { useTranslation } from "next-i18next"; + +import Container from "components/services/widget/container"; +import Block from "components/services/widget/block"; +import useWidgetAPI from "utils/proxy/use-widget-api"; + +export default function Component({ service }) { + const { t } = useTranslation(); + + const { widget } = service; + + const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup.json"); + const { data: hdData, error: hdError } = useWidgetAPI(widget, "hd"); + + if (channelsError || hdError) { + return ; + } + + if (!channelsData || !hdData) { + return ( + + + + + ); + } + + return ( + + + + + ); +} diff --git a/src/widgets/hdhomerun/widget.js b/src/widgets/hdhomerun/widget.js new file mode 100644 index 00000000..fff75dda --- /dev/null +++ b/src/widgets/hdhomerun/widget.js @@ -0,0 +1,21 @@ +import genericProxyHandler from "utils/proxy/handlers/generic"; +import { jsonArrayFilter } from "utils/proxy/api-helpers"; + +const widget = { + api: "{url}/{endpoint}", + proxyHandler: genericProxyHandler, + + mappings: { + "lineup.json": { + endpoint: "lineup.json", + }, + hd: { + endpoint: "lineup.json", + map: (data) => ({ + have: jsonArrayFilter(data, (item) => item?.HD === 1).length, + }), + }, + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 0352466d..47218a1f 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -6,6 +6,7 @@ import changedetectionio from "./changedetectionio/widget"; import coinmarketcap from "./coinmarketcap/widget"; import emby from "./emby/widget"; import gotify from "./gotify/widget"; +import hdhomerun from "./hdhomerun/widget"; import homebridge from "./homebridge/widget"; import jackett from "./jackett/widget"; import jellyseerr from "./jellyseerr/widget"; @@ -44,6 +45,7 @@ const widgets = { coinmarketcap, emby, gotify, + hdhomerun, homebridge, jackett, jellyfin: emby,