Skip to content

Commit 884b396

Browse files
committedDec 16, 2024·
fix(plex): Use track artist from response data when album artist is present
* Fixes #241 by using the track artist as the primary artist when album artist is present * Bug is reported in LukeHagar/plexjs#27 but will need be patched at runtime for the foreeable future due to npm packages not being published since September LukeHagar/plexjs#26
1 parent 8de2296 commit 884b396

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed
 
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/node_modules/@lukehagar/plexjs/sdk/models/operations/getsessions.d.ts b/node_modules/@lukehagar/plexjs/sdk/models/operations/getsessions.d.ts
2+
index 16632eb..e21bda6 100644
3+
--- a/node_modules/@lukehagar/plexjs/sdk/models/operations/getsessions.d.ts
4+
+++ b/node_modules/@lukehagar/plexjs/sdk/models/operations/getsessions.d.ts
5+
@@ -95,6 +95,7 @@ export type GetSessionsMetadata = {
6+
parentThumb?: string | undefined;
7+
parentTitle?: string | undefined;
8+
parentYear?: number | undefined;
9+
+ originalTitle?: string | undefined;
10+
ratingCount?: number | undefined;
11+
ratingKey?: string | undefined;
12+
sessionKey?: string | undefined;
13+
diff --git a/node_modules/@lukehagar/plexjs/sdk/models/operations/getsessions.js b/node_modules/@lukehagar/plexjs/sdk/models/operations/getsessions.js
14+
index efce9e2..f5c6eae 100644
15+
--- a/node_modules/@lukehagar/plexjs/sdk/models/operations/getsessions.js
16+
+++ b/node_modules/@lukehagar/plexjs/sdk/models/operations/getsessions.js
17+
@@ -290,6 +290,7 @@ exports.GetSessionsMetadata$inboundSchema = z.object({
18+
parentRatingKey: z.string().optional(),
19+
parentStudio: z.string().optional(),
20+
parentThumb: z.string().optional(),
21+
+ originalTitle: z.string().optional(),
22+
parentTitle: z.string().optional(),
23+
parentYear: z.number().int().optional(),
24+
ratingCount: z.number().int().optional(),
25+
@@ -339,6 +340,7 @@ exports.GetSessionsMetadata$outboundSchema = z.object({
26+
parentThumb: z.string().optional(),
27+
parentTitle: z.string().optional(),
28+
parentYear: z.number().int().optional(),
29+
+ originalTitle: z.string().optional(),
30+
ratingCount: z.number().int().optional(),
31+
ratingKey: z.string().optional(),
32+
sessionKey: z.string().optional(),

‎src/backend/sources/PlexApiSource.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,26 @@ export default class PlexApiSource extends MemoryPositionalSource {
304304
} = {},
305305
user: {
306306
title: userTitle,
307-
} = {}
307+
} = {},
308308
// plex returns the track artist as originalTitle (when there is an album artist)
309309
// otherwise this is undefined
310-
//originalTitle: trackArtist = undefined
310+
originalTitle: trackArtist
311311
} = obj;
312312

313+
const realArtists: string[] = [];
314+
const albumArtists: string[] = [];
315+
316+
if(trackArtist !== undefined) {
317+
realArtists.push(trackArtist);
318+
albumArtists.push(artist);
319+
} else {
320+
realArtists.push(artist);
321+
}
322+
313323
return {
314324
data: {
315-
artists: [artist],
325+
artists: realArtists,
326+
albumArtists,
316327
album,
317328
track,
318329
// albumArtists: AlbumArtists !== undefined ? AlbumArtists.map(x => x.Name) : undefined,
@@ -413,7 +424,9 @@ export default class PlexApiSource extends MemoryPositionalSource {
413424
const play: PlayObject = this.formatPlayObjAware(obj);
414425

415426
if(this.config.options.logPayload && !this.mediaIdsSeen.data.includes(play.meta.trackId)) {
416-
this.logger.debug(`First time seeing media ${play.meta.trackId} on ${msDeviceId} => ${JSON.stringify(play)}`);
427+
this.logger.debug(`First time seeing media ${play.meta.trackId} on ${msDeviceId} => ${JSON.stringify(play)}
428+
Plex Payload:
429+
${JSON.stringify(obj)}`);
417430
this.mediaIdsSeen.add(play.meta.trackId);
418431
}
419432

0 commit comments

Comments
 (0)
Please sign in to comment.