Add: EPG into data, use title and description in detailed view

live_tv
Juraj Nyíri 3 years ago
parent 73d8b030f7
commit 47d45ac16c

@ -20983,6 +20983,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.searchInputElem = document.createElement('input'); this.searchInputElem = document.createElement('input');
this.plexProtocol = 'http'; this.plexProtocol = 'http';
this.plexPort = false; this.plexPort = false;
this.epgData = {};
this.detailsShown = false; this.detailsShown = false;
this.entityRegistry = []; this.entityRegistry = [];
this.runBefore = ''; this.runBefore = '';
@ -21260,12 +21261,16 @@ class PlexMeetsHomeAssistant extends HTMLElement {
const getLiveTV = async () => { const getLiveTV = async () => {
if (this.plex) { if (this.plex) {
const liveTV = await this.plex.getLiveTV(); const liveTV = await this.plex.getLiveTV();
console.log(await this.plex.getEPG());
lodash.forEach(liveTV, (data, key) => { lodash.forEach(liveTV, (data, key) => {
this.data[key] = data; this.data[key] = data;
}); });
} }
}; };
const getEPG = async () => {
if (this.plex) {
this.epgData = await this.plex.getEPG();
}
};
let sectionKey = 0; let sectionKey = 0;
lodash.forEach(plexAllSections, (section) => { lodash.forEach(plexAllSections, (section) => {
if (lodash.isEqual(section.title, this.config.libraryName)) { if (lodash.isEqual(section.title, this.config.libraryName)) {
@ -21291,7 +21296,15 @@ class PlexMeetsHomeAssistant extends HTMLElement {
loadDataRequests.push(getRecentyAdded()); loadDataRequests.push(getRecentyAdded());
} }
loadDataRequests.push(getLiveTV()); loadDataRequests.push(getLiveTV());
loadDataRequests.push(getEPG());
const [plexSections] = await Promise.all(loadDataRequests); 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) { if (plexSections && sectionKey) {
lodash.forEach(plexSections, section => { lodash.forEach(plexSections, section => {
this.data[section.title1] = section.Metadata; this.data[section.title1] = section.Metadata;
@ -21905,7 +21918,15 @@ class PlexMeetsHomeAssistant extends HTMLElement {
else { else {
this.getElementsByClassName('detailsTitle')[0].innerHTML = escapeHtml(mainData.title); this.getElementsByClassName('detailsTitle')[0].innerHTML = escapeHtml(mainData.title);
} }
if (!lodash.isNil(mainData.year)) {
this.getElementsByClassName('detailsYear')[0].innerHTML = escapeHtml(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 this.getElementsByClassName('metaInfo')[0].innerHTML = `${(mainData.duration !== undefined
? `<span class='minutesDetail'>${Math.round(parseInt(escapeHtml(mainData.duration), 10) / 60 / 1000)} min</span>` ? `<span class='minutesDetail'>${Math.round(parseInt(escapeHtml(mainData.duration), 10) / 60 / 1000)} min</span>`
: '') + : '') +
@ -21915,7 +21936,15 @@ class PlexMeetsHomeAssistant extends HTMLElement {
(mainData.rating !== undefined (mainData.rating !== undefined
? `<span class='ratingDetail'>${mainData.rating < 5 ? '&#128465;' : '&#11088;'}&nbsp;${Math.round(parseFloat(escapeHtml(mainData.rating)) * 10) / 10}</span>` ? `<span class='ratingDetail'>${mainData.rating < 5 ? '&#128465;' : '&#11088;'}&nbsp;${Math.round(parseFloat(escapeHtml(mainData.rating)) * 10) / 10}</span>`
: '')}<div class='clear'></div>`; : '')}<div class='clear'></div>`;
if (!lodash.isNil(mainData.summary)) {
this.getElementsByClassName('detailDesc')[0].innerHTML = escapeHtml(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 /* todo temp disabled
if (data.type === 'movie') { if (data.type === 'movie') {
(this.detailElem.children[5] as HTMLElement).style.visibility = 'visible'; (this.detailElem.children[5] as HTMLElement).style.visibility = 'visible';
@ -22411,9 +22440,12 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (lodash.isEqual(data.type, 'episode')) { if (lodash.isEqual(data.type, 'episode')) {
yearElem.innerHTML = escapeHtml(data.title); yearElem.innerHTML = escapeHtml(data.title);
} }
else { else if (!lodash.isNil(data.year)) {
yearElem.innerHTML = escapeHtml(data.year); yearElem.innerHTML = escapeHtml(data.year);
} }
else if (!lodash.isNil(data.epg)) {
yearElem.innerHTML = escapeHtml(data.epg.title);
}
yearElem.className = 'yearElem'; yearElem.className = 'yearElem';
const additionalElem = document.createElement('div'); const additionalElem = document.createElement('div');
if (lodash.isEqual(data.type, 'episode')) { if (lodash.isEqual(data.type, 'episode')) {

@ -35,6 +35,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
plexPort: number | false = false; plexPort: number | false = false;
epgData: Record<string, any> = {};
detailsShown = false; detailsShown = false;
entityRegistry: Array<Record<string, any>> = []; entityRegistry: Array<Record<string, any>> = [];
@ -406,13 +408,18 @@ class PlexMeetsHomeAssistant extends HTMLElement {
const getLiveTV = async (): Promise<void> => { const getLiveTV = async (): Promise<void> => {
if (this.plex) { if (this.plex) {
const liveTV = await this.plex.getLiveTV(); const liveTV = await this.plex.getLiveTV();
console.log(await this.plex.getEPG());
_.forEach(liveTV, (data, key) => { _.forEach(liveTV, (data, key) => {
this.data[key] = data; this.data[key] = data;
}); });
} }
}; };
const getEPG = async (): Promise<void> => {
if (this.plex) {
this.epgData = await this.plex.getEPG();
}
};
let sectionKey: number | false = 0; let sectionKey: number | false = 0;
_.forEach(plexAllSections, (section: Record<string, any>) => { _.forEach(plexAllSections, (section: Record<string, any>) => {
if (_.isEqual(section.title, this.config.libraryName)) { if (_.isEqual(section.title, this.config.libraryName)) {
@ -436,8 +443,16 @@ class PlexMeetsHomeAssistant extends HTMLElement {
} }
loadDataRequests.push(getLiveTV()); loadDataRequests.push(getLiveTV());
loadDataRequests.push(getEPG());
const [plexSections] = await Promise.all(loadDataRequests); 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) { if (plexSections && sectionKey) {
_.forEach(plexSections, section => { _.forEach(plexSections, section => {
@ -1107,7 +1122,14 @@ class PlexMeetsHomeAssistant extends HTMLElement {
(this.getElementsByClassName('detailsTitle')[0] as HTMLElement).innerHTML = escapeHtml(mainData.title); (this.getElementsByClassName('detailsTitle')[0] as HTMLElement).innerHTML = escapeHtml(mainData.title);
} }
if (!_.isNil(mainData.year)) {
(this.getElementsByClassName('detailsYear')[0] as HTMLElement).innerHTML = escapeHtml(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 (this.getElementsByClassName('metaInfo')[0] as HTMLElement).innerHTML = `${(mainData.duration !== undefined
? `<span class='minutesDetail'>${Math.round( ? `<span class='minutesDetail'>${Math.round(
parseInt(escapeHtml(mainData.duration), 10) / 60 / 1000 parseInt(escapeHtml(mainData.duration), 10) / 60 / 1000
@ -1121,7 +1143,14 @@ class PlexMeetsHomeAssistant extends HTMLElement {
parseFloat(escapeHtml(mainData.rating)) * 10 parseFloat(escapeHtml(mainData.rating)) * 10
) / 10}</span>` ) / 10}</span>`
: '')}<div class='clear'></div>`; : '')}<div class='clear'></div>`;
if (!_.isNil(mainData.summary)) {
(this.getElementsByClassName('detailDesc')[0] as HTMLElement).innerHTML = escapeHtml(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 /* todo temp disabled
if (data.type === 'movie') { if (data.type === 'movie') {
@ -1672,8 +1701,10 @@ class PlexMeetsHomeAssistant extends HTMLElement {
const yearElem = document.createElement('div'); const yearElem = document.createElement('div');
if (_.isEqual(data.type, 'episode')) { if (_.isEqual(data.type, 'episode')) {
yearElem.innerHTML = escapeHtml(data.title); yearElem.innerHTML = escapeHtml(data.title);
} else { } else if (!_.isNil(data.year)) {
yearElem.innerHTML = escapeHtml(data.year); yearElem.innerHTML = escapeHtml(data.year);
} else if (!_.isNil(data.epg)) {
yearElem.innerHTML = escapeHtml(data.epg.title);
} }
yearElem.className = 'yearElem'; yearElem.className = 'yearElem';

Loading…
Cancel
Save