|
|
@ -10,6 +10,7 @@ import widgets from "widgets/widgets";
|
|
|
|
|
|
|
|
|
|
|
|
const proxyName = "plexProxyHandler";
|
|
|
|
const proxyName = "plexProxyHandler";
|
|
|
|
const librariesCacheKey = `${proxyName}__libraries`;
|
|
|
|
const librariesCacheKey = `${proxyName}__libraries`;
|
|
|
|
|
|
|
|
const albumsCacheKey = `${proxyName}__albums`;
|
|
|
|
const moviesCacheKey = `${proxyName}__movies`;
|
|
|
|
const moviesCacheKey = `${proxyName}__movies`;
|
|
|
|
const tvCacheKey = `${proxyName}__tv`;
|
|
|
|
const tvCacheKey = `${proxyName}__tv`;
|
|
|
|
const logger = createLogger(proxyName);
|
|
|
|
const logger = createLogger(proxyName);
|
|
|
@ -87,32 +88,41 @@ export default async function plexProxyHandler(req, res) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let albums = cache.get(`${albumsCacheKey}.${service}`);
|
|
|
|
let movies = cache.get(`${moviesCacheKey}.${service}`);
|
|
|
|
let movies = cache.get(`${moviesCacheKey}.${service}`);
|
|
|
|
let tv = cache.get(`${tvCacheKey}.${service}`);
|
|
|
|
let tv = cache.get(`${tvCacheKey}.${service}`);
|
|
|
|
if (movies === null || tv === null) {
|
|
|
|
if (albums === null || movies === null || tv === null) {
|
|
|
|
|
|
|
|
albums = 0;
|
|
|
|
movies = 0;
|
|
|
|
movies = 0;
|
|
|
|
tv = 0;
|
|
|
|
tv = 0;
|
|
|
|
logger.debug("Getting movie + tv counts from Plex API");
|
|
|
|
logger.debug("Getting counts from Plex API");
|
|
|
|
const movieTVLibraries = libraries.filter(l => ["movie", "show"].includes(l._attributes.type));
|
|
|
|
const movieTVLibraries = libraries.filter(l => ["movie", "show", "artist"].includes(l._attributes.type));
|
|
|
|
await Promise.all(movieTVLibraries.map(async (library) => {
|
|
|
|
await Promise.all(movieTVLibraries.map(async (library) => {
|
|
|
|
[status, apiData] = await fetchFromPlexAPI(`/library/sections/${library._attributes.key}/all`, widget);
|
|
|
|
const libraryURL = ["movie", "show"].includes(library._attributes.type) ?
|
|
|
|
|
|
|
|
`/library/sections/${library._attributes.key}/all` : // tv + movies
|
|
|
|
|
|
|
|
`/library/sections/${library._attributes.key}/albums`; // music
|
|
|
|
|
|
|
|
[status, apiData] = await fetchFromPlexAPI(libraryURL, widget);
|
|
|
|
if (apiData && apiData.MediaContainer) {
|
|
|
|
if (apiData && apiData.MediaContainer) {
|
|
|
|
const size = parseInt(apiData.MediaContainer._attributes.size, 10);
|
|
|
|
const size = parseInt(apiData.MediaContainer._attributes.size, 10);
|
|
|
|
if (library._attributes.type === "movie") {
|
|
|
|
if (library._attributes.type === "movie") {
|
|
|
|
movies += size;
|
|
|
|
movies += size;
|
|
|
|
} else if (library._attributes.type === "show") {
|
|
|
|
} else if (library._attributes.type === "show") {
|
|
|
|
tv += size;
|
|
|
|
tv += size;
|
|
|
|
|
|
|
|
} else if (library._attributes.type === "artist") {
|
|
|
|
|
|
|
|
albums += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
cache.put(`${albumsCacheKey}.${service}`, albums, 1000 * 60 * 10);
|
|
|
|
cache.put(`${tvCacheKey}.${service}`, tv, 1000 * 60 * 10);
|
|
|
|
cache.put(`${tvCacheKey}.${service}`, tv, 1000 * 60 * 10);
|
|
|
|
cache.put(`${moviesCacheKey}.${service}`, movies, 1000 * 60 * 10);
|
|
|
|
cache.put(`${moviesCacheKey}.${service}`, movies, 1000 * 60 * 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
const data = {
|
|
|
|
streams,
|
|
|
|
streams,
|
|
|
|
|
|
|
|
albums,
|
|
|
|
|
|
|
|
movies,
|
|
|
|
tv,
|
|
|
|
tv,
|
|
|
|
movies
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(status).send(data);
|
|
|
|
return res.status(status).send(data);
|
|
|
|