|
|
@ -85,17 +85,59 @@ class Plex {
|
|
|
|
return this.sections;
|
|
|
|
return this.sections;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
|
|
|
|
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> => {
|
|
|
|
getSectionsData = async (): Promise<any> => {
|
|
|
|
const sections = await this.getSections();
|
|
|
|
const sections = await this.getSections();
|
|
|
|
const sectionsRequests: Array<Promise<any>> = [];
|
|
|
|
const sectionsRequests: Array<Promise<any>> = [];
|
|
|
|
_.forEach(sections, section => {
|
|
|
|
_.forEach(sections, section => {
|
|
|
|
let url = this.authorizeURL(`${this.getBasicURL()}/library/sections/${section.key}/all`);
|
|
|
|
sectionsRequests.push(this.getSectionData(section.key));
|
|
|
|
url += `&sort=${this.sort}`;
|
|
|
|
|
|
|
|
sectionsRequests.push(
|
|
|
|
|
|
|
|
axios.get(url, {
|
|
|
|
|
|
|
|
timeout: this.requestTimeout
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return this.exportSectionsData(await Promise.all(sectionsRequests));
|
|
|
|
return this.exportSectionsData(await Promise.all(sectionsRequests));
|
|
|
|
};
|
|
|
|
};
|
|
|
|