Fix #65: Support multiple servers with plex cast

sonos 3.4.1
Juraj Nyíri 3 years ago
parent a487929cfe
commit 558334dcb2

@ -19538,16 +19538,16 @@ class PlayController {
try { try {
switch (processData.type) { switch (processData.type) {
case 'artist': case 'artist':
await this.playViaCastPlex(entity.value, 'MUSIC', `plex://${JSON.stringify({ await this.playViaCastPlex(entity.value, 'MUSIC', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: libraryName, library_name: libraryName,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
artist_name: processData.title, artist_name: processData.title,
shuffle: this.shuffle ? 1 : 0 shuffle: this.shuffle ? 1 : 0
})}`); });
break; break;
case 'album': case 'album':
await this.playViaCastPlex(entity.value, 'MUSIC', `plex://${JSON.stringify({ await this.playViaCastPlex(entity.value, 'MUSIC', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: libraryName, library_name: libraryName,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
@ -19555,10 +19555,10 @@ class PlayController {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
album_name: processData.title, album_name: processData.title,
shuffle: this.shuffle ? 1 : 0 shuffle: this.shuffle ? 1 : 0
})}`); });
break; break;
case 'track': case 'track':
await this.playViaCastPlex(entity.value, 'MUSIC', `plex://${JSON.stringify({ await this.playViaCastPlex(entity.value, 'MUSIC', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: libraryName, library_name: libraryName,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
@ -19568,17 +19568,17 @@ class PlayController {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
track_name: processData.title, track_name: processData.title,
shuffle: this.shuffle ? 1 : 0 shuffle: this.shuffle ? 1 : 0
})}`); });
break; break;
case 'movie': case 'movie':
await this.playViaCastPlex(entity.value, 'movie', `plex://${JSON.stringify({ await this.playViaCastPlex(entity.value, 'movie', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: libraryName, library_name: libraryName,
title: processData.title title: processData.title
})}`); });
break; break;
case 'episode': case 'episode':
await this.playViaCastPlex(entity.value, 'EPISODE', `plex://${JSON.stringify({ await this.playViaCastPlex(entity.value, 'EPISODE', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: libraryName, library_name: libraryName,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
@ -19587,7 +19587,7 @@ class PlayController {
season_number: processData.parentIndex, season_number: processData.parentIndex,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
episode_number: processData.index episode_number: processData.index
})}`); });
break; break;
default: default:
if (!lodash.isNil(processData.Media)) { if (!lodash.isNil(processData.Media)) {
@ -19811,14 +19811,20 @@ class PlayController {
this.hass.callService('media_player', 'play_media', payload); this.hass.callService('media_player', 'play_media', payload);
} }
}; };
this.playViaCastPlex = (entityName, contentType, mediaLink) => { this.playViaCastPlex = (entityName, contentType, payload) => {
const friendlyServerName = lodash.get(this.plex, 'serverInfo.friendlyName');
const plexPayload = lodash.clone(payload);
if (friendlyServerName) {
// eslint-disable-next-line @typescript-eslint/camelcase
plexPayload.plex_server = friendlyServerName;
}
return this.hass.callService('media_player', 'play_media', { return this.hass.callService('media_player', 'play_media', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName, entity_id: entityName,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
media_content_type: contentType, media_content_type: contentType,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: mediaLink media_content_id: `plex://${JSON.stringify(plexPayload)}`
}); });
}; };
this.playViaAndroidTV = async (entityName, mediaID, instantPlay = false, provider = 'com.plexapp.plugins.library') => { this.playViaAndroidTV = async (entityName, mediaID, instantPlay = false, provider = 'com.plexapp.plugins.library') => {

@ -185,76 +185,56 @@ class PlayController {
try { try {
switch (processData.type) { switch (processData.type) {
case 'artist': case 'artist':
await this.playViaCastPlex( await this.playViaCastPlex(entity.value, 'MUSIC', {
entity.value, // eslint-disable-next-line @typescript-eslint/camelcase
'MUSIC', library_name: libraryName,
`plex://${JSON.stringify({ // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase artist_name: processData.title,
library_name: libraryName, shuffle: this.shuffle ? 1 : 0
// eslint-disable-next-line @typescript-eslint/camelcase });
artist_name: processData.title,
shuffle: this.shuffle ? 1 : 0
})}`
);
break; break;
case 'album': case 'album':
await this.playViaCastPlex( await this.playViaCastPlex(entity.value, 'MUSIC', {
entity.value, // eslint-disable-next-line @typescript-eslint/camelcase
'MUSIC', library_name: libraryName,
`plex://${JSON.stringify({ // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase artist_name: processData.parentTitle,
library_name: libraryName, // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase album_name: processData.title,
artist_name: processData.parentTitle, shuffle: this.shuffle ? 1 : 0
// eslint-disable-next-line @typescript-eslint/camelcase });
album_name: processData.title,
shuffle: this.shuffle ? 1 : 0
})}`
);
break; break;
case 'track': case 'track':
await this.playViaCastPlex( await this.playViaCastPlex(entity.value, 'MUSIC', {
entity.value, // eslint-disable-next-line @typescript-eslint/camelcase
'MUSIC', library_name: libraryName,
`plex://${JSON.stringify({ // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase artist_name: processData.grandparentTitle,
library_name: libraryName, // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase album_name: processData.parentTitle,
artist_name: processData.grandparentTitle, // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase track_name: processData.title,
album_name: processData.parentTitle, shuffle: this.shuffle ? 1 : 0
// eslint-disable-next-line @typescript-eslint/camelcase });
track_name: processData.title,
shuffle: this.shuffle ? 1 : 0
})}`
);
break; break;
case 'movie': case 'movie':
await this.playViaCastPlex( await this.playViaCastPlex(entity.value, 'movie', {
entity.value, // eslint-disable-next-line @typescript-eslint/camelcase
'movie', library_name: libraryName,
`plex://${JSON.stringify({ title: processData.title
// eslint-disable-next-line @typescript-eslint/camelcase });
library_name: libraryName,
title: processData.title
})}`
);
break; break;
case 'episode': case 'episode':
await this.playViaCastPlex( await this.playViaCastPlex(entity.value, 'EPISODE', {
entity.value, // eslint-disable-next-line @typescript-eslint/camelcase
'EPISODE', library_name: libraryName,
`plex://${JSON.stringify({ // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase show_name: processData.grandparentTitle,
library_name: libraryName, // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase season_number: processData.parentIndex,
show_name: processData.grandparentTitle, // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase episode_number: processData.index
season_number: processData.parentIndex, });
// eslint-disable-next-line @typescript-eslint/camelcase
episode_number: processData.index
})}`
);
break; break;
default: default:
if (!_.isNil(processData.Media)) { if (!_.isNil(processData.Media)) {
@ -498,14 +478,20 @@ class PlayController {
} }
}; };
private playViaCastPlex = (entityName: string, contentType: string, mediaLink: string): Promise<void> => { private playViaCastPlex = (entityName: string, contentType: string, payload: Record<string, any>): any => {
const friendlyServerName = _.get(this.plex, 'serverInfo.friendlyName');
const plexPayload = _.clone(payload);
if (friendlyServerName) {
// eslint-disable-next-line @typescript-eslint/camelcase
plexPayload.plex_server = friendlyServerName;
}
return this.hass.callService('media_player', 'play_media', { return this.hass.callService('media_player', 'play_media', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName, entity_id: entityName,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
media_content_type: contentType, media_content_type: contentType,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: mediaLink media_content_id: `plex://${JSON.stringify(plexPayload)}`
}); });
}; };

Loading…
Cancel
Save