Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/FoxxMD/multi-scrobbler. Scrobble plays from multiple sources to multiple clients docs.multi-scrobbler.app
deezer docker jellyfin koito lastfm listenbrainz maloja mopidy mpris music music-assistant plex scrobble self-hosted spotify subsonic tautulli youtube-music
Something went wrong. Try again.
2.3 kB · 66 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import type { EventEmitter } from "events";import {COMPONENT_AUTH_TYPE, type ComponentAuthType, type PlayObject} from "../../core/Atomic.ts";import type {FormatPlayObjectOptions, InternalConfig} from "../common/infrastructure/Atomic.ts";import type {KodiSourceConfig} from "../common/infrastructure/config/source/kodi.ts";import { KodiApiClient } from "../common/vendor/KodiApiClient.ts";import type {RecentlyPlayedOptions} from "./AbstractSource.ts";import { MemoryPositionalSource } from "./MemoryPositionalSource.ts";
export class KodiSource extends MemoryPositionalSource { declare config: KodiSourceConfig;
client: KodiApiClient; clientReady: boolean = false; override authType: ComponentAuthType = COMPONENT_AUTH_TYPE.unattended;
constructor(name: any, config: KodiSourceConfig, internal: InternalConfig, emitter: EventEmitter) { const { data, } = config; const { ...rest } = data || {}; super('kodi', name, {...config, data: {...rest}}, internal, emitter);
this.requiresAuth = true; this.canPoll = true; this.multiPlatform = true; }
protected async doBuildInitData(): Promise<true | string | undefined> { const { data: { url } = {} } = this.config; this.client = new KodiApiClient(this.name, this.config.data, {logger: this.logger}); this.logger.verbose(`Config URL: '${url ?? '(None Given)'}' => Normalized: '${this.client.url.toString()}'`) return true; }
doAuthentication = async () => { try { const resp = await this.client.testAuth(); this.clientReady = true; return true; } catch (e) { throw e; } }
static formatPlayObj(obj: any, options: FormatPlayObjectOptions & {version?: string} = {}): PlayObject { return KodiApiClient.formatPlayObj(obj, options); }
getRecentlyPlayed = async (options: RecentlyPlayedOptions = {}) => { if (!this.clientReady) { this.logger.warn('Cannot actively poll since client is not connected.'); return []; }
const play = await this.client.getRecentlyPlayed(options);
return await this.processRecentPlays(play); }
}