diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 8784443a4..afba679a1 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -168,6 +168,10 @@ "services": "Services", "middleware": "Middleware" }, + "navidrome": { + "nothing_streaming": "No Active Streams", + "please_wait": "Please Wait" + }, "npm": { "enabled": "Enabled", "disabled": "Disabled", diff --git a/src/widgets/components.js b/src/widgets/components.js index 33d09eac3..28b5a92f0 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -16,6 +16,7 @@ const components = { jellyseerr: dynamic(() => import("./jellyseerr/component")), lidarr: dynamic(() => import("./lidarr/component")), mastodon: dynamic(() => import("./mastodon/component")), + navidrome: dynamic(() => import("./navidrome/component")), npm: dynamic(() => import("./npm/component")), nzbget: dynamic(() => import("./nzbget/component")), ombi: dynamic(() => import("./ombi/component")), diff --git a/src/widgets/navidrome/component.jsx b/src/widgets/navidrome/component.jsx new file mode 100644 index 000000000..f4f3e6721 --- /dev/null +++ b/src/widgets/navidrome/component.jsx @@ -0,0 +1,56 @@ +import { useTranslation } from "next-i18next"; + +import Container from "components/services/widget/container"; +import useWidgetAPI from "utils/proxy/use-widget-api"; + +function SinglePlayingEntry({ entry }) { + const { username, artist, title, album } = entry; + let fullTitle = title; + if (artist) fullTitle = `${artist} - ${title}`; + if (album) fullTitle += ` — ${album}`; + if (username) fullTitle += ` (${username})`; + + return ( +
+
+
{fullTitle}
+
+
+ ); +} + +export default function Component({ service }) { + const { t } = useTranslation(); + + const { widget } = service; + + const { data: navidromeData, error: navidromeError } = useWidgetAPI(widget, "getNowPlaying"); + + if (navidromeError || navidromeData?.error || navidromeData?.["subsonic-response"]?.error) { + return ; + } + + if (!navidromeData) { + return ( + + ); + } + + const { nowPlaying } = navidromeData["subsonic-response"]; + if (!nowPlaying.entry) { + // nothing playing + return ( + + ); + } + + const nowPlayingEntries = Object.values(nowPlaying.entry); + + return ( +
+ {nowPlayingEntries.map((entry) => ( + + ))} +
+ ); +} diff --git a/src/widgets/navidrome/widget.js b/src/widgets/navidrome/widget.js new file mode 100644 index 000000000..9d7c03d45 --- /dev/null +++ b/src/widgets/navidrome/widget.js @@ -0,0 +1,14 @@ +import genericProxyHandler from "utils/proxy/handlers/generic"; + +const widget = { + api: "{url}/rest/{endpoint}?u={user}&t={token}&s={salt}&v=1.16.1&c=homepage&f=json", + proxyHandler: genericProxyHandler, + + mappings: { + "getNowPlaying": { + endpoint: "getNowPlaying", + }, + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 7bad4013b..aaf0a0255 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -11,6 +11,7 @@ import jackett from "./jackett/widget"; import jellyseerr from "./jellyseerr/widget"; import lidarr from "./lidarr/widget"; import mastodon from "./mastodon/widget"; +import navidrome from "./navidrome/widget"; import npm from "./npm/widget"; import nzbget from "./nzbget/widget"; import ombi from "./ombi/widget"; @@ -51,6 +52,7 @@ const widgets = { jellyseerr, lidarr, mastodon, + navidrome, npm, nzbget, ombi,