/** * Navidrome MCP Server - Scrobble Tracker * Copyright (C) 2025 * SPDX-License-Identifier: AGPL-3.0-or-later */ import type { StateChangeEvent } from './playback-engine.js'; import type { RetryPolicy } from '../../utils/fetch-with-timeout.js'; export declare const MIN_DURATION_SECONDS = 30; export declare const MAX_THRESHOLD_SECONDS = 240; interface ScrobbleQueueEntry { index: number; songId: string | null; entryId?: number; isCurrent?: boolean; duration?: number; } /** Lets tests pass a minimal fake instead of constructing the full playback engine. */ export interface ScrobbleEngine { onStateChange(handler: (event: StateChangeEvent) => void): () => void; getQueue(): Promise; getCachedProperty(name: string): unknown; broadcastMessage(args: string[]): Promise; } export interface ScrobbleClient { subsonicRequest(endpoint: string, params?: Record, options?: { retryPolicy?: RetryPolicy; }): Promise; } /** * Every process attached to one mpv runs a tracker. mpv delivers every claim to every client in * one order, so the first claim for a play wins and one process submits it. */ export declare class ScrobbleTracker { private readonly client; private readonly engine; private readonly onTrackStart; private readonly claimantId; private unsubscribe; private currentSongId; private currentEntryId; private currentDuration; private startedAtMs; private submitted; private firstClaimant; private claimSent; private claimTimer; private lastTimePos; private transitionPending; private inheritedPath; private lastPlaylistPos; private lastPath; private attachEpoch; private generation; /** * @param onTrackStart Runs once per tracked play without gating it. The MCP injects a web-port * probe that keeps the owner lease alive. */ constructor(client: ScrobbleClient, engine: ScrobbleEngine, onTrackStart?: () => Promise); attach(): void; /** Test isolation only, since a production tracker lives as long as its process. */ detach(): void; private handleEvent; /** * A new mpv instance restarts entry ids and replays its state as fresh emits, * so the previous instance's play ends here and is not counted by this process. */ private onEngineAttach; private onPlaylistPos; /** * Records the in-flight play as submitted, so a later queue edit confirms it instead of counting * it again. The attach-time file is its identity, since this read can land after a move or swap. */ private adoptInFlightPlay; /** * Path is the only signal for a new file at the same index or from another process. mpv reports * path before duration, so the pending flag keeps the new file's events off the displaced play. */ private onPath; private onQueueMutation; private maybeRehydrateAfterQueue; private hydrateAndStart; /** * mpv's entry id survives an index shift. Without one, songId is the only identity, so a * back-to-back replay of one song counts once. */ private isSamePlay; private confirmSamePlay; private startTrackingTrack; private runTrackStartHook; private onDuration; private onTimePos; private maybeSubmit; /** Identifies a play across processes, since every client of one mpv reads the same entry ids. */ private playKey; private sendClaim; private onMessage; /** The key check keeps a late settle for a skipped play off the next one. */ private settleClaim; private clearClaimTimer; private reset; private sendNowPlaying; private sendSubmission; } export {}; //# sourceMappingURL=scrobble-tracker.d.ts.map