Add: Get EPG WIP

live_tv
Juraj Nyíri 3 years ago
parent b9ed39b629
commit 73d8b030f7

@ -18676,6 +18676,7 @@ class Plex {
this.sections = [];
this.providers = [];
this.livetv = {};
this.livetvepg = {};
this.collections = false;
this.playlists = [];
this.init = async () => {
@ -18727,6 +18728,34 @@ class Plex {
}
return this.livetv;
};
this.getEPG = async () => {
if (lodash.isEmpty(this.livetvepg)) {
const returnData = {};
const providers = await this.getProviders();
const liveTVRequests = [];
const liveTVRequestsNames = [];
lodash.forEach(providers, provider => {
if (lodash.isEqual(provider.protocols, 'livetv')) {
let url = this.authorizeURL(`${this.getBasicURL()}/${provider.identifier}/grid?type=1&sort=beginsAt`);
url += `&endsAt>=${Math.floor(Date.now() / 1000)}`;
url += `&beginsAt<=${Math.floor(Date.now() / 1000)}`;
liveTVRequests.push(axios.get(url, {
timeout: this.requestTimeout
}));
liveTVRequestsNames.push(provider.title);
}
});
const allResults = await Promise.all(liveTVRequests);
lodash.forEach(allResults, (result, key) => {
returnData[liveTVRequestsNames[key]] = {};
lodash.forEach(result.data.MediaContainer.Metadata, data => {
returnData[liveTVRequestsNames[key]][data.Media[0].channelCallSign] = data;
});
});
this.livetvepg = returnData;
}
return this.livetvepg;
};
this.getServerID = async () => {
if (lodash.isEmpty(this.serverInfo)) {
await this.getServerInfo();
@ -21231,6 +21260,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
const getLiveTV = async () => {
if (this.plex) {
const liveTV = await this.plex.getLiveTV();
console.log(await this.plex.getEPG());
lodash.forEach(liveTV, (data, key) => {
this.data[key] = data;
});

@ -25,6 +25,8 @@ class Plex {
livetv: Record<string, any> = {};
livetvepg: Record<string, any> = {};
collections: Array<Record<string, any>> | false = false;
playlists: Array<Record<string, any>> = [];
@ -97,6 +99,37 @@ class Plex {
return this.livetv;
};
getEPG = async (): Promise<Record<string, any>> => {
if (_.isEmpty(this.livetvepg)) {
const returnData: Record<string, any> = {};
const providers = await this.getProviders();
const liveTVRequests: Array<Promise<any>> = [];
const liveTVRequestsNames: Array<string> = [];
_.forEach(providers, provider => {
if (_.isEqual(provider.protocols, 'livetv')) {
let url = this.authorizeURL(`${this.getBasicURL()}/${provider.identifier}/grid?type=1&sort=beginsAt`);
url += `&endsAt>=${Math.floor(Date.now() / 1000)}`;
url += `&beginsAt<=${Math.floor(Date.now() / 1000)}`;
liveTVRequests.push(
axios.get(url, {
timeout: this.requestTimeout
})
);
liveTVRequestsNames.push(provider.title);
}
});
const allResults = await Promise.all(liveTVRequests);
_.forEach(allResults, (result, key) => {
returnData[liveTVRequestsNames[key]] = {};
_.forEach(result.data.MediaContainer.Metadata, data => {
returnData[liveTVRequestsNames[key]][data.Media[0].channelCallSign] = data;
});
});
this.livetvepg = returnData;
}
return this.livetvepg;
};
getServerID = async (): Promise<any> => {
if (_.isEmpty(this.serverInfo)) {
await this.getServerInfo();

@ -406,6 +406,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
const getLiveTV = async (): Promise<void> => {
if (this.plex) {
const liveTV = await this.plex.getLiveTV();
console.log(await this.plex.getEPG());
_.forEach(liveTV, (data, key) => {
this.data[key] = data;
});

Loading…
Cancel
Save