diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 1a167b3..4064250 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -18676,6 +18676,7 @@ class Plex { this.sections = []; this.providers = []; this.livetv = {}; + this.livetvepg = {}; this.collections = false; this.playlists = []; this.init = async () => { @@ -18727,6 +18728,34 @@ class Plex { } return this.livetv; }; + this.getEPG = async () => { + if (lodash.isEmpty(this.livetvepg)) { + const returnData = {}; + const providers = await this.getProviders(); + const liveTVRequests = []; + const liveTVRequestsNames = []; + lodash.forEach(providers, provider => { + if (lodash.isEqual(provider.protocols, 'livetv')) { + let url = this.authorizeURL(`${this.getBasicURL()}/${provider.identifier}/grid?type=1&sort=beginsAt`); + url += `&endsAt>=${Math.floor(Date.now() / 1000)}`; + url += `&beginsAt<=${Math.floor(Date.now() / 1000)}`; + liveTVRequests.push(axios.get(url, { + timeout: this.requestTimeout + })); + liveTVRequestsNames.push(provider.title); + } + }); + const allResults = await Promise.all(liveTVRequests); + lodash.forEach(allResults, (result, key) => { + returnData[liveTVRequestsNames[key]] = {}; + lodash.forEach(result.data.MediaContainer.Metadata, data => { + returnData[liveTVRequestsNames[key]][data.Media[0].channelCallSign] = data; + }); + }); + this.livetvepg = returnData; + } + return this.livetvepg; + }; this.getServerID = async () => { if (lodash.isEmpty(this.serverInfo)) { await this.getServerInfo(); @@ -21231,6 +21260,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { const getLiveTV = async () => { if (this.plex) { const liveTV = await this.plex.getLiveTV(); + console.log(await this.plex.getEPG()); lodash.forEach(liveTV, (data, key) => { this.data[key] = data; }); diff --git a/src/modules/Plex.ts b/src/modules/Plex.ts index 242adad..2bea9bf 100644 --- a/src/modules/Plex.ts +++ b/src/modules/Plex.ts @@ -25,6 +25,8 @@ class Plex { livetv: Record = {}; + livetvepg: Record = {}; + collections: Array> | false = false; playlists: Array> = []; @@ -97,6 +99,37 @@ class Plex { return this.livetv; }; + getEPG = async (): Promise> => { + if (_.isEmpty(this.livetvepg)) { + const returnData: Record = {}; + const providers = await this.getProviders(); + const liveTVRequests: Array> = []; + const liveTVRequestsNames: Array = []; + _.forEach(providers, provider => { + if (_.isEqual(provider.protocols, 'livetv')) { + let url = this.authorizeURL(`${this.getBasicURL()}/${provider.identifier}/grid?type=1&sort=beginsAt`); + url += `&endsAt>=${Math.floor(Date.now() / 1000)}`; + url += `&beginsAt<=${Math.floor(Date.now() / 1000)}`; + liveTVRequests.push( + axios.get(url, { + timeout: this.requestTimeout + }) + ); + liveTVRequestsNames.push(provider.title); + } + }); + const allResults = await Promise.all(liveTVRequests); + _.forEach(allResults, (result, key) => { + returnData[liveTVRequestsNames[key]] = {}; + _.forEach(result.data.MediaContainer.Metadata, data => { + returnData[liveTVRequestsNames[key]][data.Media[0].channelCallSign] = data; + }); + }); + this.livetvepg = returnData; + } + return this.livetvepg; + }; + getServerID = async (): Promise => { if (_.isEmpty(this.serverInfo)) { await this.getServerInfo(); diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index 100b974..1e3a0c4 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -406,6 +406,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { const getLiveTV = async (): Promise => { if (this.plex) { const liveTV = await this.plex.getLiveTV(); + console.log(await this.plex.getEPG()); _.forEach(liveTV, (data, key) => { this.data[key] = data; });