Ported their real HTTP APIs (hal carried no client for these). jackett: an indexer proxy — tools only (list indexers, search), no events, no broker account, because it answers queries and has no timeline to observe. bazarr: subtitle tools + emits module.bazarr.subtitle.downloaded (poll history, diff). ombi: request tools + emits request.created/.approved. All pure emitters (their decisions originate here). Typecheck; manifests parse.
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
// bazarr's events. The tool runtime imports this once the broker is bound. Bazarr's one genuinely
|
|
// observable thing is a subtitle arriving: it works away in the background, searching providers for
|
|
// the missing-subtitle list, and when it succeeds a subtitle appears in its history. That is worth
|
|
// announcing to the mesh.
|
|
//
|
|
// Emits (novox/hq ADR 0046/0047):
|
|
// module.bazarr.subtitle.downloaded — a subtitle was fetched for an episode or movie
|
|
//
|
|
// Bazarr has nothing on the mesh it usefully reacts to (a download completing is Sonarr/Radarr's
|
|
// business, and they trigger Bazarr directly), so it consumes nothing — a pure emitter.
|
|
//
|
|
// The event is observation-based: poll history and diff. Primed silently on the first look, or a
|
|
// restart would re-announce the whole recent history as freshly downloaded.
|
|
|
|
import { emit } from "@novox/mesh-sdk/events";
|
|
import { BazarrClient } from "./client.js";
|
|
|
|
const bazarr = BazarrClient.fromEnv();
|
|
|
|
const seen = new Set<string>();
|
|
let primed = false;
|
|
async function pollHistory(): Promise<void> {
|
|
const entries = await bazarr.getHistory(40);
|
|
for (const entry of entries) {
|
|
if (seen.has(entry.id)) continue;
|
|
if (primed) {
|
|
await emit("module.bazarr.subtitle.downloaded", {
|
|
kind: entry.kind,
|
|
title: entry.title,
|
|
language: entry.language,
|
|
provider: entry.provider,
|
|
path: entry.path,
|
|
});
|
|
}
|
|
seen.add(entry.id);
|
|
}
|
|
primed = true;
|
|
}
|
|
|
|
const tick = (fn: () => Promise<void>, everyMs: number): void => {
|
|
const run = (): void => void fn().catch((err) => console.error(`[bazarr] ${err}`));
|
|
setInterval(run, everyMs);
|
|
run();
|
|
};
|
|
tick(pollHistory, 60_000);
|
|
|
|
console.log("[bazarr] watching subtitle-download history");
|