diff --git a/README.md b/README.md index 3c518b0..18675d7 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ _Available special libraries:_ **runAfter**: _Optional_ Specify a script to run after playing. +**playTrailer**: _Optional_ Specify whether to play trailer if available. Possible values: true, false, muted + Example of card configuration: ``` diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 1d7b846..197fc94 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -19172,7 +19172,7 @@ const isVideoFullScreen = (_this) => { const videoPlayer = _this.getElementsByClassName('videoPlayer')[0]; const video = videoPlayer.children[0]; const body = document.getElementsByTagName('body')[0]; - return ((video.offsetWidth === body.offsetHeight && video.offsetHeight === body.offsetHeight) || + return ((video.offsetWidth === body.offsetWidth && video.offsetHeight === body.offsetHeight) || (_this.videoElem && _this.videoElem.classList.contains('simulatedFullScreen'))); }; const getOldPlexServerErrorMessage = (libraryName) => { @@ -19917,6 +19917,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.plexProtocol = 'http'; this.detailsShown = false; this.runBefore = ''; + this.playTrailer = true; this.runAfter = ''; this.columnsCount = 0; this.renderedItems = 0; @@ -20580,12 +20581,15 @@ class PlexMeetsHomeAssistant extends HTMLElement { const dataDetails = await this.plex.getDetails(data.key.split('/')[3]); if (this.videoElem) { const trailerURL = findTrailerURL(dataDetails); - if (trailerURL !== '') { + if (trailerURL !== '' && !lodash.isEqual(this.playTrailer, false)) { const videoPlayer = this.getElementsByClassName('videoPlayer')[0]; const video = document.createElement('video'); video.style.height = '100%'; video.style.width = '100%'; video.controls = false; + if (lodash.isEqual(this.playTrailer, 'muted')) { + video.muted = true; + } const source = document.createElement('source'); source.type = 'video/mp4'; source.src = this.plex.authorizeURL(`${this.plex.getBasicURL()}${dataDetails.Extras.Metadata[0].Media[0].Part[0].key}`); @@ -20608,6 +20612,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { videobg2.classList.add('transparent'); this.videoElem.classList.add('maxZIndex'); video.controls = true; + video.muted = false; } else { videobg1.classList.remove('transparent'); @@ -20618,6 +20623,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { top: getOffset(this.activeMovieElem).top - 70, behavior: 'smooth' }); + if (lodash.isEqual(this.playTrailer, 'muted')) { + video.muted = true; + } } } }; @@ -21042,6 +21050,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (config.runAfter) { this.runAfter = config.runAfter; } + if (!lodash.isNil(config.playTrailer)) { + this.playTrailer = config.playTrailer; + } this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort); }; this.getCardSize = () => { diff --git a/src/modules/utils.ts b/src/modules/utils.ts index 31ec8cb..d11bc2d 100644 --- a/src/modules/utils.ts +++ b/src/modules/utils.ts @@ -60,7 +60,7 @@ const isVideoFullScreen = (_this: any): boolean => { const video = videoPlayer.children[0] as any; const body = document.getElementsByTagName('body')[0]; return ( - (video.offsetWidth === body.offsetHeight && video.offsetHeight === body.offsetHeight) || + (video.offsetWidth === body.offsetWidth && video.offsetHeight === body.offsetHeight) || (_this.videoElem && _this.videoElem.classList.contains('simulatedFullScreen')) ); }; diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index ca5f840..f0819fe 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -25,6 +25,8 @@ class PlexMeetsHomeAssistant extends HTMLElement { runBefore = ''; + playTrailer: string | boolean = true; + runAfter = ''; renderNewElementsIfNeededTimeout: any; @@ -819,12 +821,15 @@ class PlexMeetsHomeAssistant extends HTMLElement { const dataDetails = await this.plex.getDetails(data.key.split('/')[3]); if (this.videoElem) { const trailerURL = findTrailerURL(dataDetails); - if (trailerURL !== '') { + if (trailerURL !== '' && !_.isEqual(this.playTrailer, false)) { const videoPlayer = this.getElementsByClassName('videoPlayer')[0] as HTMLElement; const video = document.createElement('video'); video.style.height = '100%'; video.style.width = '100%'; video.controls = false; + if (_.isEqual(this.playTrailer, 'muted')) { + video.muted = true; + } const source = document.createElement('source'); source.type = 'video/mp4'; source.src = this.plex.authorizeURL( @@ -852,6 +857,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.videoElem.classList.add('maxZIndex'); video.controls = true; + video.muted = false; } else { videobg1.classList.remove('transparent'); videobg2.classList.remove('transparent'); @@ -862,6 +868,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { top: getOffset(this.activeMovieElem as Element).top - 70, behavior: 'smooth' }); + if (_.isEqual(this.playTrailer, 'muted')) { + video.muted = true; + } } } }; @@ -1355,6 +1364,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (config.runAfter) { this.runAfter = config.runAfter; } + if (!_.isNil(config.playTrailer)) { + this.playTrailer = config.playTrailer; + } this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort); };