diff --git a/packages/integrations/src/plex/interface.ts b/packages/integrations/src/plex/interface.ts index 17e1b5ca0..ef0941dc9 100644 --- a/packages/integrations/src/plex/interface.ts +++ b/packages/integrations/src/plex/interface.ts @@ -24,6 +24,7 @@ interface MediaContainer { title?: string; index?: number; type: string; + live?: string; }; }[]; } diff --git a/packages/integrations/src/plex/plex-integration.ts b/packages/integrations/src/plex/plex-integration.ts index c5429e018..1ec684ac5 100644 --- a/packages/integrations/src/plex/plex-integration.ts +++ b/packages/integrations/src/plex/plex-integration.ts @@ -18,7 +18,7 @@ export class PlexIntegration extends Integration { }); const body = await response.text(); // convert xml response to objects, as there is no JSON api - const data = await PlexIntegration.parseXmlAsync(body); + const data = await PlexIntegration.parseXml(body); const mediaContainer = data.MediaContainer; // no sessions are open or available if (!mediaContainer.Video) { @@ -46,7 +46,7 @@ export class PlexIntegration extends Integration { profilePictureUrl: userElement?.$.thumb ?? null, }, currentlyPlaying: { - type: PlexIntegration.getCurrentlyPlayingType(videoElement.$.type) ?? "video", + type: videoElement.$.live === "1" ? "tv" : PlexIntegration.getCurrentlyPlayingType(videoElement.$.type), name: videoElement.$.grandparentTitle ?? videoElement.$.title ?? "Unknown", seasonName: videoElement.$.parentTitle, episodeName: videoElement.$.title ?? null, @@ -72,21 +72,22 @@ export class PlexIntegration extends Integration { }); }, handleResponseAsync: async (response) => { - const result = await response.text(); - const parsedResponse = (await parseStringPromise(result)) as unknown; - if (typeof parsedResponse === "object" && parsedResponse !== null) { + try { + const result = await response.text(); + await PlexIntegration.parseXml(result); return; + } catch { + throw new IntegrationTestConnectionError("invalidCredentials"); } - throw new IntegrationTestConnectionError("invalidCredentials"); }, }); } - static async parseXmlAsync(xml: string): Promise { + static parseXml(xml: string): Promise { return parseStringPromise(xml) as Promise; } - static getCurrentlyPlayingType(type: string): "movie" | "audio" | "video" | "tv" | undefined { + static getCurrentlyPlayingType(type: string): NonNullable["type"] { switch (type) { case "movie": return "movie"; @@ -95,7 +96,7 @@ export class PlexIntegration extends Integration { case "track": return "audio"; default: - return undefined; + return "video"; } } }