Fix: Deck now automatically figures section ids

pull/16/head
Juraj Nyíri 4 years ago
parent e6e9971046
commit 0e4cc18846

@ -18729,12 +18729,17 @@ class Plex {
}); });
return this.exportSectionsData(await Promise.all(sectionsRequests)); return this.exportSectionsData(await Promise.all(sectionsRequests));
}; };
this.getContinueWatching = async (sections) => { this.getContinueWatching = async () => {
const cleanedUpSections = sections.replace(' ', ''); const sections = await this.getSections();
const url = this.authorizeURL(`${this.getBasicURL()}/hubs/continueWatching/items?contentDirectoryID=${cleanedUpSections}`); let sectionsString = '';
lodash.forEach(sections, section => {
sectionsString += `${section.key},`;
});
sectionsString = sectionsString.slice(0, -1);
const url = this.authorizeURL(`${this.getBasicURL()}/hubs/continueWatching/items?contentDirectoryID=${sectionsString}`);
return (await axios.get(url, { return (await axios.get(url, {
timeout: this.requestTimeout timeout: this.requestTimeout
})).data; })).data.MediaContainer;
}; };
this.getBasicURL = () => { this.getBasicURL = () => {
return `${this.protocol}://${this.ip}:${this.port}`; return `${this.protocol}://${this.ip}:${this.port}`;
@ -19863,14 +19868,14 @@ class PlexMeetsHomeAssistant extends HTMLElement {
try { try {
if (this.plex) { if (this.plex) {
await this.plex.init(); await this.plex.init();
const continueWatching = await this.plex.getContinueWatching('3,5,6'); const continueWatching = await this.plex.getContinueWatching();
const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]); const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]);
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
this.data.serverID = serverID; this.data.serverID = serverID;
lodash.forEach(plexSections, section => { lodash.forEach(plexSections, section => {
this.data[section.title1] = section.Metadata; this.data[section.title1] = section.Metadata;
}); });
this.data.Deck = continueWatching.MediaContainer.Metadata; this.data.Deck = continueWatching.Metadata;
if (this.data[this.config.libraryName] === undefined) { if (this.data[this.config.libraryName] === undefined) {
this.error = `Library name ${this.config.libraryName} does not exist.`; this.error = `Library name ${this.config.libraryName} does not exist.`;
} }

@ -94,16 +94,21 @@ class Plex {
return this.exportSectionsData(await Promise.all(sectionsRequests)); return this.exportSectionsData(await Promise.all(sectionsRequests));
}; };
getContinueWatching = async (sections: string): Promise<any> => { getContinueWatching = async (): Promise<any> => {
const cleanedUpSections = sections.replace(' ', ''); const sections = await this.getSections();
let sectionsString = '';
_.forEach(sections, section => {
sectionsString += `${section.key},`;
});
sectionsString = sectionsString.slice(0, -1);
const url = this.authorizeURL( const url = this.authorizeURL(
`${this.getBasicURL()}/hubs/continueWatching/items?contentDirectoryID=${cleanedUpSections}` `${this.getBasicURL()}/hubs/continueWatching/items?contentDirectoryID=${sectionsString}`
); );
return ( return (
await axios.get(url, { await axios.get(url, {
timeout: this.requestTimeout timeout: this.requestTimeout
}) })
).data; ).data.MediaContainer;
}; };
getBasicURL = (): string => { getBasicURL = (): string => {

@ -143,7 +143,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
try { try {
if (this.plex) { if (this.plex) {
await this.plex.init(); await this.plex.init();
const continueWatching = await this.plex.getContinueWatching('3,5,6'); const continueWatching = await this.plex.getContinueWatching();
const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]); const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]);
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
this.data.serverID = serverID; this.data.serverID = serverID;
@ -151,7 +151,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.data[section.title1] = section.Metadata; this.data[section.title1] = section.Metadata;
}); });
this.data.Deck = continueWatching.MediaContainer.Metadata; this.data.Deck = continueWatching.Metadata;
if (this.data[this.config.libraryName] === undefined) { if (this.data[this.config.libraryName] === undefined) {
this.error = `Library name ${this.config.libraryName} does not exist.`; this.error = `Library name ${this.config.libraryName} does not exist.`;

Loading…
Cancel
Save