[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): extract timestamp calculation to method

Moved the reduceRight logic for calculating play timestamps into a dedicated private method 'applyCalculatedTimestamps' to improve code readability and maintainability.

Exerra (Jul 14, 2026, 12:46 AM +0300) 765d86e0 f347b82d

+19 -19
+19 -19
src/backend/sources/AppleMusicSource.ts
··· 170 170 } 171 171 } 172 172 173 + // Extract the reduceRight logic: 174 + private applyCalculatedTimestamps(plays: PlayObject[]): PlayObject[] { 175 + let durSinceNow = 0; 176 + const now = dayjs(); 177 + 178 + return plays.reduceRight((acc, curr) => { 179 + const durDatedPlay = { 180 + data: { 181 + ...curr.data, 182 + playDate: durSinceNow === 0 ? now : now.subtract(durSinceNow, 'seconds'), 183 + }, 184 + meta: { ...curr.meta, newFromSource: true } 185 + } 186 + durSinceNow += curr.data.duration ?? 1; 187 + return [durDatedPlay, ...acc]; 188 + }, [] as PlayObject[]); 189 + } 190 + 173 191 parseRecentAgainstResponse = (responsePlays: PlayObject[]): {plays: PlayObject[], consistent: boolean} => { 174 192 175 193 let results: {plays: PlayObject[], consistent: boolean} = { ··· 216 234 } 217 235 } 218 236 219 - let durSinceNow = 0; 220 - const now = dayjs(); 221 - 222 - const reducedRightPlays = results.plays.reduceRight((acc, curr) => { 223 - const durDatedPlay = { 224 - data: { 225 - ...curr.data, 226 - playDate: durSinceNow === 0 ? now : now.subtract(durSinceNow, 'seconds'), 227 - }, 228 - meta: { 229 - ...curr.meta, 230 - newFromSource: true 231 - } 232 - } 233 - durSinceNow += curr.data.duration ?? 1; 234 - return [durDatedPlay, ...acc]; 235 - }, [] as PlayObject[]); 236 - 237 - results.plays = reducedRightPlays 237 + results.plays = this.applyCalculatedTimestamps(results.plays); 238 238 } 239 239 240 240 this.recentlyPlayed = plays;