---
title: Contributions
description: What a plugin adds to the app, declared in its definition, what each contribution looks like, and what the host does for it.
---

A plugin declares what it adds beside its `pages`, keyed by id. The host lists every contribution without running the plugin. While the plugin is enabled and its `activate` has returned, each contribution is live. Disabling the plugin removes them all.

| Key | Shows up as |
| --- | --- |
| `titleTabs` | A tab in a title's inspector |
| `links` | Opens a pasted, dropped or deep-linked URL, or one opened from ⌘K |
| `search` | A group of results in ⌘K |
| `addFrom` | A row in the title bar's **+** list that opens the page you add things from |
| `clipSources` | A section of outside clips in clip search |
| `songActions` | An action on an identified song |
| `sources` | A place a title or album plays from or downloads from: a row in a title's Sources tab, the title card's Play, and album downloads |
| `shelves` | Picks in a title's Similar to panel |
| `episodePanels` | A row in a podcast episode page's header |
| `episodeTranscripts` | A transcript on a podcast episode's page, when its feed has no timed one |
| `podcastImports` | An "Import from …" button on Podcasts › Following |
| `games` | How one of the plugin's games is downloaded to this Mac |
| `commands` | An action keys, links, scripts and the CLI run by id |
| `remote` | Lists in the phone remote's Library, and the pages the phone may play on the Mac |

