From dd7e971e71165ed78b27318d4726463752d239d8 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 12 Jan 2021 09:47:47 -0500 Subject: [PATCH] Fix how scrobbled tracks are returned to source Returns tracks array should only show that was a track was scrobbled or not (by existing in the array) -- and only be in the array once. --- clients/ScrobbleClients.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/clients/ScrobbleClients.js b/clients/ScrobbleClients.js index ad7a0977..83229388 100644 --- a/clients/ScrobbleClients.js +++ b/clients/ScrobbleClients.js @@ -1,5 +1,11 @@ import dayjs from "dayjs"; -import {createLabelledLogger, isValidConfigStructure, readJson, returnDuplicateStrings} from "../utils.js"; +import { + createLabelledLogger, + isValidConfigStructure, + playObjDataMatch, + readJson, + returnDuplicateStrings +} from "../utils.js"; import MalojaScrobbler from "./MalojaScrobbler.js"; import LastfmScrobbler from "./LastfmScrobbler.js"; @@ -242,7 +248,11 @@ ${sources.join('\n')}`); if (client.timeFrameIsValid(playObj, newFromSource) && !client.alreadyScrobbled(playObj, newFromSource)) { await client.scrobble(playObj) client.tracksScrobbled++; - tracksScrobbled.push(playObj); + // since this is what we return to the source only add to tracksScrobbled if not already in array + // (source should only know that a track was scrobbled (binary) -- doesn't care if it was scrobbled more than once + if(!tracksScrobbled.some(x => playObjDataMatch(x, playObj) && x.data.playDate === playObj.data.playDate)) { + tracksScrobbled.push(playObj); + } } } catch(e) { this.logger.error(`Encountered error while in scrobble loop for ${client.name}`); -- 2.51.2