Add #66: Play action for track on vlc_telnet

vlc_telnet
Juraj Nyíri 2 years ago
parent 2a8b87dd33
commit a7f6ba9ce0

@ -17207,7 +17207,8 @@ const supported = {
kodi: ['movie', 'episode', 'epg'],
androidtv: ['movie', 'show', 'season', 'episode', 'clip', 'track', 'artist', 'album'],
plexPlayer: ['movie', 'show', 'season', 'episode', 'clip', 'track', 'artist', 'album'],
cast: ['movie', 'episode', 'artist', 'album', 'track']
cast: ['movie', 'episode', 'artist', 'album', 'track'],
vlcTelnet: ['track']
};
var bind = function bind(fn, thisArg) {
@ -19508,6 +19509,9 @@ class PlayController {
case 'kodi':
await this.playViaKodi(entity.value, data, data.type);
break;
case 'vlcTelnet':
await this.playViaVLCTelnet(entity.value, data.Media[0].Part[0].key, data.type);
break;
case 'androidtv':
if (lodash.isEqual(data.type, 'epg')) {
const session = `${Math.floor(Date.now() / 1000)}`;
@ -19752,6 +19756,22 @@ class PlayController {
throw Error(`Plex type ${type} is not supported in Kodi.`);
}
};
this.playViaVLCTelnet = async (entityName, mediaLink, type) => {
switch (type) {
case 'track':
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: 'music',
// eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`)
});
break;
default:
console.error(`Type ${type} is not supported on entity ${entityName}.`);
}
};
this.playViaCast = (entityName, mediaLink, contentType = 'video') => {
if (lodash.isEqual(contentType, 'video')) {
this.hass.callService('media_player', 'play_media', {
@ -19966,11 +19986,11 @@ class PlayController {
const entities = this.exportEntity(value, key);
lodash.forEach(entities, entity => {
if (lodash.includes(this.supported[entity.key], data.type)) {
// todo: load info in this.entityStates otherwise this will never work for input selects and templates
if ((entity.key === 'kodi' && this.isKodiSupported(entity.value)) ||
(entity.key === 'androidtv' && this.isAndroidTVSupported(entity.value)) ||
(entity.key === 'plexPlayer' && this.isPlexPlayerSupported(entity.value)) ||
(entity.key === 'cast' && this.isCastSupported(entity.value))) {
(entity.key === 'cast' && this.isCastSupported(entity.value)) ||
(entity.key === 'vlcTelnet' && this.isVLCTelnetSupported(entity.value))) {
service = { key: entity.key, value: entity.value };
return false;
}
@ -20126,6 +20146,12 @@ class PlayController {
}
return false;
};
this.isVLCTelnetSupported = (entityName) => {
return ((this.entityStates[entityName] &&
!lodash.isNil(this.entityStates[entityName].attributes) &&
this.entityStates[entityName].state !== 'unavailable') ||
!lodash.isEqual(this.runBefore, false));
};
this.isCastSupported = (entityName) => {
return ((this.entityStates[entityName] &&
!lodash.isNil(this.entityStates[entityName].attributes) &&
@ -22039,11 +22065,15 @@ class PlexMeetsHomeAssistant extends HTMLElement {
realEntityString = entityString.split(' | ')[3];
isPlexPlayer = true;
}
else if (lodash.isPlainObject(entityString)) {
realEntityString = entityString[Object.keys(entityString)[0]];
}
else if (lodash.startsWith(entityString, 'androidtv | ') ||
lodash.startsWith(entityString, 'kodi | ') ||
lodash.startsWith(entityString, 'cast | ') ||
lodash.startsWith(entityString, 'input_select | ') ||
lodash.startsWith(entityString, 'input_text | ')) {
lodash.startsWith(entityString, 'input_text | ') ||
lodash.startsWith(entityString, 'vlc_telnet | ')) {
// eslint-disable-next-line prefer-destructuring
realEntityString = entityString.split(' | ')[1];
isPlexPlayer = false;
@ -22094,7 +22124,15 @@ class PlexMeetsHomeAssistant extends HTMLElement {
}
entityObj.inputText.push(entityInRegister.entity_id);
break;
// pass
case 'vlc_telnet':
if (lodash.isNil(entityObj.vlcTelnet)) {
// eslint-disable-next-line no-param-reassign
entityObj.vlcTelnet = [];
}
entityObj.vlcTelnet.push(entityInRegister.entity_id);
break;
default:
console.error(`Entity ${entityInRegister.entity_id} is not supported.`);
}
}
});

@ -12,7 +12,8 @@ const supported: any = {
kodi: ['movie', 'episode', 'epg'],
androidtv: ['movie', 'show', 'season', 'episode', 'clip', 'track', 'artist', 'album'],
plexPlayer: ['movie', 'show', 'season', 'episode', 'clip', 'track', 'artist', 'album'],
cast: ['movie', 'episode', 'artist', 'album', 'track']
cast: ['movie', 'episode', 'artist', 'album', 'track'],
vlcTelnet: ['track']
};
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.

@ -156,6 +156,9 @@ class PlayController {
case 'kodi':
await this.playViaKodi(entity.value, data, data.type);
break;
case 'vlcTelnet':
await this.playViaVLCTelnet(entity.value, data.Media[0].Part[0].key, data.type);
break;
case 'androidtv':
if (_.isEqual(data.type, 'epg')) {
const session = `${Math.floor(Date.now() / 1000)}`;
@ -422,6 +425,23 @@ class PlayController {
}
};
private playViaVLCTelnet = async (entityName: string, mediaLink: string, type: string): Promise<void> => {
switch (type) {
case 'track':
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: 'music',
// eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`)
});
break;
default:
console.error(`Type ${type} is not supported on entity ${entityName}.`);
}
};
private playViaCast = (entityName: string, mediaLink: string, contentType = 'video'): void => {
if (_.isEqual(contentType, 'video')) {
this.hass.callService('media_player', 'play_media', {
@ -654,12 +674,12 @@ class PlayController {
_.forEach(entities, entity => {
if (_.includes(this.supported[entity.key], data.type)) {
// todo: load info in this.entityStates otherwise this will never work for input selects and templates
if (
(entity.key === 'kodi' && this.isKodiSupported(entity.value)) ||
(entity.key === 'androidtv' && this.isAndroidTVSupported(entity.value)) ||
(entity.key === 'plexPlayer' && this.isPlexPlayerSupported(entity.value)) ||
(entity.key === 'cast' && this.isCastSupported(entity.value))
(entity.key === 'cast' && this.isCastSupported(entity.value)) ||
(entity.key === 'vlcTelnet' && this.isVLCTelnetSupported(entity.value))
) {
service = { key: entity.key, value: entity.value };
return false;
@ -841,6 +861,15 @@ class PlayController {
return false;
};
private isVLCTelnetSupported = (entityName: string): boolean => {
return (
(this.entityStates[entityName] &&
!_.isNil(this.entityStates[entityName].attributes) &&
this.entityStates[entityName].state !== 'unavailable') ||
!_.isEqual(this.runBefore, false)
);
};
private isCastSupported = (entityName: string): boolean => {
return (
(this.entityStates[entityName] &&

@ -295,6 +295,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
// eslint-disable-next-line prefer-destructuring
realEntityString = entityString.split(' | ')[3];
isPlexPlayer = true;
} else if (_.isPlainObject(entityString)) {
realEntityString = entityString[(Object.keys(entityString) as Record<string, any>)[0]];
} else if (
_.startsWith(entityString, 'androidtv | ') ||
_.startsWith(entityString, 'kodi | ') ||

Loading…
Cancel
Save