Pages are declared in the [manifest](/docs/plugins/manifest#pages) and listed in the sidebar with `area`.

Contributions with a `service` stay hidden, or show a not-set-up state, until that service is ready. Where the host shows a failure (a command a link ran, a song action, an album source, a download or a game's fetch), a `PluginFailure` is shown as its message and any other error gets the host's own words. A remote section's `load` or a search that throws is logged and left out.

Write a label as `phrase('Films').source` to put it in your [catalogs](/docs/plugins/manifest#translations): the host shows title tab, episode panel, song action, search group, `addFrom` and remote section labels in the user's language. Do the same for a `PluginFailure`'s message, `new PluginFailure(phrase('VPN is off').source)`, and an album source's, a download's or a game's failure is shown from your catalog. See [failures](/docs/plugins/api#failures) for when to translate one yourself. A message your catalog doesn't list, such as a service's own error text, is shown as written.

## api and api.state

Every function in a contribution gets the plugin's [`api`](/docs/plugins/api) as its last argument. `activate` is optional setup. What it returns is `api.state`, typed by inference:

```ts
definePlugin(manifest, {
  activate: api => ({ playlist: playactorPlaylist(api) }),
  songActions: {
    add: {
      service: 'spotify',
      label: { run: 'Add to Spotify', undo: 'Remove from Spotify' },
      isDone: (song, _context, api) => api.state.playlist.has(song),
      run: (song, api) => api.state.playlist.add(song),
      undo: (song, api) => api.state.playlist.remove(song),
    },
  },
})
```

- Write `activate` before the contributions. TypeScript infers left to right, so a contribution written above an `activate` that reads `api` sees no state and doesn't compile.
- An async `activate`'s state is what it resolves to.
- Without `activate`, `api.state` is `undefined`.
- Don't pass type arguments to `definePlugin`: TypeScript has no partial inference, so naming any of them drops `api.state` to `undefined`.

The host runs `activate` once per enable. A contribution is only called after it has returned, always with that activation's `api`.

## titleTabs

A title tab sits beside Similar to. Once a title has two or more of them, they share one **Discover** tab, with a switch between them inside it. The host runs `load`, caches it under the plugin's key, shows the count on the tab, and renders loading, empty and failure. Your component only gets a non-empty `data`, typed as what `load` returns; a component that takes anything else doesn't compile.

```tsx
titleTabs: {
  podcasts: {
    label: phrase('Podcasts').source,
    applies: title => title.kind === 'movie',       // every title when absent
    load: (title, { signal }, api) => podcastsForTitle(api, title, signal),
    component: ({ data }: TitleTabProps<Episode>) => <EpisodeList episodes={data} />,
  },
},
```

Type an inline component's props, as above, or pass a named one. TypeScript can't carry `load`'s type into unannotated props, so they get `unknown`, and that plugin's tabs whose `load` reads `api` go unchecked.

`title` is `{ id, kind, title, year, tmdbId, episode }`. `kind` is one of `movie`, `series`, `episode`, `video`, `home`, `album`, `track`, `book`, `audiobook`, `ebook`, `podcastEpisode`, `clip`, `unknown`. A `clip` title (`clip:<clipId>`) is a clip's own: its name, notes and favorite. `episode` is null except on an episode, where it is `{ show: { title, tmdbId }, season, number }`, numbered as TMDB numbers them; `title` is then the episode's own name.

## links

Return a page target for URLs the plugin owns, `null` for the rest. ⌘V outside a text field, a dropped link and a deep link all go through it. `playactor://link?url=https%3A%2F%2Fyoutu.be%2FdQw4w9WgXcQ` opens the page of the plugin that claims the URL, and Watch › Web when none does.

```ts
links: {
  video: {
    resolve: url => {
      const videoId = parseYoutubeVideoId(url.href)
      return videoId ? { page: 'video', params: { videoId } } : null
    },
  },
},
```

## search

A group of results in the ⌘K palette. The host caches, ranks and caps it at three. Its context has the app's `language`: write subtitles in it, with [`api.text<Messages>(language)`](/docs/plugins/api#apitext) for words and `toLocaleString(language)` for numbers. The host caches results per language, and shows `label` from your catalog when it's written as a `phrase`.

```ts
search: {
  videos: {
    label: 'YouTube',
    search: async (query, { signal }, api) =>
      (await youtube(api).search(query, signal)).map(video => ({
        id: video.id,
        title: video.title,
        subtitle: video.channel,
        thumbnailUrl: video.thumb,
        open: { page: 'video', params: { videoId: video.id } },
      })),
  },
},
```

## addFrom

A row in the list the title bar's **+** opens before you type, after **Files on this Mac…** and **A watch folder…**. It shows `label` with the plugin's sidebar icon and opens `open`, a page you declared. You pick there, and the page's Add calls [`api.app.library.add`](/docs/plugins/api#apiapp). `open` is typed by your manifest's pages, so a misspelled page doesn't compile.

```ts
addFrom: {
  photos: { label: 'Photos', open: { page: 'library' } },
},
```

It needs the release after 0.2.24; an older app ignores it.

## remote

What the [phone remote](/docs/remote) shows of the plugin: sections in its Library, and the pages a tap on the phone plays on the Mac. No plugin code runs on the phone. The Mac calls `load` with the plugin's `api` and the phone draws the items.

```ts
import { z } from 'zod'

definePlugin(manifest, {
  remote: {
    players: ['stream', 'video'],
    sections: {
      live: {
        label: phrase('Live').source,
        layout: 'live',
        requires: 'twitch',
        load: async ({ signal }, api) => ({
          items: (await liveStreams(api, signal)).map(stream => ({
            id: stream.login,
            title: stream.name,
            art: { url: stream.thumbnailUrl, aspect: 'wide' },
            live: true,
            send: { page: 'stream', params: { login: stream.login } },
          })),
          next: null,
        }),
      },
      channel: {
        label: phrase('Channel').source,
        layout: 'row',
        listed: false,
        requires: 'twitch',
        params: z.object({ login: z.string() }),
        load: ({ params, cursor, signal }, api) => channelVideos(api, params.login, cursor, signal),
      },
    },
  },
})
```

- `players` are the manifest pages that play something. The host reads them without running the plugin. An item's `send` names one of them, typed by its params; a page that isn't listed doesn't compile, and the Mac refuses it from the phone.
- A link the plugin's `links` resolves to a player opens that page when the phone sends the link. A link it resolves to any other page plays in Watch › Web.
- Each item either has `send`, which plays on the Mac, or `open: { section, params }`, which opens another of the plugin's sections on the phone. `params` are parsed by that section's `params` schema before `load` runs, and `load` gets the parsed value. When the params don't parse, the Mac refuses the load and `load` never runs.
- `layout` is one of `poster` and `square` (grids), `row`, and `live` (rows with a live marker). `art.aspect` is `poster`, `square` or `wide`; art is an `https://` URL.
- `listed: false` makes a drill-in: it is reached only through an `open`, never listed in Library.
- `load` gets `cursor`, which is null for the first page and then the `next` it returned. Return `next: null` on the last page. The cursor is the plugin's own string.
- `load` gets `language`, the Mac's UI language as a tag such as `fr` or `pt-BR`. The phone shows the page in it, so format dates and durations with it. Its words come from the plugin's catalog through [`api.text<Messages>(language)`](/docs/plugins/api#apitext), as in `t('{{count}} viewers', { count })`. Cache what a service returned, not the rows written from it, so a cached page is written again in the next load's language. A page whose load the language changed under is loaded again in the new one.
- `load` and `search` have 7 seconds. After that the section reads as not loaded and the search group is left out, whether or not the plugin stopped on `signal`; what it returns later is dropped.
- A section with `requires` is left out until that service is set up.
- Sections are listed under the plugin's sidebar area, in the order declared. A plugin with no area is listed under its name after the sidebar.
- The phone's Search includes the plugin's `search` groups, keeping only results whose `open` is one of its `players`.

## clipSources

A section under the Movies & TV clips page's own results when it is searched. Every source gets the same `ClipQuery` (`text`, `actor`, `director`, `years`, `durationSec`, `sort`, `order`) and ignores what it can't use; the page sets `years` from its decade and never sets `durationSec`. Each hit hands over its mp4 as bytes: the host plays them for the preview and saves the same bytes when the user adds the clip. See [Your first plugin](/docs/plugins/quickstart) for a full one.

## songActions

An action on each row of a title's Songs tab, on the "What's playing" card, and beside the song a live stream names in the audio bar. The host owns the busy state, the done state, "Add all" and the failure toast. The example under [api and api.state](#api-and-apistate) is Spotify's.

`song` is `{ title, artist, isrc }`; a live stream's song has no `isrc`. Without `undo`, a done action can't be clicked.

## sources

A place the host gets things from: a movie, episode or album to play now or download. `find` answers what's wanted with options, best first. An option with `stream` plays now; one with `payload` downloads through `fetch`. One option can carry both. The host owns the rest: the title page's list, landing a stream as a version, and a download's request, folder, progress, cancel and import.

```ts
sources: {
  // Plays only.
  tubi: {
    label: 'Tubi',
    service: 'tubi',
    kinds: ['movie', 'episode'],
    find: (wanted, { country, signal }, api) =>
      wanted.kind === 'album' ? [] : findOnTubi(api, wanted.title, { country, signal }),
  },
  // Streams albums track by track.
  music: {
    label: 'YouTube Music',
    service: 'youtubeMusic',
    kinds: ['album'],
    find: (wanted, { signal }, api) =>
      wanted.kind === 'album' ? findAlbum(api, wanted.release, signal) : [],
  },
  // Plays and downloads: a film's file, an album's tracks.
  archive: {
    label: 'Internet Archive',
    service: 'archive',
    kinds: ['movie', 'album'],
    find: (wanted, { signal }, api) =>
      wanted.kind === 'album'
        ? findAlbumOnArchive(api, wanted.release, signal)
        : findOnArchive(api, wanted.title, signal),
    fetch: (option, context, api) =>
      AlbumPayload.safeParse(option.payload).success
        ? downloadAlbum(api, option, context)
        : downloadFile(api, option, context),
  },
},
```

`wanted` is one of:

```ts
{ kind: 'movie' | 'episode', title: TitleFacts }      // the same TitleFacts a title tab gets
{ kind: 'album', release: ReleaseFacts, profile: MusicProfile }
```

`release` is the MusicBrainz release the library would hold: its `mbid`, `title`, `artistCredit`, `year`, `lengthMs`, and `tracks`, each with its `disc`, `position`, `title`, `lengthMs` and `recordingMbid` (null when the release doesn't list one). `title.episode` places an episode in its show; `title.imdbId` and `title.runtimeMinutes` are there when the library knows them, so a source can tell the film from its trailer. `country` is where this device is, lower-case ISO 3166-1 (`us`), from **Settings › General › Streaming**.

A source's key names where its streams are, so it is lower-case with dashes (`music`, not `youtubeMusic`).

`find` returns its options, or, when they come in parts, an async iterable of snapshots. Each snapshot is the whole answer so far and replaces the one before. The page shows each as it lands and reads **Searching…** until the last. Only an answer that ran to its end is cached; one cut off (the page closed) is asked again next time. A source over several indexes yields after each one answers, so a slow one never holds back a fast one:

```ts
async *find(wanted, { signal }, api) {
  const quick = await askQuickIndex(api, wanted, signal)
  yield quick
  yield [...quick, ...(await askSlowIndex(api, wanted, signal))]
}
```

Throw only when nothing answered. A failure is an error on the page, never "nothing here".

An option:

```ts
{
  id: 'Night.Of.The.Living.Dead_1080p/NightOfTheLivingDead_PS3.mp4',
  label: '',                  // what sets it apart from the source's other options; empty when nothing does
  detail: { height: 1080, videoCodec: 'h264', audioCodec: null, sizeBytes: 1_862_510_336, durationSeconds: 5753 },
  stream: {                   // a WebSource the host's player plays through yt-dlp
    ref: { ns: 'archive', id: 'Night.Of.The.Living.Dead_1080p/NightOfTheLivingDead_PS3.mp4' },
    url: 'https://archive.org/download/Night.Of.The.Living.Dead_1080p/NightOfTheLivingDead_PS3.mp4',
    meta: { title: 'Night of the Living Dead', durationSeconds: 5753 },
  },
  payload: { id: 'Night.Of.The.Living.Dead_1080p', file: 'NightOfTheLivingDead_PS3.mp4' },
}
```

A video's `detail` can also carry `fileCount` (a torrent's); the host fills null where a source leaves it out. An option says how soon it would download with `availability`: `{ kind: 'peers', seeders }` for a torrent, or `{ kind: 'slot', free, queue, bytesPerSecond }` for a peer's upload slot (Soulseek's). Leave it out when the option always downloads, as a file a service serves does. The host's offers list ready options first, then waiting ones, each by its own measure: seeders, or a free slot's speed, or a queue's length. An album's `detail` is the folder's quality instead (`fileCount`, `format`, `bitrate`, …), and the host judges a download against the user's profile. The host stamps each option's `detail.kind`, `'video'` or `'audio'`, as it takes the answer, so a source may leave it out. An album's `stream` is its tracks, each a release track and the `WebSource` that plays it; leave out a track you couldn't match:

```ts
{
  id: 'MPREb_1SbgcDGdrT4',
  label: '',
  detail: { format: 'm4a', bitrateKbps: 128, vbr: false, bitDepth: null, sampleRateHz: 44100, fileCount: 11, sizeBytes: null },
  stream: {
    tracks: [
      { disc: 1, position: 1, source: webVideoSource({ extractor: 'Youtube', id: 'SLlYUlS_Awo', url: 'https://music.youtube.com/watch?v=SLlYUlS_Awo', meta: { title: 'Second Hand News', durationSeconds: 177 } }) },
      // …
    ],
  },
}
```

To pair a service's tracks with the release, `matchTracks(release.tracks, candidates)` from `@playactor/plugin` takes each candidate's `{ title, durationSeconds }` and returns, per release track, the index of its candidate or null. A track pairs by title (remaster notes, case and punctuation aside) when its length is within 15% (at least 10 s) or unknown; failing that, by its place when the length agrees within 3 s. A live recording of the same song is usually longer than that, so a concert doesn't pass for the album. YouTube Music and Internet Archive both pair through it, and offer an album only when at least half its tracks paired.

Return only what yt-dlp can play as a `stream`: skip a title the service serves only with DRM. Throw when you can't tell. The host never reads a failure as "not there any more"; an empty answer is.

### On the title page

A movie's or an episode's page asks each source whose `kinds` include the title's kind. Its Sources tab lists every option with Play and, when the source has `fetch`, Download. A source whose options only download (the app's own Torrents among them) is one row instead, its count and **Download**, which opens the title's offers; an option whose stream is already one of the title's versions (by its `ref`) is listed as that version, not again. When nothing plays on this device, the card's Play takes the tallest stream, ties to the earlier plugin. Playing adds the title to the library (an episode's show, with every episode) and records the stream as one of its versions; from then on it plays from there like any other file. Downloading adds the title too and files what `fetch` wrote as a version of it.

The host caches each complete answer for a day, per title and country, under the plugin's key. Once a stream is played, the host asks `find` again in that stream's country when it was last confirmed over a day ago: when the title's page opens, and in the background, a few titles an hour, the longest unconfirmed first. If the answer no longer has the stream's `ref`, the title stops playing from it. Its clips keep their files.

### On an album's offers

An album's offers ask each source whose `kinds` include `album`. Streams come first, each with **Play**; the profile never hides one, since it says what to keep, not what to play. Playing adds the album and its tracks to the library and records each streamed track as an audio file there; the host fetches a track's audio through yt-dlp as it plays, so it plays gapless and clips like a file. Downloads follow in the host's offers picker, folded by the profile, each source's rows as it answers. YouTube Music streams albums and downloads them (AAC, which the default profile folds); Internet Archive streams and downloads them, in FLAC and MP3, from the items that name the MusicBrainz release first, then from items titled as it by its artist.

### fetch

```ts
fetch: async (option, { write, progress, signal }, api) => {
  const response = await api.services.archive.fetch(downloadUrl(option.payload), { signal })
  return [await write('notld.mp4', counted(response.body, progress))]
}
```

`dir` is a folder in the user's Downloads named for the title or album (`Artist - Album`). A fetch run again for the same request gets the same folder, with whatever the earlier attempt wrote still in it. `write(name, body)` streams a response body to `dir/name` and returns its path; `name` is one file name, no folders. A source with a native half writes under `dir` itself. Return the paths written; for a movie or episode, the first video among them becomes the title's version.

`progress` takes `{ doneBytes, totalBytes, rateBps }`, as often as the source likes; the host paces its writes. Add `files` when the source can say how far each file is, and Downloads lists them under the album, each named by the release's track it is:

```ts
progress({
  doneBytes: 43_000_000,
  totalBytes: 250_000_000,
  rateBps: 1_200_000,
  files: [{ path: 'CD1/01 - The Rainbow.flac', bytes: 31_457_280, doneBytes: 12_582_912 }], // path relative to dir
})
```

A file whose `path` is absolute or climbs out of `dir` is left out.

`saveWebAudio(url, name, tags)` saves a web page's audio, a YouTube Music track's, as `dir/name`, and returns its path. The host resolves it with its own yt-dlp (AAC where the site has it), copies it from the player's cache when the track already played, and writes `tags` into the file before it takes its name; the bytes never pass through the plugin, and `signal` cancels it. `name` is one file name, as `write`'s. The album import matches files by their tags and length, never by name, so tag every track:

```ts
fetch: async (option, { saveWebAudio, progress, signal }) => {
  const { album, tracks } = albumPayload.parse(option.payload)
  const saved = []
  for (const [i, track] of tracks.entries()) {
    signal.throwIfAborted()
    progress({ doneBytes: i, totalBytes: tracks.length, rateBps: 0 })
    saved.push(
      await saveWebAudio(track.url, `${track.disc}-${String(track.position).padStart(2, '0')} ${track.title}.m4a`, {
        title: track.title,
        artist: album.artist,
        album: album.title,
        disc: track.disc,
        track: track.position,
        mbReleaseId: album.mbReleaseId,  // optional
        mbRecordingId: track.mbRecordingId, // optional
      })
    )
  }
  return saved
}
```

The request stores the option whole: its `id`, `label`, `payload` and `detail`, with the `kind` the host stamped and a video's `fileCount`. After a restart the host calls `fetch` with it again; its `stream` and `availability` aren't kept.

## shelves

A shelf turns a seed into picks, best first. On a movie or show page, the Similar to panel asks every shelf whose `seeds` include `title` and whose `kinds` include `movie` or `series`. On an album page it asks every shelf whose `seeds` include `album` and whose `kinds` include `album` or `artist`, seeded by the album. TMDB's own "More like this" is a built-in shelf on the same contract; the built-in ListenBrainz plugin supplies the album page's two.

```ts
shelves: {
  related: {
    label: 'Related on Trakt',
    service: 'trakt',
    seeds: ['title'],
    kinds: ['movie', 'series'],
    load: async (seed, { signal }, api) => {
      if (seed.kind !== 'title' || seed.title.tmdbId == null) return []
      const related = await relatedTitles(api.services.trakt.fetch, seed.title, signal)
      return related.map(r => ({
        kind: 'title',
        id: TitleId.ofTmdb({ kind: r.kind, tmdbId: r.tmdbId }),
        title: r.title,
        year: r.year,
        posterUrl: r.posterUrl,
      }))
    },
  },
},
```

A seed is one of:

| `kind` | Carries |
| --- | --- |
| `title` | `title`: `{ id, kind, title, year, tmdbId, episode }` |
| `person` | `tmdbPersonId` |
| `album` | `album`: the title facts plus `music` (`artists`, `releaseGroupMbid`, `trackCount`) |
| `artist` | `artist`: `{ mbid, name }` |
| `none` | nothing |

A pick is one of:

| `kind` | Carries |
| --- | --- |
| `title` | `id` (a `TitleId`, from `TitleId.ofTmdb`), `title`, `year`, `posterUrl` |
| `album` | `releaseGroupMbid`, `title`, `artist` |
| `artist` | `artist` |

A title page shows title picks of TMDB movies and shows. An album page shows artist picks first, four of them, then album picks as rows, six of them, each with **See all**, under the page's **Similar** heading. An artist opens their page, an album its offers. No other page has the panel yet.

Two shelves of one plugin often need the same first request, as ListenBrainz's albums and artists both start from the seed's similar artists. Put that request in `api.queries.fetch` under one key and both loads share it, the second joining the first while it is in flight:

```ts
const similarArtistsOf = (api, mbid) =>
  api.queries.fetch({
    key: ['similar-artists', mbid],
    fn: ({ signal }) => similarArtists(api.services.listenbrainz.fetch, mbid, signal),
    staleTime: 10 * 60 * 1000,
  })
```

The host caches each shelf's picks per seed under the plugin's key, keeps them across restarts, and asks again after three days. Disabling the plugin clears them. Picks have no score: the panel takes each shelf's first pick in turn, then each one's second, and so on. A pick two shelves return shows once: a title by its `id`, an album by its release group, an artist by MBID. Titles the user owns, has watched or marked Not interested are dropped; one on the watchlist (or, for an album, the wishlist) is marked. Albums the library has (by release group) and albums or artists marked Not interested are dropped; an artist already in the library stays. A shelf whose `load` throws adds nothing, and the other shelves still show.

## episodePanels

A row in a podcast episode page's header, under the title, beside the panel's label; it folds away once the page scrolls. Keep it to a line or two, like the Podcasts plugin's small film posters. The host runs `load`, caches it under the plugin's key, and shows the panel only once `load` has found something: while loading, or when it returns nothing, the panel takes no room. When `load` throws, the panel says it couldn't reach the plugin, with the service's status link.

```tsx
episodePanels: {
  films: {
    label: phrase('Films').source,
    service: 'filmmap',
    load: (episode, { signal }, api) => filmsInEpisode(api, episode, signal),
    component: ({ data }: EpisodePanelProps<Film>) => <FilmGrid films={data} />,
  },
},
```

`episode` is what the feed says: `{ id, title, publishedAt, durationSec, enclosureUrl, show }`, with `show` as `{ id, title, author, feedUrl, itunesId, pocketCastsUuid }`. Feeds carry no outside ids, so a plugin that keys episodes its own way matches them itself. `episodeMatcher` in `@playactor/providers/podcasts` does it the way the Podcasts plugin does: by the audio file's URL without its query, then by title and day. It returns nothing when two episodes fit.

## episodeTranscripts

A transcript for an episode whose feed has no timed one (WebVTT, SubRip or JSON). The host asks each source in turn, under the plugin's key, and reads along with the first that returns one; the feed's own plain text comes after them. Return `null` when the source has none for the episode: the host moves on, and does the same when `load` throws.

```ts
episodeTranscripts: {
  pocketcasts: {
    label: 'Pocket Casts',
    applies: episode => episode.show.pocketCastsUuid !== null, // every episode when absent
    load: async (episode, { signal }, api) => {
      const cues = await generatedTranscript(api, episode, signal)
      return cues ? { timed: true, cues } : null
    },
  },
},
```

A transcript is `{ timed: true, cues }`, each cue `{ startSec, endSec, text, speaker }`, or `{ timed: false, text }` for plain text, whose timestamps still seek. `parseVtt`, `parseSrt`, `parseJsonTranscript` and `parsePlainTranscript` in `@playactor/providers/podcasts` read the usual files; a cue without a speaker of its own continues the last one's turn. The label shows beside the Transcript heading.

## podcastImports

An "Import from …" button on Listen › Podcasts. `shows` returns the shows another app subscribes to; the host does the rest. It looks each one up in Apple's directory and follows it when the title matches exactly, gives a show already followed the `pocketCastsUuid` it lacks, and lists the ones it couldn't find. Searches are spaced three seconds apart, so a long list takes a few minutes; it carries on if the user leaves the page.

```ts
podcastImports: {
  pocketcasts: {
    label: 'Pocket Casts',
    service: 'pocketcasts',
    shows: async ({ signal }, api) =>
      (await pocketCasts(api).getSubscriptions(signal)).map(show => ({
        title: show.title,
        author: show.author,
        pocketCastsUuid: show.uuid,
      })),
  },
},
```

## games

How one of the plugin's games is fetched, for [`api.app.games.download`](/docs/plugins/api#games-on-this-mac). There is one per plugin, so it isn't keyed. `fetch` gets what the page asked for and the same context a source's `fetch` does: write every file under `context.dir`, with `context.write` for a service response's body, report bytes through `context.progress`, stop on `context.signal`, and return the paths written. The host moves them into the game's folder under Games.

```ts
games: {
  fetch: async (wanted, context, api) => {
    const upload = uploadSchema.parse(wanted.payload)
    const response = await api.services.store.account.fetch(upload.url, {
      signal: context.signal,
    })
    return [await context.write(upload.filename, response.body)]
  },
},
```

`fetch` runs again from the stored `payload` after a restart, so keep in the payload what finds the file again (an upload's id), not a link that expires.

## commands

An action other apps run by id: a key bound in a keymap app, a `playactor://run/…` link, a script or `playactor run`. Use one for what a page link can't do, such as playing something without leaving the current page; to show a page, link to it.

```ts
import { definePlugin, param } from '@playactor/plugin'

definePlugin(manifest, {
  commands: {
    play: {
      title: 'Play a favorite station',
      focus: 'background',
      params: { station: param.string({ description: 'A name or id; the newest favorite when absent' }) },
      run: ({ station }, api) => playFavorite(api, station),
    },
  },
})
```

- The key is the command's name: a lowercase letter, then letters, digits or `-`. With a dot, `/`, `?` or `%` in it, `definePlugin` throws and the plugin fails to load.
- It is published as `p.<plugin>.<name>`, here `p.radio.play`, and listed under the plugin's name.
- `focus` is when it may run while Playactor isn't focused. `raise` brings the window to the front, then runs; use it when the command shows something. `background` runs where Playactor is. `focused` runs only while Playactor is focused.
- `params` are built with `param.string`, `param.number` and `param.boolean`, each taking `title` (what a keymap app labels its field with), `required`, `default` and `description`; a number also takes `int`, `min` and `max`. `run` gets them decoded and checked, typed by the declaration: a param with a `default` or `required: true` is always there. Unknown keys, a key given twice and a value of the wrong type are refused before `run`.
- A `PluginFailure` thrown from `run` is shown as its message when a link ran the command; the socket and the CLI report it as the run's failure.

A command exists while its plugin is active. Disabling, reloading or a failed activation takes it away, and a run that races one is refused, so `run` is never called on a disposed `api`.

### Deep links

```sh
open 'playactor://run/p.radio.play?station=KEXP'              # run a command, params as the query
open 'playactor://open/p/radio/stations?tag=jazz'             # open a page, by its path
open 'playactor://link?url=https%3A%2F%2Fwww.twitch.tv%2Fkexp'  # open a URL as a paste would
playactor run p.radio.play --param station=KEXP               # the same, from the command line
```

A link that launches Playactor waits until plugins have started. One that names a plugin that is off or failed to start shows "That link names nothing Playactor has" and does nothing.
