|
|
@ -1,5 +1,6 @@
|
|
|
|
import NodePlexAPI from 'plex-api';
|
|
|
|
import NodePlexAPI from 'plex-api';
|
|
|
|
import { getSettings, Library, PlexSettings } from '../lib/settings';
|
|
|
|
import { getSettings, Library, PlexSettings } from '../lib/settings';
|
|
|
|
|
|
|
|
import logger from '../logger';
|
|
|
|
|
|
|
|
|
|
|
|
export interface PlexLibraryItem {
|
|
|
|
export interface PlexLibraryItem {
|
|
|
|
ratingKey: string;
|
|
|
|
ratingKey: string;
|
|
|
@ -145,28 +146,40 @@ class PlexAPI {
|
|
|
|
public async syncLibraries(): Promise<void> {
|
|
|
|
public async syncLibraries(): Promise<void> {
|
|
|
|
const settings = getSettings();
|
|
|
|
const settings = getSettings();
|
|
|
|
|
|
|
|
|
|
|
|
const libraries = await this.getLibraries();
|
|
|
|
try {
|
|
|
|
|
|
|
|
const libraries = await this.getLibraries();
|
|
|
|
const newLibraries: Library[] = libraries
|
|
|
|
|
|
|
|
// Remove libraries that are not movie or show
|
|
|
|
const newLibraries: Library[] = libraries
|
|
|
|
.filter((library) => library.type === 'movie' || library.type === 'show')
|
|
|
|
// Remove libraries that are not movie or show
|
|
|
|
// Remove libraries that do not have a metadata agent set (usually personal video libraries)
|
|
|
|
.filter(
|
|
|
|
.filter((library) => library.agent !== 'com.plexapp.agents.none')
|
|
|
|
(library) => library.type === 'movie' || library.type === 'show'
|
|
|
|
.map((library) => {
|
|
|
|
)
|
|
|
|
const existing = settings.plex.libraries.find(
|
|
|
|
// Remove libraries that do not have a metadata agent set (usually personal video libraries)
|
|
|
|
(l) => l.id === library.key && l.name === library.title
|
|
|
|
.filter((library) => library.agent !== 'com.plexapp.agents.none')
|
|
|
|
);
|
|
|
|
.map((library) => {
|
|
|
|
|
|
|
|
const existing = settings.plex.libraries.find(
|
|
|
|
return {
|
|
|
|
(l) => l.id === library.key && l.name === library.title
|
|
|
|
id: library.key,
|
|
|
|
);
|
|
|
|
name: library.title,
|
|
|
|
|
|
|
|
enabled: existing?.enabled ?? false,
|
|
|
|
return {
|
|
|
|
type: library.type,
|
|
|
|
id: library.key,
|
|
|
|
lastScan: existing?.lastScan,
|
|
|
|
name: library.title,
|
|
|
|
};
|
|
|
|
enabled: existing?.enabled ?? false,
|
|
|
|
|
|
|
|
type: library.type,
|
|
|
|
|
|
|
|
lastScan: existing?.lastScan,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
settings.plex.libraries = newLibraries;
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
logger.error('Failed to fetch Plex libraries', {
|
|
|
|
|
|
|
|
label: 'Plex API',
|
|
|
|
|
|
|
|
message: e.message,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
settings.plex.libraries = newLibraries;
|
|
|
|
settings.plex.libraries = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
settings.save();
|
|
|
|
settings.save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|