Understudy connects activity sources to outputs. It watches what you’re doing across services, chooses your current activity, and keeps a private history on your server. Its Discord output shows:
- "Watching Plex" (or Jellyfin, Emby, Trakt), with the poster and a progress bar;
- "Listening to Plex" (or Last.fm, ListenBrainz), with album art;
- "Playing Nintendo Switch" or "Playing Steam", with the game.
It doesn't need the Discord desktop app on the machine doing the playing.
- Sources:
- Plex (via Tautulli): movies, episodes and music.
- Jellyfin / Emby: movies, episodes and music.
- Trakt: movies and episodes from anything that scrobbles to Trakt (Infuse, Kodi, browser extensions, …).
- Last.fm / ListenBrainz: music from anything that scrobbles.
- Nintendo Switch (via nxapi): Switch and Switch 2 games.
- Steam: what you're playing, including on a Steam Deck in Game Mode.
- Manual: set an activity from the web UI.
- History sources (history only; never shown live):
- Calendar (iCal): past events from Google, Apple or Outlook calendars.
- Discord status: what your own Discord clients show, such as games Discord detects on your PC.
- Outputs:
- Discord: only while you're actually on Discord, with your real status. Uses the Hub’s selected activity, with optional rules for this output.
- Calendar feed and JSON feed: publish your history at a secret link.
- Hub: source priority, paused-media rules, quiet hours, and publishing pause controls.
- History and Calendar: everything sources saw and outputs showed, as a week calendar with daily totals.
- Web UI for setup, sign-ins and live status. Settings live in
/data.
Sources and outputs are plugins, so more can be added (see Architecture).
cp compose.example.yml compose.yml # set UI_PASSWORD
docker compose up -d --buildThen open http://localhost:8080. For development, use Node 22.13 or newer (history uses built-in node:sqlite):
pnpm install
pnpm dev # builds UI assets; http://localhost:8080, data in ./data
pnpm dev:css # optional second terminal: rebuild CSS as JSX/styles change
pnpm test
pnpm typecheck
pnpm build| Env var | Default | |
|---|---|---|
PORT |
8080 |
|
DATA_DIR |
./data (/data in Docker) |
config.json (settings), state.json (tokens), and history.sqlite (activity and feed access). All are mode 600. |
UI_PASSWORD |
unset | Password for the web UI's sign-in page (and the JSON API). Set it: the UI holds your Discord tokens. Changing it signs everyone out. |
DISABLE_AUTH |
false |
Set to true to turn off the sign-in page and the API's basic auth, when a reverse proxy in front of Understudy handles sign-in instead (see Behind an authenticating proxy). UI_PASSWORD is then ignored. |
PUBLIC_URL |
request origin | The URL you open the UI at, if that differs from what the server sees (e.g. behind a reverse proxy). Used for the OAuth redirect URI, and, if it's public HTTPS, for the optional artwork proxy. |
TZ |
system zone | Default Hub time zone for quiet hours and daily totals (e.g. America/Chicago). Set it in Settings → Hub rules; outputs can override their schedule. |
NXAPI_AUTH_CLIENT_ID |
unset | Default nxapi-auth client ID for the Nintendo Switch source. |
LOG_LEVEL |
info |
debug, info, warn or error |
If a reverse proxy (Authelia, Authentik, oauth2-proxy, Cloudflare Access, …) already signs you in,
set DISABLE_AUTH=true so you don't also need the UI password. Understudy then trusts every request
that reaches it, so make sure only the proxy can reach it: don't publish its port to the host or
network.
Let these paths through the proxy without sign-in. They carry their own signatures or tokens:
/public/for artwork Discord loads, webhooks, and the calendar and JSON feeds;/feed/history.icsand/api/history.json(older feed links);/healthzif something monitors it.
For the JSON API, use whatever credentials your proxy accepts instead of the UI password.
- In the Developer Portal, create an application. Its icon doesn't matter; the activity name comes from the source (e.g. "Plex").
- Discord Social SDK → Getting Started: fill in the form and submit. Without this, login fails
with
invalid_scope. - OAuth2: turn on Public Client, and under Redirects add the URI shown on the Discord
page of this app (
<your UI URL>/plugins/discord/callback). - In the web UI: Discord → paste the Application ID → Save → Connect Discord.
If the redirect page can't load (e.g. you registered localhost but opened the UI from another
machine), copy the URL from the address bar and paste it into "Redirect page didn't load?".
Things to know:
-
One activity at a time. When several sources are active, the Hub picks one using the source order on Overview (drag to reorder, or use Move up/down on the gripper), then the most recent.
-
Paused activities are hidden by default, like Spotify's integration. Settings → Hub rules can rank them last or show them instead. Discord can use its own paused-media and schedule rules.
-
By default the activity is shown only while one of your real Discord clients (desktop, web or mobile) is online, idle or dnd ("Only while you are on Discord"). This keeps one extra Discord connection open with your login.
- That connection carries the activity, with the same status as your real clients.
- It's invisible whenever there's nothing to show, so others see exactly the status they would without this app.
-
With that turned off, the activity is published as a headless session instead, which works with Discord closed. The catches:
- a headless session makes you appear online, even while Invisible;
- Discord doesn't really delete one when asked: it lingers, holding you online with no activity, for a few minutes afterwards.
-
Quiet hours (Settings → Hub rules): daily times when nothing is shown, e.g.
23:00-07:00, in the configured time zone.
The sidebar has Pause for 1 hour, with other durations: 30 minutes, 4 hours, or until you resume. While paused, the Discord output withdraws the activity. A pause survives restarts and ends by itself when timed. To stop a single source or output, turn off its Enabled switch.
The same controls are available as a JSON API, using the UI password as HTTP basic auth (any
username). POST requests must send Content-Type: application/json, which keeps them safe from
cross-site forgery.
curl -u :PASSWORD http://localhost:8080/api/status # pause state and every source/output
curl -u :PASSWORD -X POST -H 'Content-Type: application/json' -d '{"minutes": 60}' http://localhost:8080/api/pause
curl -u :PASSWORD -X POST -H 'Content-Type: application/json' -d '{}' http://localhost:8080/api/resume
curl -u :PASSWORD -X POST -H 'Content-Type: application/json' -d '{}' http://localhost:8080/api/toggle/api/pause without minutes pauses until resumed. For example, a Home Assistant
rest_command that pauses while you're at a lecture:
rest_command:
understudy_pause:
url: http://understudy.local:8080/api/pause
method: post
username: ha
password: !secret understudy_password
content_type: application/json
payload: '{"minutes": 75}'On the Plex (Tautulli) page, set:
- the Tautulli URL and API key (Tautulli → Settings → Web Interface → API);
- Users: your Plex username. Otherwise anyone streaming from your server shows up as you.
Discord loads artwork itself, so images must be public HTTPS URLs. In order:
- TMDB posters for movies and shows, using the shared TMDB API key or read access token in Settings.
- iTunes album art for music (no key needed).
- Optionally, Plex artwork served through this app. This needs
PUBLIC_URLto be an HTTPS address Discord can reach. Only signed image URLs under/public/work without the UI password. - A fallback image: a URL, or the key of an image uploaded to your Discord app (Developer Portal → Rich Presence → Art Assets).
The text lines are templates, e.g. S{seasonPadded}E{episodePadded}[ · {episodeTitle}]. Text in
[brackets] is dropped when a variable inside is empty. The settings page lists every variable.
The buttons can link to the item's public Plex page ("View on Plex": watch.plex.tv for movies
and TV, listen.plex.tv for music) and to IMDb (or TMDB). The Plex page is only known for items
matched by Plex's own agents. Episodes link to the episode page when Plex numbers the episode the
same way your library does, and to the show's page otherwise.
On the Jellyfin / Emby page, set:
- the Server type;
- the Server URL (e.g.
http://jellyfin:8096, with your base URL if you set one; for Emby, leave off/emby) and an API key (Jellyfin: Dashboard → API Keys; Emby: Settings → API Keys); - Users: your username. Otherwise anyone playing from your server shows up as you.
Movies, episodes and music are shown, plus music videos and audiobooks. The activity is named after
the server type ("Watching Jellyfin") unless you set a name. Use Clients or devices to only show
some apps (e.g. Finamp) or devices (e.g. Living Room TV).
Artwork works as for Plex: TMDB posters (with the shared key in Settings), iTunes/Deezer album art, optionally the
server's own images served through this app (needs an HTTPS PUBLIC_URL), then a fallback image.
The text lines are templates too; the settings page lists every variable.
Trakt shows what you're watching in anything that scrobbles to it: Infuse, Kodi, browser extensions for streaming sites, and so on. You need your own Trakt API app:
- Create an API app on Trakt. This needs a verified
GitHub account connected to Trakt. Name it anything. For Redirect URI enter
urn:ietf:wg:oauth:2.0:oob; this app signs in with a code, so it never redirects anywhere (Trakt may warn that it isn't an https address; that's fine here). - On the Trakt page of this app, enter the app's Client ID. The client secret is optional; Trakt has deprecated it.
- Then either:
- Public profile: set Trakt username to the name in your profile URL
(
trakt.tv/users/<name>). Nothing else is needed. - Private profile: choose Connect Trakt, open the link shown and enter the code. The page updates once you've approved it. Leave the username empty to show the connected account. Tokens are renewed automatically; Disconnect revokes and deletes them.
- Public profile: set Trakt username to the name in your profile URL
(
Trakt is polled every 30 seconds by default, and the progress bar follows Trakt's own start and end times. Trakt has no paused state: when you pause, your player stops scrobbling and the activity goes away. When Trakt limits requests, polling waits as long as it asks.
Trakt doesn't allow its own images to be hotlinked, so posters come from TMDB using the shared TMDB API key or read access token in Settings, then from the fallback image. The buttons can link to IMDb (or TMDB) and the Trakt page. The text lines are templates, as for Plex.
The TMDB credential is shared across Plex, Jellyfin/Emby, and Trakt. Existing per-source keys are migrated automatically: the first nonempty key in source order is used unless a shared setting already exists. Replace or remove it in Settings → Shared artwork.
Anything that scrobbles (Apple Music, YouTube Music, Tidal, Plexamp, a car stereo…) can show as "Listening to Last.fm". On the Last.fm / ListenBrainz page, choose the Service and set:
- Last.fm: your username and an API key. Create one at https://www.last.fm/api/account/create; any name will do, and the callback URL can stay empty. Your recent listening must be public (Last.fm → Settings → Privacy).
- ListenBrainz: your username. A user token (listenbrainz.org → Settings) is optional; it's sent with each request if you set it.
Neither service says when a track started, so the elapsed time counts from when this app first saw it (up to one poll interval late). A progress bar is shown only when the track's length is known (ListenBrainz usually sends it; for Last.fm it's looked up once per track) and the app saw the track start. Both services keep reporting a track for a while after you stop playing, so a track is hidden 2 minutes after it should have ended, or, if its length isn't known, after Hide after minutes.
Artwork, in order: Last.fm's own image, the Cover Art Archive (when the track has a MusicBrainz release id), iTunes/Deezer album art (no key needed), then the fallback image.
If Plex or Jellyfin music also scrobbles (e.g. Plexamp to Last.fm), both sources report the same track. The Hub selects one using the source order on Overview; put the one you prefer higher.
Nintendo's API doesn't let you read your own presence, so this reads it from the friend list of a secondary Nintendo Account that is friends with your main one. You need:
-
A secondary Nintendo Account, added as a friend of your main account. Your main account must share its online status with friends (on the Switch: System Settings → Users → your user → friend settings).
-
An nxapi-auth client ID. It identifies this app to nxapi's f-token API. Register once at https://nxapi-auth.fancy.org.uk/oauth/clients:
- Type: Public. You can't change this later.
- Allowed grant types: Client credentials and Refresh token.
- Scope: in the nxapi-znca-api section, only f-generation, Request encryption and Response
decryption (
ca:gf ca:er ca:dr). Leave every other scope, and the client authentication section, alone. - Details: fill in a description and a contact URL.
Enter the Client ID on the Nintendo Switch page, or set
NXAPI_AUTH_CLIENT_ID. It isn't a secret. -
Sign in on the Nintendo Switch page:
- Read and accept the notice.
- Open the sign-in link and sign in with the secondary account.
- Right-click Select this person, copy the link (
npf71b963c1b7b6d119://auth#…) and paste it back. - Pick your main account from the friend list.
Privacy: Nintendo only accepts sign-ins from its own app. To sign in, this uses nxapi-znca-api, a third-party service. Your secondary account's Nintendo Account id_token, its Coral token, and data exchanged with Nintendo's Coral API are sent to that service. nxapi also loads its configuration from fancy.org.uk. Nothing is contacted until you accept the notice. See what this means for you. The integration follows the service's terms for clients.
Presence is polled every 60 seconds by default. Games show as "Playing Nintendo Switch" (or
"Nintendo Switch 2"), with the game's icon and, if the game provides one, its status text.
After a network error polling backs off and continues, and it waits as long as nxapi-znca-api asks
(Retry-After). Any other error stops polling until you choose Try again on the Nintendo
Switch page, because the service's terms forbid other automatic retries.
This shows what Steam says you're playing, so games on a Steam Deck in Game Mode (where Discord isn't running) still show up. On the Steam page, set:
- a Steam Web API key from https://steamcommunity.com/dev/apikey. Any domain name will do. Steam may refuse keys to limited accounts (ones that have never spent money in the store).
- Steam profile: your SteamID64, your profile URL (
steamcommunity.com/profiles/…or/id/…), or just your custom URL name.
Steam only reports your game if your profile's Game details are visible to the account the key belongs to. Public (Steam → your profile → Edit Profile → Privacy Settings) is what's known to work; My profile must be public too, since Game details can't be more public than it. If you're Invisible or Offline on Steam, your game isn't shown either. Test connection warns when Steam says the profile isn't visible.
Steam is polled every 30 seconds. Games show as "Playing Steam" (or whatever you set as the activity name, e.g. "Steam Deck"), with the game's store header image and, optionally, a "View on Steam" button. Non-Steam games added to Steam show by name, with the fallback image.
Playing on a PC that runs Discord? Then Discord already shows the game itself, and this would
show it a second time. Add those games to Ignore games (by name, or by the app id from the store
URL, e.g. 1145360 from store.steampowered.com/app/1145360/), so only games played elsewhere
(like on the Deck) come from here.
- The Discord page shows a session list. Open "Your Discord clients" to see every session Discord reports: your clients, this app's connection, and any headless session. It's the quickest way to see why something is or isn't shown. Changes are also logged (see Log).
- Shown as online after closing a browser tab. Discord keeps a web client's session for a while after the tab closes, so Understudy keeps showing your activity until Discord drops it. The desktop app disconnects cleanly.
- Nothing shows while you're Invisible. That's deliberate: showing an activity would reveal that you're online.
invalid_scopewhen connecting Discord. Enable the Social SDK for your app (see Discord setup).
The Overview follows Sources → Hub → Outputs. All source activity is recorded, including
activity that loses priority or is hidden by paused-media and quiet-hour rules. Outputs call
ctx.reportShown(activity | null) after a successful send or clear; Displayed totals count the
union of those output intervals, including paused activity that was actually shown, so two outputs
showing activity do not double-count the time.
Today’s watching, listening, and playing totals count active time, excluding paused source segments and counting overlapping observations once per kind. Intervals are clipped to the local day in the Hub’s time zone. Different kinds count independently when they happen at the same time.
The Calendar page shows a week at a time in the Hub’s time zone. Back-to-back items from one source (an album, a binge, a game night) are combined into one block; a green rail marks when an output showed something. Pick a day for its agenda, where combined blocks list every item.
History sources copy past or background activity from another service into your history. They appear in the Calendar and the totals, but never feed the Hub, so no output shows them live. They have their own card on the Overview.
- Calendar (iCal): paste a calendar's secret iCal address (Google Calendar: Settings → your calendar → Secret address in iCal format). Timed events from the last 30 days (adjustable) are imported and kept in step every 30 minutes, including recurring events, moved and cancelled occurrences. All-day events are left out: they aren't time spent on something. Calendar events aren't counted in the watching/listening/playing totals.
- Discord status: records what your own Discord clients show: games Discord detects on your PC, Spotify, and apps with their own Discord status. It uses the Discord output's connection, so connect Discord there first (it works in either Discord mode). Use Ignore apps for anything another source already records, such as Spotify when Last.fm is set up.
Removing a history source also deletes what it imported.
Activity never goes back to the service it came from.
- Events imported from a calendar never appear in a Calendar feed, and Understudy's own feed events are skipped when importing. So you can subscribe to the feed in the same Google Calendar you import, without anything looping.
- Statuses recorded from Discord never appear on the Discord output, and Understudy's own Discord activity is never recorded as your status.
Plugins declare the outside service they talk to; the registry keeps a history source's entries
away from outputs for the same service (see src/core/plugin.ts).
Feeds are outputs: add Calendar feed or JSON feed under Outputs (or from Settings). Each has its own secret link on its page, which works only while that output is enabled; Create a new link revokes the old one. Anyone with a link can read what it publishes; treat it as a password.
- Calendar feed (
/public/<id>/calendar.ics?token=…): events with stable UIDs. Choose everything sources saw or only what outputs showed, which kinds, whether to combine back-to-back items, and how many days to include. - JSON feed (
/public/<id>/history.json?token=…): source segments, each with itssourceLabeland, for history sources, itsorigin, plus output segments. Optionalfrom/toquery parameters accept ISO dates or epoch milliseconds;sourceIdfilters one source.
Links from before feeds were outputs (/feed/history.ics and /api/history.json) keep working
once you add the matching feed: its first instance adopts the old token.
History defaults to 90 days of retention, adjustable in Settings. A 15-second heartbeat closes segments interrupted by a crash at the last observed time on the next start, so downtime is not counted. A normal shutdown closes them immediately. Back up the data directory with the service stopped. Warn/error logs remain a 500-entry memory buffer; dismissing them persists a timestamp, and active instance warnings continue to appear after dismissal.
Existing Discord source priority, paused-media, quiet-hour, and time-zone settings migrate
automatically to source order and the top-level hub configuration. Different legacy schedule
rules are preserved as output overrides. Reordering and rule-only saves do not restart sources
or outputs; changes to plugin settings reconnect the affected instance.
src/
core/ activity model, selection hub, plugin interfaces, registry, JSON/SQLite stores, logger
plugins/ sources, history sources and outputs; register new ones in plugins/index.ts
discord/ OAuth (PKCE), REST client, headless session, activity mapping, publisher; Discord status history source
ical/ Calendar (iCal) history source: fetching, recurrence expansion, time zones
feeds/ Calendar feed and JSON feed outputs: secret links, iCalendar text
tautulli/ Plex via Tautulli: polling, filters, templates, artwork (TMDB, iTunes, signed proxy)
jellyfin/ Jellyfin and Emby: session polling, filters, templates, artwork (TMDB, iTunes, signed proxy)
trakt/ Trakt: watching polls, device-code sign-in with token refresh, templates, TMDB posters
scrobbler/ Last.fm / ListenBrainz now playing: polling, first-seen timing, artwork (Cover Art Archive, iTunes)
nintendo/ Nintendo Switch via nxapi: consent, sign-in, friend picker, presence polling
steam/ Steam via the Web API: profile resolution, presence polling, store artwork
shared/ helpers used by several sources: TMDB posters, album art, Retry-After, timestamp smoothing
manual/ the hand-driven test source
core/controls.ts app-wide pause; core/schedule.ts quiet-hour windows
web/ Hono + JSX server-rendered UI with htmx, and settings forms built from zod schemas
A source calls ctx.publish(nowPlaying | null). A history source (defineHistorySource)
writes to ctx.history instead: observe(items) for what a service shows right now, or
importEntries(window, entries) for entries copied from elsewhere; it never reaches the Hub. An
output gets onState(hubState) with
selected and selectionReason, alongside every source’s current activity. An output can call
ctx.reportShown(sourceActivity | null) to record what it has sent, and read history through
ctx.history, with the no-echo rule already applied. Plugins call
ctx.reportSuccess() after successful polls or connection tests. A plugin declares its settings as a zod schema, which also
generates its settings form. Plugins can add their own routes (under /plugins/<instance>/,
behind the UI password), public routes (under /public/<instance>/, for images and webhooks; they
must authenticate requests themselves) and UI panels. A configured instance restarts when its plugin settings change. Form presentation comes from
schema metadata: group, widget (chips, segmented, template), showIf, disabledIf,
templateTab, and variables. Tailwind v4 scans all src/**/*.tsx files, including plugins; the
palette is defined in src/web/styles.css with @theme. Lucide/Simple Icons render SVGs on the
server, and fonts, htmx, SortableJS, and the small enhancement script are served locally.