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.1 kB · 38 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839import type { AlbumSearchResult, ArtistSearchResult, MetadataResultServiceScore, MetadataSearchError, TrackDataCreditBase, TrackSearchResult } from "../../../core/Api.ts";import type { Credit, MusicServicesBase, TrackData } from "../../../core/Atomic.ts";
export interface MetadataProvider { getTrackResults: (query: TrackDataCreditBase | MusicServicesBase) => Promise<TrackSearchResult[] | false> getArtistResults: (query: TrackDataCreditBase | MusicServicesBase) => Promise<ArtistSearchResult[] | false> getAlbumResults: (query: TrackDataCreditBase | MusicServicesBase) => Promise<AlbumSearchResult[] | false>}
export interface AggregateMetadataResponse<T extends (TrackSearchResult | ArtistSearchResult | AlbumSearchResult)> { data: T[] errors: MetadataSearchError[]}
export const asMetadataProvider = (val: object): val is MetadataProvider => `getTrackResults` in val && typeof val.getTrackResults === 'function' && `getArtistResults` in val && typeof val.getArtistResults === 'function' && `getAlbumResults` in val && typeof val.getAlbumResults === 'function'
/** A Credit as a result nested in another result: found on the same service as its parent and identified by the first service id it has, or its name if it has none */export const creditToResult = (credit: Credit, service: string): ArtistSearchResult => ({ ...credit, service, id: credit.metadata?.[0]?.id ?? credit.name});
/** Build a track result from TrackData, nesting its artists and album as results from the same service */export const trackDataToResult = ( data: TrackData, result: Pick<TrackSearchResult, 'id' | 'service' | 'score' | 'albumCount'>, album: Omit<Partial<AlbumSearchResult>, keyof ArtistSearchResult> & Partial<Pick<MetadataResultServiceScore, 'score'>> = {}): TrackSearchResult => ({ ...data, ...result, artists: data.artists?.map(x => creditToResult(x, result.service)), albumArtists: data.albumArtists?.map(x => creditToResult(x, result.service)), album: data.album === undefined ? undefined : { ...creditToResult(data.album, result.service), ...album }});