diff --git a/overseerr-api.yml b/overseerr-api.yml index 07da768af..28bdcadb2 100644 --- a/overseerr-api.yml +++ b/overseerr-api.yml @@ -643,7 +643,6 @@ components: readOnly: true requestedBy: $ref: '#/components/schemas/User' - readOnly: true modifiedBy: anyOf: - $ref: '#/components/schemas/User' diff --git a/server/api/plexapi.ts b/server/api/plexapi.ts index c8e123710..cc71b07e7 100644 --- a/server/api/plexapi.ts +++ b/server/api/plexapi.ts @@ -4,10 +4,12 @@ import { getSettings } from '../lib/settings'; export interface PlexLibraryItem { ratingKey: string; parentRatingKey?: string; + grandparentRatingKey?: string; title: string; guid: string; parentGuid?: string; - type: 'movie' | 'show' | 'season'; + grandparentGuid?: string; + type: 'movie' | 'show' | 'season' | 'episode'; } interface PlexLibraryResponse { @@ -20,6 +22,7 @@ export interface PlexLibrary { type: 'show' | 'movie'; key: string; title: string; + agent: string; } interface PlexLibrariesResponse { @@ -120,9 +123,9 @@ class PlexAPI { return response.MediaContainer.Metadata[0]; } - public async getRecentlyAdded(): Promise { + public async getRecentlyAdded(id: string): Promise { const response = await this.plexClient.query( - '/library/recentlyAdded' + `/library/sections/${id}/recentlyAdded` ); return response.MediaContainer.Metadata; diff --git a/server/job/plexsync/index.ts b/server/job/plexsync/index.ts index cefce9fd1..d64e5898d 100644 --- a/server/job/plexsync/index.ts +++ b/server/job/plexsync/index.ts @@ -137,7 +137,9 @@ class JobPlexSync { try { const metadata = await this.plexClient.getMetadata( - plexitem.parentRatingKey ?? plexitem.ratingKey, + plexitem.grandparentRatingKey ?? + plexitem.parentRatingKey ?? + plexitem.ratingKey, { includeChildren: true } ); if (metadata.guid.match(tvdbRegex)) { @@ -240,7 +242,9 @@ class JobPlexSync { } catch (e) { this.log( `Failed to process plex item. ratingKey: ${ - plexitem.parentRatingKey ?? plexitem.ratingKey + plexitem.grandparentRatingKey ?? + plexitem.parentRatingKey ?? + plexitem.ratingKey }`, 'error' ); @@ -252,7 +256,11 @@ class JobPlexSync { slicedItems.map(async (plexitem) => { if (plexitem.type === 'movie') { await this.processMovie(plexitem); - } else if (plexitem.type === 'show') { + } else if ( + plexitem.type === 'show' || + plexitem.type === 'episode' || + plexitem.type === 'season' + ) { await this.processShow(plexitem); } }) @@ -301,20 +309,22 @@ class JobPlexSync { }); this.plexClient = new PlexAPI({ plexToken: admin.plexToken }); + + this.libraries = settings.plex.libraries.filter( + (library) => library.enabled + ); + if (this.isRecentOnly) { - this.currentLibrary = { - id: '0', - name: 'Recently Added', - enabled: true, - }; - this.log(`Beginning to process recently added`, 'info'); - this.items = await this.plexClient.getRecentlyAdded(); - await this.loop(); + for (const library of this.libraries) { + this.currentLibrary = library; + this.log( + `Beginning to process recently added for library: ${library.name}`, + 'info' + ); + this.items = await this.plexClient.getRecentlyAdded(library.id); + await this.loop(); + } } else { - this.libraries = settings.plex.libraries.filter( - (library) => library.enabled - ); - for (const library of this.libraries) { this.currentLibrary = library; this.log(`Beginning to process library: ${library.name}`, 'info');