diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index e10c092..5b50661 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -18728,6 +18728,7 @@ class Plex { class PlayController { constructor(hass, plex, entity) { + this.plexPlayerEntity = ''; this.supported = supported; this.getState = async (entityID) => { return this.hass.callApi('GET', `states/${entityID}`); @@ -18819,6 +18820,7 @@ class PlayController { }; }; this.playViaPlexPlayer = async (movieID) => { + const machineID = !lodash.isEmpty(this.plexPlayerEntity) ? this.plexPlayerEntity : this.entity.plexPlayer; const { playQueueID, playQueueSelectedMetadataItemID } = await this.plexPlayerCreateQueue(movieID); const url = `${this.plex.protocol}://${this.plex.ip}:${this.plex.port}/player/playback/playMedia?address=${this.plex.ip}&commandID=1&containerKey=/playQueues/${playQueueID}?window=100%26own=1&key=/library/metadata/${playQueueSelectedMetadataItemID}&machineIdentifier=${await this.plex.getServerID()}&offset=0&port=${this.plex.port}&token=${this.plex.token}&type=video&protocol=${this.plex.protocol}`; try { @@ -18826,7 +18828,7 @@ class PlayController { method: 'post', url, headers: { - 'X-Plex-Target-Client-Identifier': this.entity.plexPlayer, + 'X-Plex-Target-Client-Identifier': machineID, 'X-Plex-Client-Identifier': 'PlexMeetsHomeAssistant' } }); @@ -18924,6 +18926,19 @@ class PlayController { return false; } }); + // Try to look into any other fields to identify machine ID + if (!found) { + lodash.forEach(this.plex.clients, plexClient => { + if (lodash.isEqual(plexClient.product, this.entity.plexPlayer) || + lodash.isEqual(plexClient.name, this.entity.plexPlayer) || + lodash.isEqual(plexClient.host, this.entity.plexPlayer) || + lodash.isEqual(plexClient.address, this.entity.plexPlayer)) { + this.plexPlayerEntity = plexClient.machineIdentifier; + found = true; + return false; + } + }); + } return found; }; this.isPlaySupported = (data) => { diff --git a/src/modules/PlayController.ts b/src/modules/PlayController.ts index db7872d..38e0598 100644 --- a/src/modules/PlayController.ts +++ b/src/modules/PlayController.ts @@ -9,6 +9,8 @@ import { supported } from '../const'; class PlayController { entity: Record; + plexPlayerEntity = ''; + hass: HomeAssistant; plex: Plex; @@ -120,6 +122,7 @@ class PlayController { }; private playViaPlexPlayer = async (movieID: number): Promise => { + const machineID = !_.isEmpty(this.plexPlayerEntity) ? this.plexPlayerEntity : this.entity.plexPlayer; const { playQueueID, playQueueSelectedMetadataItemID } = await this.plexPlayerCreateQueue(movieID); const url = `${this.plex.protocol}://${this.plex.ip}:${this.plex.port}/player/playback/playMedia?address=${ @@ -132,7 +135,7 @@ class PlayController { method: 'post', url, headers: { - 'X-Plex-Target-Client-Identifier': this.entity.plexPlayer, + 'X-Plex-Target-Client-Identifier': machineID, 'X-Plex-Client-Identifier': 'PlexMeetsHomeAssistant' } }); @@ -238,6 +241,21 @@ class PlayController { return false; } }); + // Try to look into any other fields to identify machine ID + if (!found) { + _.forEach(this.plex.clients, plexClient => { + if ( + _.isEqual(plexClient.product, this.entity.plexPlayer) || + _.isEqual(plexClient.name, this.entity.plexPlayer) || + _.isEqual(plexClient.host, this.entity.plexPlayer) || + _.isEqual(plexClient.address, this.entity.plexPlayer) + ) { + this.plexPlayerEntity = plexClient.machineIdentifier; + found = true; + return false; + } + }); + } return found; };