From a6f64ac889464a2aadd04befa42d945fc7ef9a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Sun, 11 Jul 2021 12:23:33 +0200 Subject: [PATCH] Add: Better look for season view when opened from Deck or other special libraries directly --- dist/plex-meets-homeassistant.js | 44 +++++++++++++++++------------- src/plex-meets-homeassistant.ts | 46 ++++++++++++++++++-------------- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 426a35c..c9e5bdf 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -20856,15 +20856,21 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.detailElem.style.transition = '0s'; this.detailElem.style.top = `${top - 1000}px`; clearInterval(this.showDetailsTimeout); - this.showDetailsTimeout = setTimeout(() => { - if (this.detailElem) { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + this.showDetailsTimeout = setTimeout(async () => { + if (this.detailElem && this.plex) { this.detailElem.style.visibility = 'visible'; this.detailElem.style.transition = '0.7s'; this.detailElem.style.top = `${top}px`; + let mainData = data; + if (lodash.isEqual(data.type, 'season')) { + mainData = await this.plex.getDetails(data.parentKey.split('/')[3]); + mainData.title = `${mainData.title} - ${data.title}`; + } const directorElem = this.getElementsByClassName('metaInfoDetailsData')[0]; if (directorElem.parentElement) { - if (data.Director && data.Director.length > 0) { - directorElem.innerHTML = escapeHtml(data.Director[0].tag); + if (mainData.Director && mainData.Director.length > 0) { + directorElem.innerHTML = escapeHtml(mainData.Director[0].tag); directorElem.parentElement.style.display = 'table-row'; } else { @@ -20873,8 +20879,8 @@ class PlexMeetsHomeAssistant extends HTMLElement { } const writerElem = this.getElementsByClassName('metaInfoDetailsData')[1]; if (writerElem.parentElement) { - if (data.Writer && data.Writer.length > 0) { - writerElem.innerHTML = escapeHtml(data.Writer[0].tag); + if (mainData.Writer && mainData.Writer.length > 0) { + writerElem.innerHTML = escapeHtml(mainData.Writer[0].tag); writerElem.parentElement.style.display = 'table-row'; } else { @@ -20883,8 +20889,8 @@ class PlexMeetsHomeAssistant extends HTMLElement { } const studioElem = this.getElementsByClassName('metaInfoDetailsData')[2]; if (studioElem.parentElement) { - if (data.studio) { - studioElem.innerHTML = escapeHtml(data.studio); + if (mainData.studio) { + studioElem.innerHTML = escapeHtml(mainData.studio); studioElem.parentElement.style.display = 'table-row'; } else { @@ -20893,9 +20899,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { } const genreElem = this.getElementsByClassName('metaInfoDetailsData')[3]; if (genreElem.parentElement) { - if (data.Genre && data.Genre.length > 0) { + if (mainData.Genre && mainData.Genre.length > 0) { let genre = ''; - lodash.forEach(data.Genre, tag => { + lodash.forEach(mainData.Genre, tag => { genre += `${tag.tag}, `; }); genreElem.innerHTML = escapeHtml(genre.slice(0, -2)); @@ -20905,18 +20911,18 @@ class PlexMeetsHomeAssistant extends HTMLElement { genreElem.parentElement.style.display = 'none'; } } - this.getElementsByClassName('detailsTitle')[0].innerHTML = escapeHtml(data.title); - this.getElementsByClassName('detailsYear')[0].innerHTML = escapeHtml(data.year); - this.getElementsByClassName('metaInfo')[0].innerHTML = `${(data.duration !== undefined - ? `${Math.round(parseInt(escapeHtml(data.duration), 10) / 60 / 1000)} min` + this.getElementsByClassName('detailsTitle')[0].innerHTML = escapeHtml(mainData.title); + this.getElementsByClassName('detailsYear')[0].innerHTML = escapeHtml(mainData.year); + this.getElementsByClassName('metaInfo')[0].innerHTML = `${(mainData.duration !== undefined + ? `${Math.round(parseInt(escapeHtml(mainData.duration), 10) / 60 / 1000)} min` : '') + - (data.contentRating !== undefined - ? `${escapeHtml(data.contentRating)}` + (mainData.contentRating !== undefined + ? `${escapeHtml(mainData.contentRating)}` : '') + - (data.rating !== undefined - ? `${data.rating < 5 ? '🗑' : '⭐'} ${Math.round(parseFloat(escapeHtml(data.rating)) * 10) / 10}` + (mainData.rating !== undefined + ? `${mainData.rating < 5 ? '🗑' : '⭐'} ${Math.round(parseFloat(escapeHtml(mainData.rating)) * 10) / 10}` : '')}
`; - this.getElementsByClassName('detailDesc')[0].innerHTML = escapeHtml(data.summary); + this.getElementsByClassName('detailDesc')[0].innerHTML = escapeHtml(mainData.summary); /* todo temp disabled if (data.type === 'movie') { (this.detailElem.children[5] as HTMLElement).style.visibility = 'visible'; diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index 57eba07..534852d 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -865,16 +865,22 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.detailElem.style.transition = '0s'; this.detailElem.style.top = `${top - 1000}px`; clearInterval(this.showDetailsTimeout); - this.showDetailsTimeout = setTimeout(() => { - if (this.detailElem) { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + this.showDetailsTimeout = setTimeout(async () => { + if (this.detailElem && this.plex) { this.detailElem.style.visibility = 'visible'; this.detailElem.style.transition = '0.7s'; this.detailElem.style.top = `${top}px`; + let mainData = data; + if (_.isEqual(data.type, 'season')) { + mainData = await this.plex.getDetails(data.parentKey.split('/')[3]); + mainData.title = `${mainData.title} - ${data.title}`; + } const directorElem = this.getElementsByClassName('metaInfoDetailsData')[0] as HTMLElement; if (directorElem.parentElement) { - if (data.Director && data.Director.length > 0) { - directorElem.innerHTML = escapeHtml(data.Director[0].tag); + if (mainData.Director && mainData.Director.length > 0) { + directorElem.innerHTML = escapeHtml(mainData.Director[0].tag); directorElem.parentElement.style.display = 'table-row'; } else { directorElem.parentElement.style.display = 'none'; @@ -883,8 +889,8 @@ class PlexMeetsHomeAssistant extends HTMLElement { const writerElem = this.getElementsByClassName('metaInfoDetailsData')[1] as HTMLElement; if (writerElem.parentElement) { - if (data.Writer && data.Writer.length > 0) { - writerElem.innerHTML = escapeHtml(data.Writer[0].tag); + if (mainData.Writer && mainData.Writer.length > 0) { + writerElem.innerHTML = escapeHtml(mainData.Writer[0].tag); writerElem.parentElement.style.display = 'table-row'; } else { writerElem.parentElement.style.display = 'none'; @@ -892,8 +898,8 @@ class PlexMeetsHomeAssistant extends HTMLElement { } const studioElem = this.getElementsByClassName('metaInfoDetailsData')[2] as HTMLElement; if (studioElem.parentElement) { - if (data.studio) { - studioElem.innerHTML = escapeHtml(data.studio); + if (mainData.studio) { + studioElem.innerHTML = escapeHtml(mainData.studio); studioElem.parentElement.style.display = 'table-row'; } else { studioElem.parentElement.style.display = 'none'; @@ -901,9 +907,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { } const genreElem = this.getElementsByClassName('metaInfoDetailsData')[3] as HTMLElement; if (genreElem.parentElement) { - if (data.Genre && data.Genre.length > 0) { + if (mainData.Genre && mainData.Genre.length > 0) { let genre = ''; - _.forEach(data.Genre, tag => { + _.forEach(mainData.Genre, tag => { genre += `${tag.tag}, `; }); genreElem.innerHTML = escapeHtml(genre.slice(0, -2)); @@ -912,22 +918,22 @@ class PlexMeetsHomeAssistant extends HTMLElement { genreElem.parentElement.style.display = 'none'; } } - (this.getElementsByClassName('detailsTitle')[0] as HTMLElement).innerHTML = escapeHtml(data.title); - (this.getElementsByClassName('detailsYear')[0] as HTMLElement).innerHTML = escapeHtml(data.year); - (this.getElementsByClassName('metaInfo')[0] as HTMLElement).innerHTML = `${(data.duration !== undefined + (this.getElementsByClassName('detailsTitle')[0] as HTMLElement).innerHTML = escapeHtml(mainData.title); + (this.getElementsByClassName('detailsYear')[0] as HTMLElement).innerHTML = escapeHtml(mainData.year); + (this.getElementsByClassName('metaInfo')[0] as HTMLElement).innerHTML = `${(mainData.duration !== undefined ? `${Math.round( - parseInt(escapeHtml(data.duration), 10) / 60 / 1000 + parseInt(escapeHtml(mainData.duration), 10) / 60 / 1000 )} min` : '') + - (data.contentRating !== undefined - ? `${escapeHtml(data.contentRating)}` + (mainData.contentRating !== undefined + ? `${escapeHtml(mainData.contentRating)}` : '') + - (data.rating !== undefined - ? `${data.rating < 5 ? '🗑' : '⭐'} ${Math.round( - parseFloat(escapeHtml(data.rating)) * 10 + (mainData.rating !== undefined + ? `${mainData.rating < 5 ? '🗑' : '⭐'} ${Math.round( + parseFloat(escapeHtml(mainData.rating)) * 10 ) / 10}` : '')}
`; - (this.getElementsByClassName('detailDesc')[0] as HTMLElement).innerHTML = escapeHtml(data.summary); + (this.getElementsByClassName('detailDesc')[0] as HTMLElement).innerHTML = escapeHtml(mainData.summary); /* todo temp disabled if (data.type === 'movie') {