// 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 0041/0042): // 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(); let primed = false; async function pollHistory(): Promise { const entries = await bazarr.getHistory(40); for (const entry of entries) { if (seen.has(entry.id)) continue; if (primed) { await emit("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, 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");