Add: WIP play live TV

live_tv
Juraj Nyíri 3 years ago
parent 47d45ac16c
commit 0bac7f089e

@ -17205,9 +17205,9 @@ const CSS_STYLE = {
}; };
const supported = { const supported = {
kodi: ['movie', 'episode'], kodi: ['movie', 'episode'],
androidtv: ['movie', 'show', 'season', 'episode', 'clip'], androidtv: ['movie', 'show', 'season', 'episode', 'clip', 'epg'],
plexPlayer: ['movie', 'show', 'season', 'episode', 'clip'], plexPlayer: ['movie', 'show', 'season', 'episode', 'clip', 'epg'],
cast: ['movie', 'episode'] cast: ['movie', 'episode', 'epg']
}; };
var bind = function bind(fn, thisArg) { var bind = function bind(fn, thisArg) {
@ -19283,6 +19283,7 @@ class PlayController {
return foundResult; return foundResult;
}; };
this.play = async (data, instantPlay = false) => { this.play = async (data, instantPlay = false) => {
console.log('play');
if (lodash.isArray(this.runBefore)) { if (lodash.isArray(this.runBefore)) {
const entityID = `${this.runBefore[0]}.${this.runBefore[1]}`; const entityID = `${this.runBefore[0]}.${this.runBefore[1]}`;
await this.hass.callService(this.runBefore[0], this.runBefore[1], {}); await this.hass.callService(this.runBefore[0], this.runBefore[1], {});
@ -19292,26 +19293,35 @@ class PlayController {
} }
} }
const entity = this.getPlayService(data); const entity = this.getPlayService(data);
let processData = data;
let provider;
if (!lodash.isNil(data.epg)) {
processData = data.epg;
provider = '';
}
console.log(processData);
switch (entity.key) { switch (entity.key) {
case 'kodi': case 'kodi':
await this.playViaKodi(entity.value, data, data.type); await this.playViaKodi(entity.value, processData, processData.type);
break; break;
case 'androidtv': case 'androidtv':
await this.playViaAndroidTV(entity.value, data.key.split('/')[3], instantPlay); await this.playViaAndroidTV(entity.value, processData.key, instantPlay, provider);
break; break;
case 'plexPlayer': case 'plexPlayer':
await this.playViaPlexPlayer(entity.value, data.key.split('/')[3]); await this.playViaPlexPlayer(entity.value, processData.key.split('/')[3]);
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; const libraryName = lodash.isNil(processData.librarySectionTitle)
? this.libraryName
: processData.librarySectionTitle;
try { try {
switch (data.type) { switch (processData.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: libraryName, library_name: libraryName,
title: data.title title: processData.title
})}`); })}`);
break; break;
case 'episode': case 'episode':
@ -19319,28 +19329,28 @@ class PlayController {
// 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
show_name: data.grandparentTitle, show_name: processData.grandparentTitle,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
season_number: data.parentIndex, season_number: processData.parentIndex,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
episode_number: data.index episode_number: processData.index
})}`); })}`);
break; break;
default: default:
this.playViaCast(entity.value, data.Media[0].Part[0].key); this.playViaCast(entity.value, processData.Media[0].Part[0].key);
} }
} }
catch (err) { catch (err) {
console.log(err); console.log(err);
this.playViaCast(entity.value, data.Media[0].Part[0].key); this.playViaCast(entity.value, processData.Media[0].Part[0].key);
} }
} }
else { else {
this.playViaCast(entity.value, data.Media[0].Part[0].key); this.playViaCast(entity.value, processData.Media[0].Part[0].key);
} }
break; break;
default: default:
throw Error(`No service available to play ${data.title}!`); throw Error(`No service available to play ${processData.title}!`);
} }
if (lodash.isArray(this.runAfter)) { if (lodash.isArray(this.runAfter)) {
await this.hass.callService(this.runAfter[0], this.runAfter[1], {}); await this.hass.callService(this.runAfter[0], this.runAfter[1], {});
@ -19481,13 +19491,14 @@ class PlayController {
media_content_id: mediaLink media_content_id: mediaLink
}); });
}; };
this.playViaAndroidTV = async (entityName, mediaID, instantPlay = false) => { this.playViaAndroidTV = async (entityName, mediaID, instantPlay = false, provider = 'com.plexapp.plugins.library') => {
const serverID = await this.plex.getServerID(); const serverID = await this.plex.getServerID();
let command = `am start`; let command = `am start`;
if (instantPlay) { if (instantPlay) {
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}/com.plexapp.plugins.library/library/metadata/${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,
@ -21302,6 +21313,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
lodash.forEach(this.data[key], (libraryData, libraryKey) => { lodash.forEach(this.data[key], (libraryData, libraryKey) => {
if (!lodash.isNil(this.epgData[key][libraryData.channelCallSign])) { if (!lodash.isNil(this.epgData[key][libraryData.channelCallSign])) {
this.data[key][libraryKey].epg = this.epgData[key][libraryData.channelCallSign]; this.data[key][libraryKey].epg = this.epgData[key][libraryData.channelCallSign];
this.data[key][libraryKey].type = 'epg';
} }
}); });
}); });
@ -21850,7 +21862,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
fullscreenTrailer.style.visibility = 'hidden'; fullscreenTrailer.style.visibility = 'hidden';
}; };
this.showDetails = async (data) => { this.showDetails = async (data) => {
console.log(data);
this.detailsShown = true; this.detailsShown = true;
const top = this.getTop(); const top = this.getTop();
if (this.detailElem) { if (this.detailElem) {

@ -10,9 +10,9 @@ const CSS_STYLE: any = {
const supported: any = { const supported: any = {
kodi: ['movie', 'episode'], kodi: ['movie', 'episode'],
androidtv: ['movie', 'show', 'season', 'episode', 'clip'], androidtv: ['movie', 'show', 'season', 'episode', 'clip', 'epg'],
plexPlayer: ['movie', 'show', 'season', 'episode', 'clip'], plexPlayer: ['movie', 'show', 'season', 'episode', 'clip', 'epg'],
cast: ['movie', 'episode'] cast: ['movie', 'episode', 'epg']
}; };
const LOREM_IPSUM = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec semper risus vitae aliquet interdum. Nulla facilisi. Pellentesque viverra sagittis lorem eget aliquet. Cras vehicula, purus vel consectetur mattis, ipsum arcu ullamcorper mi, id viverra purus ex eu dolor. Integer vehicula lacinia sem convallis iaculis. Nulla fermentum erat interdum, efficitur felis in, mollis neque. Vivamus luctus metus eget nisl pellentesque, placerat elementum magna eleifend. const LOREM_IPSUM = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec semper risus vitae aliquet interdum. Nulla facilisi. Pellentesque viverra sagittis lorem eget aliquet. Cras vehicula, purus vel consectetur mattis, ipsum arcu ullamcorper mi, id viverra purus ex eu dolor. Integer vehicula lacinia sem convallis iaculis. Nulla fermentum erat interdum, efficitur felis in, mollis neque. Vivamus luctus metus eget nisl pellentesque, placerat elementum magna eleifend.

@ -103,6 +103,7 @@ class PlayController {
}; };
play = async (data: Record<string, any>, instantPlay = false): Promise<void> => { play = async (data: Record<string, any>, instantPlay = false): Promise<void> => {
console.log('play');
if (_.isArray(this.runBefore)) { if (_.isArray(this.runBefore)) {
const entityID = `${this.runBefore[0]}.${this.runBefore[1]}`; const entityID = `${this.runBefore[0]}.${this.runBefore[1]}`;
await this.hass.callService(this.runBefore[0], this.runBefore[1], {}); await this.hass.callService(this.runBefore[0], this.runBefore[1], {});
@ -113,21 +114,31 @@ class PlayController {
} }
} }
const entity = this.getPlayService(data); const entity = this.getPlayService(data);
let processData = data;
let provider;
if (!_.isNil(data.epg)) {
processData = data.epg;
provider = '';
}
console.log(processData);
switch (entity.key) { switch (entity.key) {
case 'kodi': case 'kodi':
await this.playViaKodi(entity.value, data, data.type); await this.playViaKodi(entity.value, processData, processData.type);
break; break;
case 'androidtv': case 'androidtv':
await this.playViaAndroidTV(entity.value, data.key.split('/')[3], instantPlay); await this.playViaAndroidTV(entity.value, processData.key, instantPlay, provider);
break; break;
case 'plexPlayer': case 'plexPlayer':
await this.playViaPlexPlayer(entity.value, data.key.split('/')[3]); await this.playViaPlexPlayer(entity.value, processData.key.split('/')[3]);
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; const libraryName = _.isNil(processData.librarySectionTitle)
? this.libraryName
: processData.librarySectionTitle;
try { try {
switch (data.type) { switch (processData.type) {
case 'movie': case 'movie':
await this.playViaCastPlex( await this.playViaCastPlex(
entity.value, entity.value,
@ -135,7 +146,7 @@ class PlayController {
`plex://${JSON.stringify({ `plex://${JSON.stringify({
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
library_name: libraryName, library_name: libraryName,
title: data.title title: processData.title
})}` })}`
); );
break; break;
@ -147,27 +158,27 @@ class PlayController {
// 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
show_name: data.grandparentTitle, show_name: processData.grandparentTitle,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
season_number: data.parentIndex, season_number: processData.parentIndex,
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
episode_number: data.index episode_number: processData.index
})}` })}`
); );
break; break;
default: default:
this.playViaCast(entity.value, data.Media[0].Part[0].key); this.playViaCast(entity.value, processData.Media[0].Part[0].key);
} }
} catch (err) { } catch (err) {
console.log(err); console.log(err);
this.playViaCast(entity.value, data.Media[0].Part[0].key); this.playViaCast(entity.value, processData.Media[0].Part[0].key);
} }
} else { } else {
this.playViaCast(entity.value, data.Media[0].Part[0].key); this.playViaCast(entity.value, processData.Media[0].Part[0].key);
} }
break; break;
default: default:
throw Error(`No service available to play ${data.title}!`); throw Error(`No service available to play ${processData.title}!`);
} }
if (_.isArray(this.runAfter)) { if (_.isArray(this.runAfter)) {
await this.hass.callService(this.runAfter[0], this.runAfter[1], {}); await this.hass.callService(this.runAfter[0], this.runAfter[1], {});
@ -317,7 +328,12 @@ class PlayController {
}); });
}; };
private playViaAndroidTV = async (entityName: string, mediaID: number, instantPlay = false): Promise<void> => { private playViaAndroidTV = async (
entityName: string,
mediaID: string,
instantPlay = false,
provider = 'com.plexapp.plugins.library'
): Promise<void> => {
const serverID = await this.plex.getServerID(); const serverID = await this.plex.getServerID();
let command = `am start`; let command = `am start`;
@ -325,7 +341,9 @@ 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}/com.plexapp.plugins.library/library/metadata/${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

@ -450,6 +450,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
_.forEach(this.data[key], (libraryData, libraryKey) => { _.forEach(this.data[key], (libraryData, libraryKey) => {
if (!_.isNil(this.epgData[key][libraryData.channelCallSign])) { if (!_.isNil(this.epgData[key][libraryData.channelCallSign])) {
this.data[key][libraryKey].epg = this.epgData[key][libraryData.channelCallSign]; this.data[key][libraryKey].epg = this.epgData[key][libraryData.channelCallSign];
this.data[key][libraryKey].type = 'epg';
} }
}); });
}); });
@ -1054,7 +1055,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
}; };
showDetails = async (data: any): Promise<void> => { showDetails = async (data: any): Promise<void> => {
console.log(data);
this.detailsShown = true; this.detailsShown = true;
const top = this.getTop(); const top = this.getTop();
if (this.detailElem) { if (this.detailElem) {

Loading…
Cancel
Save