Merge branch 'main' into next

# Conflicts:
#	dist/plex-meets-homeassistant.js
#	src/plex-meets-homeassistant.ts
pull/16/head
Juraj Nyíri 3 years ago
commit 0c8c28a0ae

@ -29,8 +29,6 @@ More images [at the end of the readme](https://github.com/JurajNyiri/PlexMeetsHo
**ip**: Enter ip address of plex server. You can also enter hostname without protocol or port. **ip**: Enter ip address of plex server. You can also enter hostname without protocol or port.
**port**: Enter port of your plex sever.
**libraryName**: Name of the library you wish to render. **libraryName**: Name of the library you wish to render.
_Available special libraries:_ _Available special libraries:_
@ -49,6 +47,8 @@ _Available special libraries:_
- **plexPlayer**: Name or machine ID of your plex client. Use this if you do not have devices above. See [detailed instructions](https://github.com/JurajNyiri/PlexMeetsHomeAssistant#all-other-plex-clients). - **plexPlayer**: Name or machine ID of your plex client. Use this if you do not have devices above. See [detailed instructions](https://github.com/JurajNyiri/PlexMeetsHomeAssistant#all-other-plex-clients).
- **cast**: Entity id of your media_player configured via [Google Cast](https://www.home-assistant.io/integrations/cast/). See [detailed instructions](https://github.com/JurajNyiri/PlexMeetsHomeAssistant#google-cast). - **cast**: Entity id of your media_player configured via [Google Cast](https://www.home-assistant.io/integrations/cast/). See [detailed instructions](https://github.com/JurajNyiri/PlexMeetsHomeAssistant#google-cast).
**port**: _Optional_ Port of your plex sever.
**protocol**: _Optional_ Protocol to use for Plex. Defaults to "http". **protocol**: _Optional_ Protocol to use for Plex. Defaults to "http".
**maxCount**: _Optional_ Maximum number of items to display in card. **maxCount**: _Optional_ Maximum number of items to display in card.

@ -18669,7 +18669,7 @@ var axios = axios_1;
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
class Plex { class Plex {
constructor(ip, port = 32400, token, protocol = 'http', sort = 'titleSort:asc') { constructor(ip, port = false, token, protocol = 'http', sort = 'titleSort:asc') {
this.serverInfo = {}; this.serverInfo = {};
this.clients = []; this.clients = [];
this.requestTimeout = 5000; this.requestTimeout = 5000;
@ -18791,7 +18791,7 @@ class Plex {
return onDeckData; return onDeckData;
}; };
this.getBasicURL = () => { this.getBasicURL = () => {
return `${this.protocol}://${this.ip}:${this.port}`; return `${this.protocol}://${this.ip}${this.port === false ? '' : `:${this.port}`}`;
}; };
this.authorizeURL = (url) => { this.authorizeURL = (url) => {
if (!lodash.includes(url, 'X-Plex-Token')) { if (!lodash.includes(url, 'X-Plex-Token')) {
@ -19191,11 +19191,11 @@ const findTrailerURL = (movieData) => {
} }
return foundURL; return foundURL;
}; };
const createEpisodesView = (playController, plexProtocol, ip, port, token, data) => { const createEpisodesView = (playController, plex, data) => {
const episodeContainer = document.createElement('div'); const episodeContainer = document.createElement('div');
episodeContainer.className = 'episodeContainer'; episodeContainer.className = 'episodeContainer';
episodeContainer.style.width = `${CSS_STYLE.episodeWidth}px`; episodeContainer.style.width = `${CSS_STYLE.episodeWidth}px`;
const episodeThumbURL = `${plexProtocol}://${ip}:${port}/photo/:/transcode?width=${CSS_STYLE.episodeWidth}&height=${CSS_STYLE.episodeHeight}&minSize=1&upscale=1&url=${data.thumb}&X-Plex-Token=${token}`; const episodeThumbURL = plex.authorizeURL(`${plex.getBasicURL()}/photo/:/transcode?width=${CSS_STYLE.episodeWidth}&height=${CSS_STYLE.episodeHeight}&minSize=1&upscale=1&url=${data.thumb}`);
const episodeElem = document.createElement('div'); const episodeElem = document.createElement('div');
episodeElem.className = 'episodeElem'; episodeElem.className = 'episodeElem';
episodeElem.style.width = `${CSS_STYLE.episodeWidth}px`; episodeElem.style.width = `${CSS_STYLE.episodeWidth}px`;
@ -19978,6 +19978,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
constructor() { constructor() {
super(...arguments); super(...arguments);
this.plexProtocol = 'http'; this.plexProtocol = 'http';
this.plexPort = false;
this.detailsShown = false; this.detailsShown = false;
this.runBefore = ''; this.runBefore = '';
this.playTrailer = true; this.playTrailer = true;
@ -20753,12 +20754,12 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.seasonsElem.style.top = `${top + 2000}px`; this.seasonsElem.style.top = `${top + 2000}px`;
} }
lodash.forEach(seasonsData, seasonData => { lodash.forEach(seasonsData, seasonData => {
if (this.seasonsElem) { if (this.seasonsElem && this.plex) {
this.seasonsElemHidden = false; this.seasonsElemHidden = false;
const seasonContainer = document.createElement('div'); const seasonContainer = document.createElement('div');
seasonContainer.className = 'seasonContainer'; seasonContainer.className = 'seasonContainer';
seasonContainer.style.width = `${CSS_STYLE.width}px`; seasonContainer.style.width = `${CSS_STYLE.width}px`;
const thumbURL = `${this.plexProtocol}://${this.config.ip}:${this.config.port}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${CSS_STYLE.expandedHeight}&minSize=1&upscale=1&url=${seasonData.thumb}&X-Plex-Token=${this.config.token}`; const thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${CSS_STYLE.expandedHeight}&minSize=1&upscale=1&url=${seasonData.thumb}&X-Plex-Token=${this.config.token}`;
const seasonElem = document.createElement('div'); const seasonElem = document.createElement('div');
seasonElem.className = 'seasonElem'; seasonElem.className = 'seasonElem';
seasonElem.style.width = `${CSS_STYLE.width}px`; seasonElem.style.width = `${CSS_STYLE.width}px`;
@ -20838,8 +20839,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.episodesElem.style.transition = `0s`; this.episodesElem.style.transition = `0s`;
this.episodesElem.style.top = `${top + 2000}px`; this.episodesElem.style.top = `${top + 2000}px`;
lodash.forEach(episodesData, episodeData => { lodash.forEach(episodesData, episodeData => {
if (this.episodesElem && this.playController) { if (this.episodesElem && this.playController && this.plex) {
this.episodesElem.append(createEpisodesView(this.playController, this.plexProtocol, this.config.ip, this.config.port, this.config.token, episodeData)); this.episodesElem.append(createEpisodesView(this.playController, this.plex, episodeData));
} }
}); });
clearInterval(this.episodesLoadTimeout); clearInterval(this.episodesLoadTimeout);
@ -20918,8 +20919,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (this.showExtras) { if (this.showExtras) {
const extras = dataDetails.Extras.Metadata; const extras = dataDetails.Extras.Metadata;
lodash.forEach(extras, extrasData => { lodash.forEach(extras, extrasData => {
if (this.episodesElem && this.playController) { if (this.episodesElem && this.playController && this.plex) {
this.episodesElem.append(createEpisodesView(this.playController, this.plexProtocol, this.config.ip, this.config.port, this.config.token, extrasData)); this.episodesElem.append(createEpisodesView(this.playController, this.plex, extrasData));
} }
}); });
} }
@ -21012,11 +21013,13 @@ class PlexMeetsHomeAssistant extends HTMLElement {
}; };
this.getMovieElement = (data, hasAdditionalData = false) => { this.getMovieElement = (data, hasAdditionalData = false) => {
let thumbURL = ''; let thumbURL = '';
if (lodash.isEqual(data.type, 'episode')) { if (this.plex) {
thumbURL = `${this.plexProtocol}://${this.config.ip}:${this.config.port}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${CSS_STYLE.expandedHeight}&minSize=1&upscale=1&url=${data.grandparentThumb}&X-Plex-Token=${this.config.token}`; if (lodash.isEqual(data.type, 'episode')) {
} thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${CSS_STYLE.expandedHeight}&minSize=1&upscale=1&url=${data.grandparentThumb}&X-Plex-Token=${this.config.token}`;
else { }
thumbURL = `${this.plexProtocol}://${this.config.ip}:${this.config.port}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${CSS_STYLE.expandedHeight}&minSize=1&upscale=1&url=${data.thumb}&X-Plex-Token=${this.config.token}`; else {
thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${CSS_STYLE.expandedHeight}&minSize=1&upscale=1&url=${data.thumb}&X-Plex-Token=${this.config.token}`;
}
} }
const container = document.createElement('div'); const container = document.createElement('div');
container.className = 'container'; container.className = 'container';
@ -21130,9 +21133,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (!config.ip) { if (!config.ip) {
throw new Error('You need to define a ip'); throw new Error('You need to define a ip');
} }
if (!config.port) {
throw new Error('You need to define a port');
}
if (!config.libraryName) { if (!config.libraryName) {
throw new Error('You need to define a libraryName'); throw new Error('You need to define a libraryName');
} }
@ -21140,6 +21140,9 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (config.protocol) { if (config.protocol) {
this.plexProtocol = config.protocol; this.plexProtocol = config.protocol;
} }
if (config.port) {
this.plexPort = config.port;
}
if (config.maxCount) { if (config.maxCount) {
this.maxCount = config.maxCount; this.maxCount = config.maxCount;
} }
@ -21155,7 +21158,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (!lodash.isNil(config.showExtras)) { if (!lodash.isNil(config.showExtras)) {
this.showExtras = config.showExtras; this.showExtras = config.showExtras;
} }
this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort); this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort);
}; };
this.getCardSize = () => { this.getCardSize = () => {
return 3; return 3;

@ -5,7 +5,7 @@ import _ from 'lodash';
class Plex { class Plex {
ip: string; ip: string;
port: number; port: number | false;
token: string; token: string;
@ -21,7 +21,13 @@ class Plex {
sections: Array<Record<string, any>> = []; sections: Array<Record<string, any>> = [];
constructor(ip: string, port = 32400, token: string, protocol: 'http' | 'https' = 'http', sort = 'titleSort:asc') { constructor(
ip: string,
port: number | false = false,
token: string,
protocol: 'http' | 'https' = 'http',
sort = 'titleSort:asc'
) {
this.ip = ip; this.ip = ip;
this.port = port; this.port = port;
this.token = token; this.token = token;
@ -172,7 +178,7 @@ class Plex {
}; };
getBasicURL = (): string => { getBasicURL = (): string => {
return `${this.protocol}://${this.ip}:${this.port}`; return `${this.protocol}://${this.ip}${this.port === false ? '' : `:${this.port}`}`;
}; };
authorizeURL = (url: string): string => { authorizeURL = (url: string): string => {

@ -87,18 +87,15 @@ const findTrailerURL = (movieData: Record<string, any>): string => {
return foundURL; return foundURL;
}; };
const createEpisodesView = ( const createEpisodesView = (playController: PlayController, plex: Plex, data: Record<string, any>): HTMLElement => {
playController: PlayController,
plexProtocol: string,
ip: string,
port: string,
token: string,
data: Record<string, any>
): HTMLElement => {
const episodeContainer = document.createElement('div'); const episodeContainer = document.createElement('div');
episodeContainer.className = 'episodeContainer'; episodeContainer.className = 'episodeContainer';
episodeContainer.style.width = `${CSS_STYLE.episodeWidth}px`; episodeContainer.style.width = `${CSS_STYLE.episodeWidth}px`;
const episodeThumbURL = `${plexProtocol}://${ip}:${port}/photo/:/transcode?width=${CSS_STYLE.episodeWidth}&height=${CSS_STYLE.episodeHeight}&minSize=1&upscale=1&url=${data.thumb}&X-Plex-Token=${token}`; const episodeThumbURL = plex.authorizeURL(
`${plex.getBasicURL()}/photo/:/transcode?width=${CSS_STYLE.episodeWidth}&height=${
CSS_STYLE.episodeHeight
}&minSize=1&upscale=1&url=${data.thumb}`
);
const episodeElem = document.createElement('div'); const episodeElem = document.createElement('div');
episodeElem.className = 'episodeElem'; episodeElem.className = 'episodeElem';

@ -22,6 +22,8 @@ import style from './modules/style';
class PlexMeetsHomeAssistant extends HTMLElement { class PlexMeetsHomeAssistant extends HTMLElement {
plexProtocol: 'http' | 'https' = 'http'; plexProtocol: 'http' | 'https' = 'http';
plexPort: number | false = false;
detailsShown = false; detailsShown = false;
runBefore = ''; runBefore = '';
@ -948,12 +950,14 @@ class PlexMeetsHomeAssistant extends HTMLElement {
} }
_.forEach(seasonsData, seasonData => { _.forEach(seasonsData, seasonData => {
if (this.seasonsElem) { if (this.seasonsElem && this.plex) {
this.seasonsElemHidden = false; this.seasonsElemHidden = false;
const seasonContainer = document.createElement('div'); const seasonContainer = document.createElement('div');
seasonContainer.className = 'seasonContainer'; seasonContainer.className = 'seasonContainer';
seasonContainer.style.width = `${CSS_STYLE.width}px`; seasonContainer.style.width = `${CSS_STYLE.width}px`;
const thumbURL = `${this.plexProtocol}://${this.config.ip}:${this.config.port}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${CSS_STYLE.expandedHeight}&minSize=1&upscale=1&url=${seasonData.thumb}&X-Plex-Token=${this.config.token}`; const thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${
CSS_STYLE.expandedHeight
}&minSize=1&upscale=1&url=${seasonData.thumb}&X-Plex-Token=${this.config.token}`;
const seasonElem = document.createElement('div'); const seasonElem = document.createElement('div');
seasonElem.className = 'seasonElem'; seasonElem.className = 'seasonElem';
@ -1047,17 +1051,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.episodesElem.style.transition = `0s`; this.episodesElem.style.transition = `0s`;
this.episodesElem.style.top = `${top + 2000}px`; this.episodesElem.style.top = `${top + 2000}px`;
_.forEach(episodesData, episodeData => { _.forEach(episodesData, episodeData => {
if (this.episodesElem && this.playController) { if (this.episodesElem && this.playController && this.plex) {
this.episodesElem.append( this.episodesElem.append(createEpisodesView(this.playController, this.plex, episodeData));
createEpisodesView(
this.playController,
this.plexProtocol,
this.config.ip,
this.config.port,
this.config.token,
episodeData
)
);
} }
}); });
clearInterval(this.episodesLoadTimeout); clearInterval(this.episodesLoadTimeout);
@ -1142,17 +1137,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (this.showExtras) { if (this.showExtras) {
const extras = dataDetails.Extras.Metadata; const extras = dataDetails.Extras.Metadata;
_.forEach(extras, extrasData => { _.forEach(extras, extrasData => {
if (this.episodesElem && this.playController) { if (this.episodesElem && this.playController && this.plex) {
this.episodesElem.append( this.episodesElem.append(createEpisodesView(this.playController, this.plex, extrasData));
createEpisodesView(
this.playController,
this.plexProtocol,
this.config.ip,
this.config.port,
this.config.token,
extrasData
)
);
} }
}); });
} }
@ -1255,10 +1241,16 @@ class PlexMeetsHomeAssistant extends HTMLElement {
getMovieElement = (data: any, hasAdditionalData = false): HTMLDivElement => { getMovieElement = (data: any, hasAdditionalData = false): HTMLDivElement => {
let thumbURL = ''; let thumbURL = '';
if (_.isEqual(data.type, 'episode')) { if (this.plex) {
thumbURL = `${this.plexProtocol}://${this.config.ip}:${this.config.port}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${CSS_STYLE.expandedHeight}&minSize=1&upscale=1&url=${data.grandparentThumb}&X-Plex-Token=${this.config.token}`; if (_.isEqual(data.type, 'episode')) {
} else { thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${
thumbURL = `${this.plexProtocol}://${this.config.ip}:${this.config.port}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${CSS_STYLE.expandedHeight}&minSize=1&upscale=1&url=${data.thumb}&X-Plex-Token=${this.config.token}`; CSS_STYLE.expandedHeight
}&minSize=1&upscale=1&url=${data.grandparentThumb}&X-Plex-Token=${this.config.token}`;
} else {
thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${CSS_STYLE.expandedWidth}&height=${
CSS_STYLE.expandedHeight
}&minSize=1&upscale=1&url=${data.thumb}&X-Plex-Token=${this.config.token}`;
}
} }
const container = document.createElement('div'); const container = document.createElement('div');
@ -1389,9 +1381,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (!config.ip) { if (!config.ip) {
throw new Error('You need to define a ip'); throw new Error('You need to define a ip');
} }
if (!config.port) {
throw new Error('You need to define a port');
}
if (!config.libraryName) { if (!config.libraryName) {
throw new Error('You need to define a libraryName'); throw new Error('You need to define a libraryName');
} }
@ -1399,6 +1388,9 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (config.protocol) { if (config.protocol) {
this.plexProtocol = config.protocol; this.plexProtocol = config.protocol;
} }
if (config.port) {
this.plexPort = config.port;
}
if (config.maxCount) { if (config.maxCount) {
this.maxCount = config.maxCount; this.maxCount = config.maxCount;
} }
@ -1415,7 +1407,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.showExtras = config.showExtras; this.showExtras = config.showExtras;
} }
this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort); this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort);
}; };
getCardSize = (): number => { getCardSize = (): number => {

Loading…
Cancel
Save