Fix scrobbling. For real?

This commit is contained in:
Wolfgang Kulhanek
2025-10-16 15:28:47 +02:00
parent d88767cbe6
commit 892b95d0f6

View File

@@ -608,17 +608,21 @@ function server(
logger.debug(`Received Sonos reporting event (v${version}): ${JSON.stringify(req.body)}`); logger.debug(`Received Sonos reporting event (v${version}): ${JSON.stringify(req.body)}`);
try { 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]; const reports = Array.isArray(req.body) ? req.body : [req.body];
for (const report of reports) { for (const report of reports) {
const { // Handle both direct report format and items array format
reportId, const items = report.items || [report];
mediaUrl,
durationPlayedMillis, for (const item of items) {
positionMillis, const {
type, reportId,
} = report; mediaUrl,
durationPlayedMillis,
positionMillis,
type,
} = item;
// Extract track ID from mediaUrl (format: /stream/track/{id} or x-sonos-http:track%3a{id}.mp3) // Extract track ID from mediaUrl (format: /stream/track/{id} or x-sonos-http:track%3a{id}.mp3)
let trackId: string | undefined; let trackId: string | undefined;
@@ -692,6 +696,7 @@ function server(
logger.debug("No authentication available for reporting endpoint scrobble"); logger.debug("No authentication available for reporting endpoint scrobble");
} }
} }
}
} }
return res.status(200).json({ status: "ok" }); return res.status(200).json({ status: "ok" });