Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add navidrome support #503

Merged
merged 3 commits into from Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions public/locales/en/common.json
Expand Up @@ -168,6 +168,10 @@
"services": "Services",
"middleware": "Middleware"
},
"navidrome": {
"nothing_streaming": "No Active Streams",
"please_wait": "Please Wait"
},
"npm": {
"enabled": "Enabled",
"disabled": "Disabled",
Expand Down
1 change: 1 addition & 0 deletions src/widgets/components.js
Expand Up @@ -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")),
Expand Down
56 changes: 56 additions & 0 deletions 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 (
<div className="text-theme-700 dark:text-theme-200 relative h-5 w-full rounded-md bg-theme-200/50 dark:bg-theme-900/20 mt-1 flex">
<div className="text-xs z-10 self-center ml-2 relative w-full h-4 grow mr-2">
<div className="absolute w-full whitespace-nowrap text-ellipsis overflow-hidden">{fullTitle}</div>
</div>
</div>
);
}

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 <Container error={t("widget.api_error")} />;
}

if (!navidromeData) {
return (
<SinglePlayingEntry entry={{ title: t("navidrome.please_wait") }} />
);
}

const { nowPlaying } = navidromeData["subsonic-response"];
if (!nowPlaying.entry) {
// nothing playing
return (
<SinglePlayingEntry entry={{ title: t("navidrome.nothing_streaming") }} />
);
}

const nowPlayingEntries = Object.values(nowPlaying.entry);

return (
<div className="flex flex-col pb-1 mx-1">
{nowPlayingEntries.map((entry) => (
<SinglePlayingEntry key={entry.id} entry={entry} />
))}
</div>
);
}
14 changes: 14 additions & 0 deletions 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;
2 changes: 2 additions & 0 deletions src/widgets/widgets.js
Expand Up @@ -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";
Expand Down Expand Up @@ -51,6 +52,7 @@ const widgets = {
jellyseerr,
lidarr,
mastodon,
navidrome,
npm,
nzbget,
ombi,
Expand Down