|
|
@ -18675,12 +18675,7 @@ class Plex {
|
|
|
|
this.requestTimeout = 10000;
|
|
|
|
this.requestTimeout = 10000;
|
|
|
|
this.sections = [];
|
|
|
|
this.sections = [];
|
|
|
|
this.init = async () => {
|
|
|
|
this.init = async () => {
|
|
|
|
await this.getClients();
|
|
|
|
await Promise.all([this.getSections(), this.getClients(), this.getServerID()]);
|
|
|
|
/*
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
|
|
|
this.getClients();
|
|
|
|
|
|
|
|
}, 30000);
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
this.getClients = async () => {
|
|
|
|
this.getClients = async () => {
|
|
|
|
const url = this.authorizeURL(`${this.getBasicURL()}/clients`);
|
|
|
|
const url = this.authorizeURL(`${this.getBasicURL()}/clients`);
|
|
|
@ -18719,6 +18714,9 @@ class Plex {
|
|
|
|
return this.sections;
|
|
|
|
return this.sections;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
this.getSectionData = async (sectionID) => {
|
|
|
|
this.getSectionData = async (sectionID) => {
|
|
|
|
|
|
|
|
return this.exportSectionsData([await this.getSectionDataWithoutProcessing(sectionID)]);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getSectionDataWithoutProcessing = async (sectionID) => {
|
|
|
|
const bulkItems = 50;
|
|
|
|
const bulkItems = 50;
|
|
|
|
let url = this.authorizeURL(`${this.getBasicURL()}/library/sections/${sectionID}/all`);
|
|
|
|
let url = this.authorizeURL(`${this.getBasicURL()}/library/sections/${sectionID}/all`);
|
|
|
|
url += `&sort=${this.sort}`;
|
|
|
|
url += `&sort=${this.sort}`;
|
|
|
@ -18759,7 +18757,7 @@ class Plex {
|
|
|
|
const sections = await this.getSections();
|
|
|
|
const sections = await this.getSections();
|
|
|
|
const sectionsRequests = [];
|
|
|
|
const sectionsRequests = [];
|
|
|
|
lodash.forEach(sections, section => {
|
|
|
|
lodash.forEach(sections, section => {
|
|
|
|
sectionsRequests.push(this.getSectionData(section.key));
|
|
|
|
sectionsRequests.push(this.getSectionDataWithoutProcessing(section.key));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return this.exportSectionsData(await Promise.all(sectionsRequests));
|
|
|
|
return this.exportSectionsData(await Promise.all(sectionsRequests));
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -20954,73 +20952,114 @@ class PlexMeetsHomeAssistant extends HTMLElement {
|
|
|
|
await this.playController.init();
|
|
|
|
await this.playController.init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await this.plex.init();
|
|
|
|
await this.plex.init();
|
|
|
|
try {
|
|
|
|
const plexAllSections = await this.plex.getSections();
|
|
|
|
const onDeck = await this.plex.getOnDeck();
|
|
|
|
const getOnDeck = async () => {
|
|
|
|
this.data.Deck = onDeck.Metadata;
|
|
|
|
if (this.plex) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
catch (err) {
|
|
|
|
const onDeck = await this.plex.getOnDeck();
|
|
|
|
if (lodash.includes(err.message, 'Request failed with status code 404')) {
|
|
|
|
this.data.Deck = onDeck.Metadata;
|
|
|
|
console.warn(getOldPlexServerErrorMessage('Deck'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
else {
|
|
|
|
if (lodash.includes(err.message, 'Request failed with status code 404')) {
|
|
|
|
throw err;
|
|
|
|
console.warn(getOldPlexServerErrorMessage('Deck'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
throw err;
|
|
|
|
const continueWatching = await this.plex.getContinueWatching();
|
|
|
|
}
|
|
|
|
this.data['Continue Watching'] = continueWatching.Metadata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
|
|
|
|
if (lodash.includes(err.message, 'Request failed with status code 404')) {
|
|
|
|
|
|
|
|
console.warn(getOldPlexServerErrorMessage('Continue Watching'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
const getContinueWatching = async () => {
|
|
|
|
const watchNext = await this.plex.getWatchNext();
|
|
|
|
if (this.plex) {
|
|
|
|
this.data['Watch Next'] = watchNext.Metadata;
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
const continueWatching = await this.plex.getContinueWatching();
|
|
|
|
catch (err) {
|
|
|
|
this.data['Continue Watching'] = continueWatching.Metadata;
|
|
|
|
if (lodash.includes(err.message, 'Request failed with status code 404')) {
|
|
|
|
}
|
|
|
|
console.warn(getOldPlexServerErrorMessage('Watch Next'));
|
|
|
|
catch (err) {
|
|
|
|
|
|
|
|
if (lodash.includes(err.message, 'Request failed with status code 404')) {
|
|
|
|
|
|
|
|
console.warn(getOldPlexServerErrorMessage('Continue Watching'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
};
|
|
|
|
throw err;
|
|
|
|
const getWatchNext = async () => {
|
|
|
|
|
|
|
|
if (this.plex) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const watchNext = await this.plex.getWatchNext();
|
|
|
|
|
|
|
|
this.data['Watch Next'] = watchNext.Metadata;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
|
|
|
|
if (lodash.includes(err.message, 'Request failed with status code 404')) {
|
|
|
|
|
|
|
|
console.warn(getOldPlexServerErrorMessage('Watch Next'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
const getRecentyAdded = async () => {
|
|
|
|
const recentlyAdded = await this.plex.getRecentyAdded();
|
|
|
|
if (this.plex) {
|
|
|
|
this.data['Recently Added'] = recentlyAdded.Metadata;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
|
|
|
|
if (lodash.includes(err.message, 'Request failed with status code 404')) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
console.warn('PlexMeetsHomeAssistant: Using old endpoint for recently added tv shows. Consider updating your Plex server.');
|
|
|
|
const recentlyAdded = await this.plex.getRecentyAdded();
|
|
|
|
const recentlyAdded = await this.plex.getRecentyAdded(true);
|
|
|
|
|
|
|
|
this.data['Recently Added'] = recentlyAdded.Metadata;
|
|
|
|
this.data['Recently Added'] = recentlyAdded.Metadata;
|
|
|
|
// eslint-disable-next-line no-shadow
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
catch (err) {
|
|
|
|
if (lodash.includes(err.message, 'Request failed with status code 404')) {
|
|
|
|
if (lodash.includes(err.message, 'Request failed with status code 404')) {
|
|
|
|
console.warn(getOldPlexServerErrorMessage('Recently Added'));
|
|
|
|
try {
|
|
|
|
|
|
|
|
console.warn('PlexMeetsHomeAssistant: Using old endpoint for recently added tv shows. Consider updating your Plex server.');
|
|
|
|
|
|
|
|
const recentlyAdded = await this.plex.getRecentyAdded(true);
|
|
|
|
|
|
|
|
this.data['Recently Added'] = recentlyAdded.Metadata;
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-shadow
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
|
|
|
|
if (lodash.includes(err.message, 'Request failed with status code 404')) {
|
|
|
|
|
|
|
|
console.warn(getOldPlexServerErrorMessage('Recently Added'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
throw err;
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
};
|
|
|
|
throw err;
|
|
|
|
let sectionKey = 0;
|
|
|
|
|
|
|
|
lodash.forEach(plexAllSections, (section) => {
|
|
|
|
|
|
|
|
if (lodash.isEqual(section.title, this.config.libraryName)) {
|
|
|
|
|
|
|
|
sectionKey = section.key;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
const [serverID, plexSections] = await Promise.all([this.plex.getServerID(), this.plex.getSectionsData()]);
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
|
|
|
|
|
|
this.data.serverID = serverID;
|
|
|
|
|
|
|
|
lodash.forEach(plexSections, section => {
|
|
|
|
|
|
|
|
this.data[section.title1] = section.Metadata;
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const loadDataRequests = [];
|
|
|
|
|
|
|
|
if (sectionKey) {
|
|
|
|
|
|
|
|
loadDataRequests.push(this.plex.getSectionData(sectionKey));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lodash.isEqual(this.config.libraryName, 'Deck')) {
|
|
|
|
|
|
|
|
loadDataRequests.push(getOnDeck());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (lodash.isEqual(this.config.libraryName, 'Continue Watching')) {
|
|
|
|
|
|
|
|
loadDataRequests.push(getContinueWatching());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (lodash.isEqual(this.config.libraryName, 'Watch Next')) {
|
|
|
|
|
|
|
|
loadDataRequests.push(getWatchNext());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (lodash.isEqual(this.config.libraryName, 'Recently Added')) {
|
|
|
|
|
|
|
|
loadDataRequests.push(getRecentyAdded());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const [plexSections] = await Promise.all(loadDataRequests);
|
|
|
|
|
|
|
|
if (plexSections && sectionKey) {
|
|
|
|
|
|
|
|
lodash.forEach(plexSections, section => {
|
|
|
|
|
|
|
|
this.data[section.title1] = section.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.`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|