From 30f26257f3957a406c66238819f77adb38ffd413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Thu, 2 Sep 2021 22:52:20 +0200 Subject: [PATCH] Add: Live TV support in Kodi --- dist/plex-meets-homeassistant.js | 20 ++++++++++++++++---- src/const.ts | 2 +- src/modules/PlayController.ts | 17 ++++++++++++++--- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index d1663dc..9863ff9 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -17204,7 +17204,7 @@ const CSS_STYLE = { minimumEpisodeWidth: 300 }; const supported = { - kodi: ['movie', 'episode'], + kodi: ['movie', 'episode', 'epg'], androidtv: ['movie', 'show', 'season', 'episode', 'clip', 'epg'], plexPlayer: ['movie', 'show', 'season', 'episode', 'clip'], cast: ['movie', 'episode', 'epg'] @@ -19402,7 +19402,7 @@ class PlayController { } switch (entity.key) { case 'kodi': - await this.playViaKodi(entity.value, processData, processData.type); + await this.playViaKodi(entity.value, data, processData.type); break; case 'androidtv': if (!lodash.isNil(data.epg)) { @@ -19548,7 +19548,18 @@ class PlayController { } }; this.playViaKodi = async (entityName, data, type) => { - if (type === 'movie') { + if (!lodash.isNil(lodash.get(data, 'epg.Media[0].channelCallSign'))) { + const streamLink = `${this.plex.getBasicURL()}${await this.plex.tune(data.channelIdentifier, 'todo')}`; + await this.hass.callService('kodi', 'call_method', { + // eslint-disable-next-line @typescript-eslint/camelcase + entity_id: entityName, + method: 'Player.Open', + item: { + file: streamLink + } + }); + } + else if (type === 'movie') { const kodiData = await this.getKodiSearch(data.title); await this.hass.callService('kodi', 'call_method', { // eslint-disable-next-line @typescript-eslint/camelcase @@ -19755,7 +19766,8 @@ class PlayController { hasKodiMediaSearchInstalled) || (!lodash.isEqual(this.runBefore, false) && hasKodiMediaSearchInstalled)); } - return false; + return true; // temp + // return false; }; this.isCastSupported = (entityName) => { return ((this.hass.states[entityName] && diff --git a/src/const.ts b/src/const.ts index 160edea..18a03f7 100644 --- a/src/const.ts +++ b/src/const.ts @@ -9,7 +9,7 @@ const CSS_STYLE: any = { }; const supported: any = { - kodi: ['movie', 'episode'], + kodi: ['movie', 'episode', 'epg'], androidtv: ['movie', 'show', 'season', 'episode', 'clip', 'epg'], plexPlayer: ['movie', 'show', 'season', 'episode', 'clip'], cast: ['movie', 'episode', 'epg'] diff --git a/src/modules/PlayController.ts b/src/modules/PlayController.ts index ec85757..097a570 100644 --- a/src/modules/PlayController.ts +++ b/src/modules/PlayController.ts @@ -122,7 +122,7 @@ class PlayController { } switch (entity.key) { case 'kodi': - await this.playViaKodi(entity.value, processData, processData.type); + await this.playViaKodi(entity.value, data, processData.type); break; case 'androidtv': if (!_.isNil(data.epg)) { @@ -279,7 +279,17 @@ class PlayController { }; private playViaKodi = async (entityName: string, data: Record, type: string): Promise => { - if (type === 'movie') { + if (!_.isNil(_.get(data, 'epg.Media[0].channelCallSign'))) { + const streamLink = `${this.plex.getBasicURL()}${await this.plex.tune(data.channelIdentifier, 'todo')}`; + await this.hass.callService('kodi', 'call_method', { + // eslint-disable-next-line @typescript-eslint/camelcase + entity_id: entityName, + method: 'Player.Open', + item: { + file: streamLink + } + }); + } else if (type === 'movie') { const kodiData = await this.getKodiSearch(data.title); await this.hass.callService('kodi', 'call_method', { // eslint-disable-next-line @typescript-eslint/camelcase @@ -528,7 +538,8 @@ class PlayController { (!_.isEqual(this.runBefore, false) && hasKodiMediaSearchInstalled) ); } - return false; + return true; // temp + // return false; }; private isCastSupported = (entityName: string): boolean => {