Update: Refactor playlist generator

vlc_telnet
Juraj Nyíri 3 years ago
parent 0526e8f43b
commit 8296198500

@ -19510,7 +19510,7 @@ class PlayController {
await this.playViaKodi(entity.value, data, data.type); await this.playViaKodi(entity.value, data, data.type);
break; break;
case 'vlcTelnet': case 'vlcTelnet':
await this.playViaVLCTelnet(entity.value, data.Media[0].Part[0].key, data.type); await this.playViaVLCTelnet(entity.value, data, data.type);
break; break;
case 'androidtv': case 'androidtv':
if (lodash.isEqual(data.type, 'epg')) { if (lodash.isEqual(data.type, 'epg')) {
@ -19617,8 +19617,8 @@ class PlayController {
await this.hass.callService(this.runAfter[0], this.runAfter[1], {}); await this.hass.callService(this.runAfter[0], this.runAfter[1], {});
} }
}; };
this.plexPlayerCreateQueue = async (movieID, plex) => { this.plexPlayerCreateQueue = async (key, plex, type, shuffle = false, repeat = false, continuous = false) => {
const url = `${plex.getBasicURL()}/playQueues?type=video&shuffle=0&repeat=0&continuous=1&own=1&uri=server://${await plex.getServerID()}/com.plexapp.plugins.library/library/metadata/${movieID}`; const url = `${plex.getBasicURL()}/playQueues?type=${type}&shuffle=${shuffle ? '1' : '0'}&repeat=${repeat ? '1' : '0'}&continuous=${continuous ? '1' : '0'}&own=1&uri=server://${await plex.getServerID()}/com.plexapp.plugins.library${key}`;
const plexResponse = await axios({ const plexResponse = await axios({
method: 'post', method: 'post',
url, url,
@ -19641,7 +19641,7 @@ class PlayController {
if (lodash.isObject(entity) && !lodash.isNil(entity.plex)) { if (lodash.isObject(entity) && !lodash.isNil(entity.plex)) {
plex = entity.plex; plex = entity.plex;
} }
const { playQueueID, playQueueSelectedMetadataItemID } = await this.plexPlayerCreateQueue(movieID, this.plex); const { playQueueID, playQueueSelectedMetadataItemID } = await this.plexPlayerCreateQueue(`/library/metadata/${movieID}`, this.plex, 'video');
let url = plex.getBasicURL(); let url = plex.getBasicURL();
url += `/player/playback/playMedia`; url += `/player/playback/playMedia`;
url += `?type=video`; url += `?type=video`;
@ -19756,7 +19756,7 @@ class PlayController {
throw Error(`Plex type ${type} is not supported in Kodi.`); throw Error(`Plex type ${type} is not supported in Kodi.`);
} }
}; };
this.playViaVLCTelnet = async (entityName, mediaLink, type) => { this.playViaVLCTelnet = async (entityName, data, type) => {
switch (type) { switch (type) {
case 'track': case 'track':
this.hass.callService('media_player', 'play_media', { this.hass.callService('media_player', 'play_media', {
@ -19765,7 +19765,7 @@ class PlayController {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
media_content_type: 'music', media_content_type: 'music',
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`) media_content_id: this.plex.authorizeURL(`${this.plex.getBasicURL()}${data.Media[0].Part[0].key}`)
}); });
break; break;
default: default:

@ -157,7 +157,7 @@ class PlayController {
await this.playViaKodi(entity.value, data, data.type); await this.playViaKodi(entity.value, data, data.type);
break; break;
case 'vlcTelnet': case 'vlcTelnet':
await this.playViaVLCTelnet(entity.value, data.Media[0].Part[0].key, data.type); await this.playViaVLCTelnet(entity.value, data, data.type);
break; break;
case 'androidtv': case 'androidtv':
if (_.isEqual(data.type, 'epg')) { if (_.isEqual(data.type, 'epg')) {
@ -281,8 +281,19 @@ class PlayController {
} }
}; };
private plexPlayerCreateQueue = async (movieID: number, plex: Plex): Promise<Record<string, number>> => { private plexPlayerCreateQueue = async (
const url = `${plex.getBasicURL()}/playQueues?type=video&shuffle=0&repeat=0&continuous=1&own=1&uri=server://${await plex.getServerID()}/com.plexapp.plugins.library/library/metadata/${movieID}`; key: string,
plex: Plex,
type: string,
shuffle = false,
repeat = false,
continuous = false
): Promise<Record<string, number>> => {
const url = `${plex.getBasicURL()}/playQueues?type=${type}&shuffle=${shuffle ? '1' : '0'}&repeat=${
repeat ? '1' : '0'
}&continuous=${
continuous ? '1' : '0'
}&own=1&uri=server://${await plex.getServerID()}/com.plexapp.plugins.library${key}`;
const plexResponse = await axios({ const plexResponse = await axios({
method: 'post', method: 'post',
@ -308,7 +319,11 @@ class PlayController {
if (_.isObject(entity) && !_.isNil(entity.plex)) { if (_.isObject(entity) && !_.isNil(entity.plex)) {
plex = entity.plex; plex = entity.plex;
} }
const { playQueueID, playQueueSelectedMetadataItemID } = await this.plexPlayerCreateQueue(movieID, this.plex); const { playQueueID, playQueueSelectedMetadataItemID } = await this.plexPlayerCreateQueue(
`/library/metadata/${movieID}`,
this.plex,
'video'
);
let url = plex.getBasicURL(); let url = plex.getBasicURL();
url += `/player/playback/playMedia`; url += `/player/playback/playMedia`;
@ -425,7 +440,7 @@ class PlayController {
} }
}; };
private playViaVLCTelnet = async (entityName: string, mediaLink: string, type: string): Promise<void> => { private playViaVLCTelnet = async (entityName: string, data: Record<string, any>, type: string): Promise<void> => {
switch (type) { switch (type) {
case 'track': case 'track':
this.hass.callService('media_player', 'play_media', { this.hass.callService('media_player', 'play_media', {
@ -434,7 +449,7 @@ class PlayController {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
media_content_type: 'music', media_content_type: 'music',
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
media_content_id: this.plex.authorizeURL(`${this.plex.getBasicURL()}${mediaLink}`) media_content_id: this.plex.authorizeURL(`${this.plex.getBasicURL()}${data.Media[0].Part[0].key}`)
}); });
break; break;
default: default:

Loading…
Cancel
Save