Fix: Cast functionality for video

pull/40/head
Juraj Nyíri 3 years ago
parent 7c7a260174
commit 9d692f745d

@ -18943,6 +18943,7 @@ class Plex {
})).data.MediaContainer; })).data.MediaContainer;
}; };
this.tune = async (channelID, session) => { this.tune = async (channelID, session) => {
// eslint-disable-next-line no-param-reassign
session = 'PlexMeetsHomeAssistant3'; session = 'PlexMeetsHomeAssistant3';
console.log(channelID); console.log(channelID);
// Todo: what is 12? do we need to get this from somewhere and change? // Todo: what is 12? do we need to get this from somewhere and change?
@ -19427,7 +19428,7 @@ class PlayController {
const session = `PlexMeetsHomeAssistant-${Math.floor(Date.now() / 1000)}`; const session = `PlexMeetsHomeAssistant-${Math.floor(Date.now() / 1000)}`;
const streamURL = await this.plex.tune(data.channelIdentifier, session); const streamURL = await this.plex.tune(data.channelIdentifier, session);
console.log(`${this.plex.getBasicURL()}${streamURL}`); console.log(`${this.plex.getBasicURL()}${streamURL}`);
this.playViaCast(entity.value, `${streamURL}`); this.playViaCast(entity.value, `${streamURL}`, 'epg');
} }
else if (this.hass.services.plex) { else if (this.hass.services.plex) {
const libraryName = lodash.isNil(processData.librarySectionTitle) const libraryName = lodash.isNil(processData.librarySectionTitle)
@ -19613,32 +19614,45 @@ class PlayController {
throw Error(`Plex type ${type} is not supported in Kodi.`); throw Error(`Plex type ${type} is not supported in Kodi.`);
} }
}; };
this.playViaCast = (entityName, mediaLink) => { this.playViaCast = (entityName, mediaLink, contentType = 'video') => {
mediaLink = this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`); if (lodash.isEqual(contentType, 'video')) {
const payload = { 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: 'application/vnd.apple.mpegurl', media_content_type: 'video',
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: mediaLink media_content_id: this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`)
}; });
/* }
payload = { else if (lodash.isEqual(contentType, 'epg')) {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line no-param-reassign
entity_id: entityName, mediaLink = this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`);
// eslint-disable-next-line @typescript-eslint/camelcase const payload = {
media_content_type: 'cast', // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase entity_id: entityName,
media_content_id: `{ // eslint-disable-next-line @typescript-eslint/camelcase
"app_name": "bubbleupnp", media_content_type: 'application/vnd.apple.mpegurl',
"media_id": "${mediaLink}", // eslint-disable-next-line @typescript-eslint/camelcase
"media_type": "application/x-mpegURL" media_content_id: mediaLink
}` };
}; /*
*/ payload = {
console.log(payload); // eslint-disable-next-line @typescript-eslint/camelcase
this.hass.callService('media_player', 'play_media', payload); entity_id: entityName,
// eslint-disable-next-line @typescript-eslint/camelcase
media_content_type: 'cast',
// eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: `{
"app_name": "bubbleupnp",
"media_id": "${mediaLink}",
"media_type": "application/x-mpegURL"
}`
};
*/
console.log(payload);
this.hass.callService('media_player', 'play_media', payload);
}
}; };
this.playViaCastPlex = (entityName, contentType, mediaLink) => { this.playViaCastPlex = (entityName, contentType, mediaLink) => {
return this.hass.callService('media_player', 'play_media', { return this.hass.callService('media_player', 'play_media', {
@ -19657,7 +19671,6 @@ class PlayController {
command += ' --ez "android.intent.extra.START_PLAYBACK" true'; command += ' --ez "android.intent.extra.START_PLAYBACK" true';
} }
command += ` -a android.intent.action.VIEW 'plex://server://${serverID}/${provider}${mediaID}'`; command += ` -a android.intent.action.VIEW 'plex://server://${serverID}/${provider}${mediaID}'`;
console.log(command);
this.hass.callService('androidtv', 'adb_command', { this.hass.callService('androidtv', 'adb_command', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName, entity_id: entityName,

@ -148,7 +148,7 @@ class PlayController {
const session = `PlexMeetsHomeAssistant-${Math.floor(Date.now() / 1000)}`; const session = `PlexMeetsHomeAssistant-${Math.floor(Date.now() / 1000)}`;
const streamURL = await this.plex.tune(data.channelIdentifier, session); const streamURL = await this.plex.tune(data.channelIdentifier, session);
console.log(`${this.plex.getBasicURL()}${streamURL}`); console.log(`${this.plex.getBasicURL()}${streamURL}`);
this.playViaCast(entity.value, `${streamURL}`); this.playViaCast(entity.value, `${streamURL}`, 'epg');
} else if (this.hass.services.plex) { } else if (this.hass.services.plex) {
const libraryName = _.isNil(processData.librarySectionTitle) const libraryName = _.isNil(processData.librarySectionTitle)
? this.libraryName ? this.libraryName
@ -345,34 +345,46 @@ class PlayController {
} }
}; };
private playViaCast = (entityName: string, mediaLink: string): void => { private playViaCast = (entityName: string, mediaLink: string, contentType = 'video'): void => {
mediaLink = this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`); if (_.isEqual(contentType, 'video')) {
const payload: any = { 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: 'application/vnd.apple.mpegurl', media_content_type: 'video',
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: mediaLink media_content_id: this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`)
}; });
} else if (_.isEqual(contentType, 'epg')) {
/* // eslint-disable-next-line no-param-reassign
payload = { mediaLink = this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`);
// eslint-disable-next-line @typescript-eslint/camelcase const payload: any = {
entity_id: entityName, // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase entity_id: entityName,
media_content_type: 'cast', // eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line @typescript-eslint/camelcase media_content_type: 'application/vnd.apple.mpegurl',
media_content_id: `{ // eslint-disable-next-line @typescript-eslint/camelcase
"app_name": "bubbleupnp", media_content_id: mediaLink
"media_id": "${mediaLink}", };
"media_type": "application/x-mpegURL"
}`
};
*/
console.log(payload); /*
this.hass.callService('media_player', 'play_media', payload); payload = {
// eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName,
// eslint-disable-next-line @typescript-eslint/camelcase
media_content_type: 'cast',
// eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: `{
"app_name": "bubbleupnp",
"media_id": "${mediaLink}",
"media_type": "application/x-mpegURL"
}`
};
*/
console.log(payload);
this.hass.callService('media_player', 'play_media', payload);
}
}; };
private playViaCastPlex = (entityName: string, contentType: string, mediaLink: string): Promise<void> => { private playViaCastPlex = (entityName: string, contentType: string, mediaLink: string): Promise<void> => {
@ -401,8 +413,6 @@ class PlayController {
command += ` -a android.intent.action.VIEW 'plex://server://${serverID}/${provider}${mediaID}'`; command += ` -a android.intent.action.VIEW 'plex://server://${serverID}/${provider}${mediaID}'`;
console.log(command);
this.hass.callService('androidtv', 'adb_command', { this.hass.callService('androidtv', 'adb_command', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName, entity_id: entityName,

@ -366,6 +366,7 @@ class Plex {
}; };
tune = async (channelID: string, session: string): Promise<any> => { tune = async (channelID: string, session: string): Promise<any> => {
// eslint-disable-next-line no-param-reassign
session = 'PlexMeetsHomeAssistant3'; session = 'PlexMeetsHomeAssistant3';
console.log(channelID); console.log(channelID);
// Todo: what is 12? do we need to get this from somewhere and change? // Todo: what is 12? do we need to get this from somewhere and change?

Loading…
Cancel
Save