Add: Getting providers and live tv channels

live_tv
Juraj Nyíri 3 years ago
parent 69def579da
commit fa37fbda00

@ -18674,6 +18674,8 @@ class Plex {
this.clients = [];
this.requestTimeout = 10000;
this.sections = [];
this.providers = [];
this.livetv = {};
this.collections = false;
this.playlists = [];
this.init = async () => {
@ -18692,6 +18694,39 @@ class Plex {
}
return this.clients;
};
this.getProviders = async () => {
if (lodash.isEmpty(this.providers)) {
const url = this.authorizeURL(`${this.getBasicURL()}/media/providers`);
const providersData = await axios.get(url, {
timeout: this.requestTimeout
});
this.providers = providersData.data.MediaContainer.MediaProvider;
}
return this.providers;
};
this.getLiveTV = async () => {
if (lodash.isEmpty(this.livetv)) {
const returnData = {};
const providers = await this.getProviders();
const liveTVRequests = [];
const liveTVRequestsNames = [];
lodash.forEach(providers, provider => {
if (lodash.isEqual(provider.protocols, 'livetv')) {
const url = this.authorizeURL(`${this.getBasicURL()}/${provider.identifier}/tags?type=310`);
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]] = result.data.MediaContainer.Directory;
});
this.livetv = returnData;
}
return this.livetv;
};
this.getServerID = async () => {
if (lodash.isEmpty(this.serverInfo)) {
await this.getServerInfo();
@ -21108,6 +21143,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
}
await this.plex.init();
const plexAllSections = await this.plex.getSections();
console.log(await this.plex.getLiveTV());
const getOnDeck = async () => {
if (this.plex) {
try {

@ -21,6 +21,10 @@ class Plex {
sections: Array<Record<string, any>> = [];
providers: Array<Record<string, any>> = [];
livetv: Record<string, any> = {};
collections: Array<Record<string, any>> | false = false;
playlists: Array<Record<string, any>> = [];
@ -56,6 +60,43 @@ class Plex {
return this.clients;
};
getProviders = async (): Promise<any> => {
if (_.isEmpty(this.providers)) {
const url = this.authorizeURL(`${this.getBasicURL()}/media/providers`);
const providersData = await axios.get(url, {
timeout: this.requestTimeout
});
this.providers = providersData.data.MediaContainer.MediaProvider;
}
return this.providers;
};
getLiveTV = async (): Promise<Record<string, any>> => {
if (_.isEmpty(this.livetv)) {
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')) {
const url = this.authorizeURL(`${this.getBasicURL()}/${provider.identifier}/tags?type=310`);
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]] = result.data.MediaContainer.Directory;
});
this.livetv = returnData;
}
return this.livetv;
};
getServerID = async (): Promise<any> => {
if (_.isEmpty(this.serverInfo)) {
await this.getServerInfo();

@ -333,6 +333,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
await this.plex.init();
const plexAllSections = await this.plex.getSections();
console.log(await this.plex.getLiveTV());
const getOnDeck = async (): Promise<void> => {
if (this.plex) {
try {

Loading…
Cancel
Save