diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 4064250..7590953 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -20983,6 +20983,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.searchInputElem = document.createElement('input'); this.plexProtocol = 'http'; this.plexPort = false; + this.epgData = {}; this.detailsShown = false; this.entityRegistry = []; this.runBefore = ''; @@ -21260,12 +21261,16 @@ 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; }); } }; + const getEPG = async () => { + if (this.plex) { + this.epgData = await this.plex.getEPG(); + } + }; let sectionKey = 0; lodash.forEach(plexAllSections, (section) => { if (lodash.isEqual(section.title, this.config.libraryName)) { @@ -21291,7 +21296,15 @@ class PlexMeetsHomeAssistant extends HTMLElement { loadDataRequests.push(getRecentyAdded()); } loadDataRequests.push(getLiveTV()); + loadDataRequests.push(getEPG()); const [plexSections] = await Promise.all(loadDataRequests); + lodash.forEach(this.epgData, (value, key) => { + lodash.forEach(this.data[key], (libraryData, libraryKey) => { + if (!lodash.isNil(this.epgData[key][libraryData.channelCallSign])) { + this.data[key][libraryKey].epg = this.epgData[key][libraryData.channelCallSign]; + } + }); + }); if (plexSections && sectionKey) { lodash.forEach(plexSections, section => { this.data[section.title1] = section.Metadata; @@ -21905,7 +21918,15 @@ class PlexMeetsHomeAssistant extends HTMLElement { else { this.getElementsByClassName('detailsTitle')[0].innerHTML = escapeHtml(mainData.title); } - this.getElementsByClassName('detailsYear')[0].innerHTML = escapeHtml(mainData.year); + if (!lodash.isNil(mainData.year)) { + this.getElementsByClassName('detailsYear')[0].innerHTML = escapeHtml(mainData.year); + } + else if (!lodash.isNil(mainData.epg) && !lodash.isNil(mainData.epg.title)) { + this.getElementsByClassName('detailsYear')[0].innerHTML = escapeHtml(mainData.epg.title); + } + else { + this.getElementsByClassName('detailsYear')[0].innerHTML = ''; + } this.getElementsByClassName('metaInfo')[0].innerHTML = `${(mainData.duration !== undefined ? `${Math.round(parseInt(escapeHtml(mainData.duration), 10) / 60 / 1000)} min` : '') + @@ -21915,7 +21936,15 @@ class PlexMeetsHomeAssistant extends HTMLElement { (mainData.rating !== undefined ? `${mainData.rating < 5 ? '🗑' : '⭐'} ${Math.round(parseFloat(escapeHtml(mainData.rating)) * 10) / 10}` : '')}
`; - this.getElementsByClassName('detailDesc')[0].innerHTML = escapeHtml(mainData.summary); + if (!lodash.isNil(mainData.summary)) { + this.getElementsByClassName('detailDesc')[0].innerHTML = escapeHtml(mainData.summary); + } + else if (!lodash.isNil(mainData.epg) && !lodash.isNil(mainData.epg.summary)) { + this.getElementsByClassName('detailDesc')[0].innerHTML = escapeHtml(mainData.epg.summary); + } + else { + this.getElementsByClassName('detailDesc')[0].innerHTML = ''; + } /* todo temp disabled if (data.type === 'movie') { (this.detailElem.children[5] as HTMLElement).style.visibility = 'visible'; @@ -22411,9 +22440,12 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (lodash.isEqual(data.type, 'episode')) { yearElem.innerHTML = escapeHtml(data.title); } - else { + else if (!lodash.isNil(data.year)) { yearElem.innerHTML = escapeHtml(data.year); } + else if (!lodash.isNil(data.epg)) { + yearElem.innerHTML = escapeHtml(data.epg.title); + } yearElem.className = 'yearElem'; const additionalElem = document.createElement('div'); if (lodash.isEqual(data.type, 'episode')) { diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index 1e3a0c4..082bc17 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -35,6 +35,8 @@ class PlexMeetsHomeAssistant extends HTMLElement { plexPort: number | false = false; + epgData: Record = {}; + detailsShown = false; entityRegistry: Array> = []; @@ -406,13 +408,18 @@ 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; }); } }; + const getEPG = async (): Promise => { + if (this.plex) { + this.epgData = await this.plex.getEPG(); + } + }; + let sectionKey: number | false = 0; _.forEach(plexAllSections, (section: Record) => { if (_.isEqual(section.title, this.config.libraryName)) { @@ -436,8 +443,16 @@ class PlexMeetsHomeAssistant extends HTMLElement { } loadDataRequests.push(getLiveTV()); + loadDataRequests.push(getEPG()); const [plexSections] = await Promise.all(loadDataRequests); + _.forEach(this.epgData, (value, key) => { + _.forEach(this.data[key], (libraryData, libraryKey) => { + if (!_.isNil(this.epgData[key][libraryData.channelCallSign])) { + this.data[key][libraryKey].epg = this.epgData[key][libraryData.channelCallSign]; + } + }); + }); if (plexSections && sectionKey) { _.forEach(plexSections, section => { @@ -1107,7 +1122,14 @@ class PlexMeetsHomeAssistant extends HTMLElement { (this.getElementsByClassName('detailsTitle')[0] as HTMLElement).innerHTML = escapeHtml(mainData.title); } - (this.getElementsByClassName('detailsYear')[0] as HTMLElement).innerHTML = escapeHtml(mainData.year); + if (!_.isNil(mainData.year)) { + (this.getElementsByClassName('detailsYear')[0] as HTMLElement).innerHTML = escapeHtml(mainData.year); + } else if (!_.isNil(mainData.epg) && !_.isNil(mainData.epg.title)) { + (this.getElementsByClassName('detailsYear')[0] as HTMLElement).innerHTML = escapeHtml(mainData.epg.title); + } else { + (this.getElementsByClassName('detailsYear')[0] as HTMLElement).innerHTML = ''; + } + (this.getElementsByClassName('metaInfo')[0] as HTMLElement).innerHTML = `${(mainData.duration !== undefined ? `${Math.round( parseInt(escapeHtml(mainData.duration), 10) / 60 / 1000 @@ -1121,7 +1143,14 @@ class PlexMeetsHomeAssistant extends HTMLElement { parseFloat(escapeHtml(mainData.rating)) * 10 ) / 10}` : '')}
`; - (this.getElementsByClassName('detailDesc')[0] as HTMLElement).innerHTML = escapeHtml(mainData.summary); + + if (!_.isNil(mainData.summary)) { + (this.getElementsByClassName('detailDesc')[0] as HTMLElement).innerHTML = escapeHtml(mainData.summary); + } else if (!_.isNil(mainData.epg) && !_.isNil(mainData.epg.summary)) { + (this.getElementsByClassName('detailDesc')[0] as HTMLElement).innerHTML = escapeHtml(mainData.epg.summary); + } else { + (this.getElementsByClassName('detailDesc')[0] as HTMLElement).innerHTML = ''; + } /* todo temp disabled if (data.type === 'movie') { @@ -1672,8 +1701,10 @@ class PlexMeetsHomeAssistant extends HTMLElement { const yearElem = document.createElement('div'); if (_.isEqual(data.type, 'episode')) { yearElem.innerHTML = escapeHtml(data.title); - } else { + } else if (!_.isNil(data.year)) { yearElem.innerHTML = escapeHtml(data.year); + } else if (!_.isNil(data.epg)) { + yearElem.innerHTML = escapeHtml(data.epg.title); } yearElem.className = 'yearElem';