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,7 +19614,19 @@ 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') => {
if (lodash.isEqual(contentType, 'video')) {
this.hass.callService('media_player', 'play_media', {
// eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName,
// eslint-disable-next-line @typescript-eslint/camelcase
media_content_type: 'video',
// eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`)
});
}
else if (lodash.isEqual(contentType, 'epg')) {
// eslint-disable-next-line no-param-reassign
mediaLink = this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`); mediaLink = this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`);
const payload = { const payload = {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
@ -19639,6 +19652,7 @@ class PlayController {
*/ */
console.log(payload); console.log(payload);
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, 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,7 +345,18 @@ class PlayController {
} }
}; };
private playViaCast = (entityName: string, mediaLink: string): void => { private playViaCast = (entityName: string, mediaLink: string, contentType = 'video'): void => {
if (_.isEqual(contentType, 'video')) {
this.hass.callService('media_player', 'play_media', {
// eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName,
// eslint-disable-next-line @typescript-eslint/camelcase
media_content_type: 'video',
// eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`)
});
} else if (_.isEqual(contentType, 'epg')) {
// eslint-disable-next-line no-param-reassign
mediaLink = this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`); mediaLink = this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`);
const payload: any = { const payload: any = {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
@ -373,6 +384,7 @@ class PlayController {
console.log(payload); console.log(payload);
this.hass.callService('media_player', 'play_media', 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