|
|
|
@ -85,18 +85,60 @@ class Plex {
|
|
|
|
|
return this.sections;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getSectionsData = async (): Promise<any> => {
|
|
|
|
|
const sections = await this.getSections();
|
|
|
|
|
const sectionsRequests: Array<Promise<any>> = [];
|
|
|
|
|
_.forEach(sections, section => {
|
|
|
|
|
let url = this.authorizeURL(`${this.getBasicURL()}/library/sections/${section.key}/all`);
|
|
|
|
|
getSectionData = async (sectionID: number): Promise<any> => {
|
|
|
|
|
const bulkItems = 50;
|
|
|
|
|
let url = this.authorizeURL(`${this.getBasicURL()}/library/sections/${sectionID}/all`);
|
|
|
|
|
url += `&sort=${this.sort}`;
|
|
|
|
|
let result: Record<string, any> = {};
|
|
|
|
|
try {
|
|
|
|
|
result = await axios.get(url, {
|
|
|
|
|
timeout: this.requestTimeout
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
// probably hitting limit of items to return, we need to request in parts
|
|
|
|
|
if (_.includes(err.message, 'Request failed with status code 500')) {
|
|
|
|
|
url += `&X-Plex-Container-Start=0&X-Plex-Container-Size=${bulkItems}`;
|
|
|
|
|
result = await axios.get(url, {
|
|
|
|
|
timeout: this.requestTimeout
|
|
|
|
|
});
|
|
|
|
|
const { totalSize } = result.data.MediaContainer;
|
|
|
|
|
let startOfItems = bulkItems;
|
|
|
|
|
const sectionsRequests: Array<Promise<any>> = [];
|
|
|
|
|
while (startOfItems < totalSize) {
|
|
|
|
|
sectionsRequests.push(
|
|
|
|
|
axios.get(url, {
|
|
|
|
|
axios.get(
|
|
|
|
|
this.authorizeURL(
|
|
|
|
|
`${this.getBasicURL()}/library/sections/${sectionID}/all?sort=${
|
|
|
|
|
this.sort
|
|
|
|
|
}&X-Plex-Container-Start=${startOfItems}&X-Plex-Container-Size=${bulkItems}`
|
|
|
|
|
),
|
|
|
|
|
{
|
|
|
|
|
timeout: this.requestTimeout
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
startOfItems += bulkItems;
|
|
|
|
|
}
|
|
|
|
|
const allResults = await Promise.all(sectionsRequests);
|
|
|
|
|
_.forEach(allResults, multiResult => {
|
|
|
|
|
result.data.MediaContainer.Metadata = _.concat(
|
|
|
|
|
result.data.MediaContainer.Metadata,
|
|
|
|
|
multiResult.data.MediaContainer.Metadata
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getSectionsData = async (): Promise<any> => {
|
|
|
|
|
const sections = await this.getSections();
|
|
|
|
|
const sectionsRequests: Array<Promise<any>> = [];
|
|
|
|
|
_.forEach(sections, section => {
|
|
|
|
|
sectionsRequests.push(this.getSectionData(section.key));
|
|
|
|
|
});
|
|
|
|
|
return this.exportSectionsData(await Promise.all(sectionsRequests));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|