Fix: Cast through Plex not working on named libraries

pull/30/head
Juraj Nyíri 3 years ago
parent c29c377c92
commit 7773d8d0ee

@ -18861,7 +18861,7 @@ class Plex {
} }
class PlayController { class PlayController {
constructor(hass, plex, entity, runBefore, runAfter) { constructor(hass, plex, entity, runBefore, runAfter, libraryName) {
this.plexPlayerEntity = ''; this.plexPlayerEntity = '';
this.runBefore = false; this.runBefore = false;
this.runAfter = false; this.runAfter = false;
@ -18940,19 +18940,20 @@ class PlayController {
break; break;
case 'cast': case 'cast':
if (this.hass.services.plex) { if (this.hass.services.plex) {
const libraryName = lodash.isNil(data.librarySectionTitle) ? this.libraryName : data.librarySectionTitle;
try { try {
switch (data.type) { switch (data.type) {
case 'movie': case 'movie':
await this.playViaCastPlex(entity.value, 'movie', `plex://${JSON.stringify({ await this.playViaCastPlex(entity.value, 'movie', `plex://${JSON.stringify({
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: data.librarySectionTitle, library_name: libraryName,
title: data.title title: data.title
})}`); })}`);
break; break;
case 'episode': case 'episode':
await this.playViaCastPlex(entity.value, 'EPISODE', `plex://${JSON.stringify({ await this.playViaCastPlex(entity.value, 'EPISODE', `plex://${JSON.stringify({
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: data.librarySectionTitle, library_name: libraryName,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
show_name: data.grandparentTitle, show_name: data.grandparentTitle,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
@ -19266,6 +19267,7 @@ class PlayController {
this.hass = hass; this.hass = hass;
this.plex = plex; this.plex = plex;
this.entity = entity; this.entity = entity;
this.libraryName = libraryName;
if (!lodash.isEmpty(runBefore) && this.hass.states[runBefore]) { if (!lodash.isEmpty(runBefore) && this.hass.states[runBefore]) {
this.runBefore = runBefore.split('.'); this.runBefore = runBefore.split('.');
} }
@ -20947,7 +20949,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.renderPage(); this.renderPage();
try { try {
if (this.plex && this.hassObj) { if (this.plex && this.hassObj) {
this.playController = new PlayController(this.hassObj, this.plex, entity, this.runBefore, this.runAfter); this.playController = new PlayController(this.hassObj, this.plex, entity, this.runBefore, this.runAfter, this.config.libraryName);
if (this.playController) { if (this.playController) {
await this.playController.init(); await this.playController.init();
} }

@ -22,10 +22,20 @@ class PlayController {
supported: any = supported; supported: any = supported;
constructor(hass: HomeAssistant, plex: Plex, entity: Record<string, any>, runBefore: string, runAfter: string) { libraryName: string;
constructor(
hass: HomeAssistant,
plex: Plex,
entity: Record<string, any>,
runBefore: string,
runAfter: string,
libraryName: string
) {
this.hass = hass; this.hass = hass;
this.plex = plex; this.plex = plex;
this.entity = entity; this.entity = entity;
this.libraryName = libraryName;
if (!_.isEmpty(runBefore) && this.hass.states[runBefore]) { if (!_.isEmpty(runBefore) && this.hass.states[runBefore]) {
this.runBefore = runBefore.split('.'); this.runBefore = runBefore.split('.');
} }
@ -112,6 +122,7 @@ class PlayController {
break; break;
case 'cast': case 'cast':
if (this.hass.services.plex) { if (this.hass.services.plex) {
const libraryName = _.isNil(data.librarySectionTitle) ? this.libraryName : data.librarySectionTitle;
try { try {
switch (data.type) { switch (data.type) {
case 'movie': case 'movie':
@ -120,7 +131,7 @@ class PlayController {
'movie', 'movie',
`plex://${JSON.stringify({ `plex://${JSON.stringify({
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: data.librarySectionTitle, library_name: libraryName,
title: data.title title: data.title
})}` })}`
); );
@ -131,7 +142,7 @@ class PlayController {
'EPISODE', 'EPISODE',
`plex://${JSON.stringify({ `plex://${JSON.stringify({
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: data.librarySectionTitle, library_name: libraryName,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
show_name: data.grandparentTitle, show_name: data.grandparentTitle,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase

@ -313,7 +313,14 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.renderPage(); this.renderPage();
try { try {
if (this.plex && this.hassObj) { if (this.plex && this.hassObj) {
this.playController = new PlayController(this.hassObj, this.plex, entity, this.runBefore, this.runAfter); this.playController = new PlayController(
this.hassObj,
this.plex,
entity,
this.runBefore,
this.runAfter,
this.config.libraryName
);
if (this.playController) { if (this.playController) {
await this.playController.init(); await this.playController.init();
} }

Loading…
Cancel
Save