[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
0

Configure Feed

Select the types of activity you want to include in your feed.

refactor(AppleMusicSource): improve type safety and code readability

Refactored AppleMusicSource to use defined types for history consistency, updated the getRecentlyPlayedTracks limit type, and renamed variable for clarity.

Exerra (Jul 14, 2026, 12:42 AM +0300) 417ce85b c8d917cf

+14 -6
+14 -6
src/backend/sources/AppleMusicSource.ts
··· 1 1 import dayjs, { type Dayjs } from "dayjs"; 2 2 import type EventEmitter from "events"; 3 - import { MusicKit, type Song } from "node-musickit-api"; 3 + import { MusicKit, type MeHistoryRecentlyPlayedTracksProps, type Song } from "node-musickit-api"; 4 4 import type { PlayObject, PlayObjectMinimal } from "../../core/Atomic.ts"; 5 5 import type { InternalConfig } from "../common/infrastructure/Atomic.ts"; 6 6 import type { AppleMusicSourceConfig } from "../common/infrastructure/config/source/applemusic.ts"; ··· 16 16 playsAreBumpedOnly, 17 17 playsAreSortConsistent 18 18 } from "../utils/PlayComparisonUtils.ts"; 19 + 20 + export interface HistoryConsistencyResult { 21 + plays: PlayObject[]; 22 + consistent: boolean; 23 + diffType?: 'bump' | 'added'; 24 + diffResults?: PlayOrderConsistencyResults<PlayOrderChangeType>; 25 + reason?: string; 26 + } 19 27 20 28 export default class AppleMusicSource extends AbstractSource { 21 29 ··· 111 119 112 120 private getTracks = async (limit: number): Promise<PlayObject[]> => { 113 121 const clampedLimit = Math.max(1, Math.min(30, Math.round(limit))); 114 - const result = await this.musicKit.me.history.getRecentlyPlayedTracks({ limit: clampedLimit as 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30, types: ["songs"] }); 122 + const result = await this.musicKit.me.history.getRecentlyPlayedTracks({ limit: clampedLimit as MeHistoryRecentlyPlayedTracksProps["limit"], types: ["songs"] }); 115 123 if (result.error) { 116 124 throw new Error(result.error); 117 125 } ··· 121 129 return (result.data as unknown as Song[]).map(track => AppleMusicSource.formatPlayObj(track)); 122 130 } 123 131 124 - getIncomingHistoryConsistencyResult = (plays: PlayObject[]): {plays: PlayObject[], consistent: boolean, diffType?: 'bump' | 'added', diffResults?: PlayOrderConsistencyResults<PlayOrderChangeType>, reason?: string} => { 125 - const results: {plays: PlayObject[], consistent: boolean} = { 132 + getIncomingHistoryConsistencyResult = (plays: PlayObject[]): HistoryConsistencyResult => { 133 + const results: HistoryConsistencyResult = { 126 134 plays: [], 127 135 consistent: true 128 136 } ··· 207 215 let durSinceNow = 0; 208 216 const now = dayjs(); 209 217 210 - const rrPlays = results.plays.reduceRight((acc, curr) => { 218 + const reducedRightPlays = results.plays.reduceRight((acc, curr) => { 211 219 const durDatedPlay = { 212 220 data: { 213 221 ...curr.data, ··· 222 230 return [durDatedPlay, ...acc]; 223 231 }, [] as PlayObject[]); 224 232 225 - results.plays = rrPlays 233 + results.plays = reducedRightPlays 226 234 } 227 235 228 236 this.recentlyPlayed = plays;