Skip to content

Commit

Permalink
feat(player): Add sourceOfTruth variable to control logging and futur…
Browse files Browse the repository at this point in the history
…e use

Will not be used by listenbrainz source for actual scrobbling so make logs less noisy by suppressing what would normally be logging on newely added tracks from player
  • Loading branch information
FoxxMD committed Sep 18, 2023
1 parent 3fb5d6a commit 7dece44
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/backend/sources/MemorySource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import {EventEmitter} from "events";
import objectHash from 'object-hash';

export default class MemorySource extends AbstractSource {

playerSourceOfTruth: boolean = true;

/*
* MemorySource uses its own state to maintain a list of recently played tracks and determine if a track is valid.
* This is necessary for any source that
Expand Down Expand Up @@ -159,22 +162,28 @@ export default class MemorySource extends AbstractSource {
const matchingRecent = this.existingDiscovered(candidate); //sRecentlyPlayed.find(x => playObjDataMatch(x, candidate));
let stPrefix = `${buildTrackString(candidate, {include: ['trackId', 'artist', 'track']})}`;
if (matchingRecent === undefined) {
player.logger.debug(`${stPrefix} added after ${thresholdResultSummary(thresholdResults)} and not matching any prior plays`);
if(this.playerSourceOfTruth) {
player.logger.debug(`${stPrefix} added after ${thresholdResultSummary(thresholdResults)} and not matching any prior plays`);
}
newStatefulPlays.push(candidate);
} else {
const {data: {playDate, duration}} = candidate;
const {data: {playDate: rplayDate}} = matchingRecent;
if (!playDate.isSame(rplayDate)) {
if (duration !== undefined) {
if (playDate.isAfter(rplayDate.add(duration, 's'))) {
player.logger.debug(`${stPrefix} added after ${thresholdResultSummary(thresholdResults)} and having a different timestamp than a prior play`);
if(this.playerSourceOfTruth) {
player.logger.debug(`${stPrefix} added after ${thresholdResultSummary(thresholdResults)} and having a different timestamp than a prior play`);
}
newStatefulPlays.push(candidate);
}
} else {
const discoveredPlays = this.getRecentlyDiscoveredPlaysByPlatform(genGroupId(candidate));
if (discoveredPlays.length === 0 || !playObjDataMatch(discoveredPlays[0], candidate)) {
// if most recent stateful play is not this track we'll add it
player.logger.debug(`${stPrefix} added after ${thresholdResultSummary(thresholdResults)}. Matched other recent play but could not determine time frame due to missing duration. Allowed due to not being last played track.`);
if(this.playerSourceOfTruth) {
player.logger.debug(`${stPrefix} added after ${thresholdResultSummary(thresholdResults)}. Matched other recent play but could not determine time frame due to missing duration. Allowed due to not being last played track.`);
}
newStatefulPlays.push(candidate);
}
}
Expand Down

0 comments on commit 7dece44

Please sign in to comment.