Skip to content

Commit 48ddd42

Browse files
committed
feat(scrobbler): Improve log readability for duplicate checking
1 parent ea408ac commit 48ddd42

File tree

4 files changed

+6
-39
lines changed

4 files changed

+6
-39
lines changed

src/backend/scrobblers/AbstractScrobbleClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export default abstract class AbstractScrobbleClient implements Authenticatable
294294
// return early if we don't care about checking existing
295295
if (false === this.checkExistingScrobbles) {
296296
if (this.verboseOptions.match.onNoMatch) {
297-
this.logger.debug(`(Existing Check) Source: ${buildTrackString(playObj, scoreTrackOpts)} => No Match because existing scrobble check is FALSE`);
297+
this.logger.debug(`${capitalize(playObj.meta.source ?? 'Source')}: ${buildTrackString(playObj, scoreTrackOpts)} => No Match because existing scrobble check is FALSE`, {leaf: ['Dupe Check']});
298298
}
299299
return undefined;
300300
}
@@ -325,7 +325,7 @@ export default abstract class AbstractScrobbleClient implements Authenticatable
325325
// (either user doesnt want to check history or there is no history to check!)
326326
if (this.recentScrobbles.length === 0) {
327327
if (this.verboseOptions.match.onNoMatch) {
328-
this.logger.debug(`(Existing Check) ${buildTrackString(playObj, scoreTrackOpts)} => No Match because no recent scrobbles returned from API`);
328+
this.logger.debug(`${buildTrackString(playObj, scoreTrackOpts)} => No Match because no recent scrobbles returned from API`, {leaf: ['Dupe Check']});
329329
}
330330
return undefined;
331331
}
@@ -410,10 +410,10 @@ export default abstract class AbstractScrobbleClient implements Authenticatable
410410

411411
if ((existingScrobble !== undefined && this.verboseOptions.match.onMatch) || (existingScrobble === undefined && this.verboseOptions.match.onNoMatch)) {
412412
const closestScrobble = `Closest Scrobble: ${buildTrackString(closestMatch.scrobble, scoreTrackOpts)} => ${closestMatch.confidence}`;
413-
this.logger.debug(`(Existing Check) Source: ${buildTrackString(playObj, scoreTrackOpts)} => ${closestScrobble}`);
413+
this.logger.debug(`${capitalize(playObj.meta.source ?? 'Source')}: ${buildTrackString(playObj, scoreTrackOpts)} => ${closestScrobble}`, {leaf: ['Dupe Check']});
414414
if (this.verboseOptions.match.confidenceBreakdown === true) {
415415
this.logger.debug(`Breakdown:
416-
${closestMatch.breakdowns.join('\n')}`);
416+
${closestMatch.breakdowns.join('\n')}`, {leaf: ['Dupe Check']});
417417
}
418418
}
419419
return existingScrobble;

src/backend/tests/plays/mixedDuration.json

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"track": "Fricassee",
88
"duration": 305,
99
"playDate": "2023-09-20T14:32:39.000Z"
10-
},
11-
"meta": {
12-
"source": "Maloja"
1310
}
1411
},
1512
{
@@ -19,9 +16,6 @@
1916
],
2017
"track": "Jimbó",
2118
"playDate": "2023-09-20T14:46:00.000Z"
22-
},
23-
"meta": {
24-
"source": "Maloja"
2519
}
2620
},
2721
{
@@ -33,9 +27,6 @@
3327
"track": "Aisha",
3428
"duration": 559,
3529
"playDate": "2023-09-20T15:10:09.000Z"
36-
},
37-
"meta": {
38-
"source": "Maloja"
3930
}
4031
},
4132
{
@@ -47,9 +38,6 @@
4738
"track": "Ballade No. 4 in F Minor, Op. 52",
4839
"duration": 575,
4940
"playDate": "2023-09-20T15:17:12.000Z"
50-
},
51-
"meta": {
52-
"source": "Maloja"
5341
}
5442
},
5543
{
@@ -62,9 +50,6 @@
6250
"duration": 327,
6351
"listenedFor": 327,
6452
"playDate": "2023-09-27T20:02:17.000Z"
65-
},
66-
"meta": {
67-
"source": "Maloja"
6853
}
6954
},
7055
{
@@ -74,9 +59,6 @@
7459
],
7560
"track": "Aprieta (Oye Cómo Va)",
7661
"playDate": "2023-09-20T15:38:12.000Z"
77-
},
78-
"meta": {
79-
"source": "Maloja"
8062
}
8163
},
8264
{
@@ -86,9 +68,6 @@
8668
],
8769
"track": "Another Brick in the Wall, Pt. 1",
8870
"playDate": "2023-09-20T15:39:12.000Z"
89-
},
90-
"meta": {
91-
"source": "Maloja"
9271
}
9372
},
9473
{
@@ -101,9 +80,6 @@
10180
"duration": 575,
10281
"listenedFor": 570,
10382
"playDate": "2023-09-20T15:41:12.000Z"
104-
},
105-
"meta": {
106-
"source": "Maloja"
10783
}
10884
},
10985
{
@@ -116,9 +92,6 @@
11692
"track": "Aquil",
11793
"listenedFor": 300,
11894
"playDate": "2023-09-20T17:55:05.000Z"
119-
},
120-
"meta": {
121-
"source": "Maloja"
12295
}
12396
},
12497
{
@@ -129,9 +102,6 @@
129102
"track": "Da Art of Storytellin' (Pt. 1)",
130103
"duration": 422,
131104
"playDate": "2023-09-20T15:39:12.000Z"
132-
},
133-
"meta": {
134-
"source": "Maloja"
135105
}
136106
},
137107
{
@@ -148,9 +118,6 @@
148118
"track": "Freeze Tag",
149119
"album": "Dinner Party: Dessert",
150120
"playDate": "2024-01-01T16:29:26.000Z"
151-
},
152-
"meta": {
153-
"source": "Maloja"
154121
}
155122
}
156123
]

src/backend/tests/scrobbler/scrobblers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ describe('Detects duplicate and unique scrobbles from client recent history', fu
339339

340340
testScrobbler.recentScrobbles = normalizedWithDur;
341341

342-
const timeEnd = clone(normalizedWithDur[normalizedWithMixedDur.length - 1]);
342+
const timeEnd = clone(normalizedWithDur[normalizedWithMixedDur.length - 2]);
343343
timeEnd.data.playDate = timeEnd.data.playDate.add(timeEnd.data.duration, 's');
344344

345345
assert.isTrue(await testScrobbler.alreadyScrobbled(timeEnd));

src/backend/tests/utils/PlayTestUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const generatePlay = (data: ObjectPlayData = {}, meta: PlayMeta = {}): Pl
8888
...data
8989
},
9090
meta: {
91-
source: faker.word.noun(),
91+
source: ['Spotify', 'Listenbrainz', 'Lastfm', 'Jellyfin', 'Plex'][faker.number.int({min: 0, max: 4})],
9292
...meta,
9393
}
9494
}

0 commit comments

Comments
 (0)