From 892b95d0f60047748beb26e110226594221d8ec1 Mon Sep 17 00:00:00 2001 From: Wolfgang Kulhanek Date: Thu, 16 Oct 2025 15:28:47 +0200 Subject: [PATCH] Fix scrobbling. For real? --- src/server.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/server.ts b/src/server.ts index f0e3565..be12873 100644 --- a/src/server.ts +++ b/src/server.ts @@ -608,17 +608,21 @@ function server( logger.debug(`Received Sonos reporting event (v${version}): ${JSON.stringify(req.body)}`); try { - // Sonos may send an array of reports + // Sonos may send an array of reports or a single report with items array const reports = Array.isArray(req.body) ? req.body : [req.body]; for (const report of reports) { - const { - reportId, - mediaUrl, - durationPlayedMillis, - positionMillis, - type, - } = report; + // Handle both direct report format and items array format + const items = report.items || [report]; + + for (const item of items) { + const { + reportId, + mediaUrl, + durationPlayedMillis, + positionMillis, + type, + } = item; // Extract track ID from mediaUrl (format: /stream/track/{id} or x-sonos-http:track%3a{id}.mp3) let trackId: string | undefined; @@ -692,6 +696,7 @@ function server( logger.debug("No authentication available for reporting endpoint scrobble"); } } + } } return res.status(200).json({ status: "ok" });