Skip to content

Commit

Permalink
Add: playTrailer option
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Jun 10, 2021
1 parent 285c63d commit 40846d3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```
Expand Down
15 changes: 13 additions & 2 deletions dist/plex-meets-homeassistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}`);
Expand All @@ -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');
Expand All @@ -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;
}
}
}
};
Expand Down Expand Up @@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
);
};
Expand Down
14 changes: 13 additions & 1 deletion src/plex-meets-homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {

runBefore = '';

playTrailer: string | boolean = true;

runAfter = '';

renderNewElementsIfNeededTimeout: any;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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');
Expand All @@ -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;
}
}
}
};
Expand Down Expand Up @@ -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);
};
Expand Down

0 comments on commit 40846d3

Please sign in to comment.