Add: Use native Kodi channel functionality if available

live_tv_play
Juraj Nyíri 3 years ago
parent 30f26257f3
commit 7c7a260174

@ -19033,7 +19033,7 @@ class Plex {
let res = await axios.get(this.authorizeURL(decisionURL), { let res = await axios.get(this.authorizeURL(decisionURL), {
timeout: this.requestTimeout timeout: this.requestTimeout
}); });
while (parseFloat(res.data.MediaContainer.Metadata[0].Media[0].Part[0].key.split('offset=')[1].split('&')[0]) < 10) { while (parseFloat(res.data.MediaContainer.Metadata[0].Media[0].Part[0].key.split('offset=')[1].split('&')[0]) < 3) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await sleep(500); await sleep(500);
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
@ -19333,7 +19333,7 @@ class PlayController {
this.getKodiSearchResults = async () => { this.getKodiSearchResults = async () => {
return JSON.parse((await getState(this.hass, 'sensor.kodi_media_sensor_search')).attributes.data); return JSON.parse((await getState(this.hass, 'sensor.kodi_media_sensor_search')).attributes.data);
}; };
this.getKodiSearch = async (search) => { this.getKodiSearch = async (search, silent = false) => {
await this.hass.callService('kodi_media_sensors', 'call_method', { await this.hass.callService('kodi_media_sensors', 'call_method', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: 'sensor.kodi_media_sensor_search', entity_id: 'sensor.kodi_media_sensor_search',
@ -19351,8 +19351,12 @@ class PlayController {
foundResult = result; foundResult = result;
return false; return false;
} }
if (lodash.isEqual(result.label, search)) {
foundResult = result;
return false;
}
}); });
if (lodash.isEmpty(foundResult)) { if (lodash.isEmpty(foundResult) && !silent) {
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
alert(`Title ${search} not found in Kodi.`); alert(`Title ${search} not found in Kodi.`);
throw Error(`Title ${search} not found in Kodi.`); throw Error(`Title ${search} not found in Kodi.`);
@ -19549,6 +19553,18 @@ class PlayController {
}; };
this.playViaKodi = async (entityName, data, type) => { this.playViaKodi = async (entityName, data, type) => {
if (!lodash.isNil(lodash.get(data, 'epg.Media[0].channelCallSign'))) { if (!lodash.isNil(lodash.get(data, 'epg.Media[0].channelCallSign'))) {
try {
const kodiData = await this.getKodiSearch(lodash.get(data, 'epg.Media[0].channelCallSign'), true);
await this.hass.callService('kodi', 'call_method', {
// eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName,
method: 'Player.Open',
item: {
channelid: kodiData.channelid
}
});
}
catch (err) {
const streamLink = `${this.plex.getBasicURL()}${await this.plex.tune(data.channelIdentifier, 'todo')}`; const streamLink = `${this.plex.getBasicURL()}${await this.plex.tune(data.channelIdentifier, 'todo')}`;
await this.hass.callService('kodi', 'call_method', { await this.hass.callService('kodi', 'call_method', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
@ -19559,6 +19575,7 @@ class PlayController {
} }
}); });
} }
}
else if (type === 'movie') { else if (type === 'movie') {
const kodiData = await this.getKodiSearch(data.title); const kodiData = await this.getKodiSearch(data.title);
await this.hass.callService('kodi', 'call_method', { await this.hass.callService('kodi', 'call_method', {

@ -49,7 +49,7 @@ class PlayController {
return JSON.parse((await getState(this.hass, 'sensor.kodi_media_sensor_search')).attributes.data); return JSON.parse((await getState(this.hass, 'sensor.kodi_media_sensor_search')).attributes.data);
}; };
private getKodiSearch = async (search: string): Promise<Record<string, any>> => { private getKodiSearch = async (search: string, silent = false): Promise<Record<string, any>> => {
await this.hass.callService('kodi_media_sensors', 'call_method', { await this.hass.callService('kodi_media_sensors', 'call_method', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: 'sensor.kodi_media_sensor_search', entity_id: 'sensor.kodi_media_sensor_search',
@ -67,8 +67,12 @@ class PlayController {
foundResult = result; foundResult = result;
return false; return false;
} }
if (_.isEqual(result.label, search)) {
foundResult = result;
return false;
}
}); });
if (_.isEmpty(foundResult)) { if (_.isEmpty(foundResult) && !silent) {
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
alert(`Title ${search} not found in Kodi.`); alert(`Title ${search} not found in Kodi.`);
throw Error(`Title ${search} not found in Kodi.`); throw Error(`Title ${search} not found in Kodi.`);
@ -280,6 +284,18 @@ class PlayController {
private playViaKodi = async (entityName: string, data: Record<string, any>, type: string): Promise<void> => { private playViaKodi = async (entityName: string, data: Record<string, any>, type: string): Promise<void> => {
if (!_.isNil(_.get(data, 'epg.Media[0].channelCallSign'))) { if (!_.isNil(_.get(data, 'epg.Media[0].channelCallSign'))) {
try {
const kodiData = await this.getKodiSearch(_.get(data, 'epg.Media[0].channelCallSign'), true);
await this.hass.callService('kodi', 'call_method', {
// eslint-disable-next-line @typescript-eslint/camelcase
entity_id: entityName,
method: 'Player.Open',
item: {
channelid: kodiData.channelid
}
});
} catch (err) {
const streamLink = `${this.plex.getBasicURL()}${await this.plex.tune(data.channelIdentifier, 'todo')}`; const streamLink = `${this.plex.getBasicURL()}${await this.plex.tune(data.channelIdentifier, 'todo')}`;
await this.hass.callService('kodi', 'call_method', { await this.hass.callService('kodi', 'call_method', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
@ -289,6 +305,7 @@ class PlayController {
file: streamLink file: streamLink
} }
}); });
}
} else if (type === 'movie') { } else if (type === 'movie') {
const kodiData = await this.getKodiSearch(data.title); const kodiData = await this.getKodiSearch(data.title);
await this.hass.callService('kodi', 'call_method', { await this.hass.callService('kodi', 'call_method', {

@ -475,9 +475,7 @@ class Plex {
let res = await axios.get(this.authorizeURL(decisionURL), { let res = await axios.get(this.authorizeURL(decisionURL), {
timeout: this.requestTimeout timeout: this.requestTimeout
}); });
while ( while (parseFloat(res.data.MediaContainer.Metadata[0].Media[0].Part[0].key.split('offset=')[1].split('&')[0]) < 3) {
parseFloat(res.data.MediaContainer.Metadata[0].Media[0].Part[0].key.split('offset=')[1].split('&')[0]) < 10
) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await sleep(500); await sleep(500);
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop

Loading…
Cancel
Save