Add: playTrailer option

pull/16/head 1.0.1
Juraj Nyíri 4 years ago
parent 285c63db17
commit 40846d3a9d

@ -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:
```

@ -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 = () => {

@ -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'))
);
};

@ -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);
};

Loading…
Cancel
Save