Compare commits
3 Commits
renovate/r
...
preview-pl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb08eb024f | ||
|
|
b5c8e21104 | ||
|
|
54baa53aac |
@@ -27,10 +27,13 @@ export interface PlexLibraryItem {
|
|||||||
Media: Media[];
|
Media: Media[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PlexLibraryResponse {
|
interface PlexLibraryResponseRaw {
|
||||||
MediaContainer: {
|
MediaContainer: {
|
||||||
totalSize: number;
|
totalSize?: number;
|
||||||
Metadata: PlexLibraryItem[];
|
size?: number;
|
||||||
|
Metadata?: PlexLibraryItem[];
|
||||||
|
Directory?: PlexLibraryItem[];
|
||||||
|
[key: string]: unknown;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +180,7 @@ class PlexAPI extends ExternalAPI {
|
|||||||
id: string,
|
id: string,
|
||||||
{ offset = 0, size = 50 }: { offset?: number; size?: number } = {}
|
{ offset = 0, size = 50 }: { offset?: number; size?: number } = {}
|
||||||
): Promise<{ totalSize: number; items: PlexLibraryItem[] }> {
|
): Promise<{ totalSize: number; items: PlexLibraryItem[] }> {
|
||||||
const response = await this.get<PlexLibraryResponse>(
|
const response = await this.get<PlexLibraryResponseRaw>(
|
||||||
`/library/sections/${id}/all?includeGuids=1`,
|
`/library/sections/${id}/all?includeGuids=1`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -187,9 +190,26 @@ class PlexAPI extends ExternalAPI {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const container = response.MediaContainer;
|
||||||
|
const metadataLength = container.Metadata?.length ?? 0;
|
||||||
|
const directoryLength = container.Directory?.length ?? 0;
|
||||||
|
|
||||||
|
logger.debug('Plex getLibraryContents raw response', {
|
||||||
|
label: 'Plex API',
|
||||||
|
libraryId: id,
|
||||||
|
offset,
|
||||||
|
metadataLength,
|
||||||
|
directoryLength,
|
||||||
|
totalSize: container.totalSize,
|
||||||
|
size: container.size,
|
||||||
|
keys: Object.keys(container).filter((k) =>
|
||||||
|
['Metadata', 'Directory', 'totalSize', 'size'].includes(k)
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalSize: response.MediaContainer.totalSize,
|
totalSize: container.totalSize ?? 0,
|
||||||
items: response.MediaContainer.Metadata ?? [],
|
items: container.Metadata ?? [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +241,7 @@ class PlexAPI extends ExternalAPI {
|
|||||||
},
|
},
|
||||||
mediaType: 'movie' | 'show'
|
mediaType: 'movie' | 'show'
|
||||||
): Promise<PlexLibraryItem[]> {
|
): Promise<PlexLibraryItem[]> {
|
||||||
const response = await this.get<PlexLibraryResponse>(
|
const response = await this.get<PlexLibraryResponseRaw>(
|
||||||
`/library/sections/${id}/all?type=${
|
`/library/sections/${id}/all?type=${
|
||||||
mediaType === 'show' ? '4' : '1'
|
mediaType === 'show' ? '4' : '1'
|
||||||
}&sort=addedAt%3Adesc&addedAt>>=${Math.floor(options.addedAt / 1000)}`,
|
}&sort=addedAt%3Adesc&addedAt>>=${Math.floor(options.addedAt / 1000)}`,
|
||||||
@@ -233,7 +253,21 @@ class PlexAPI extends ExternalAPI {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return response.MediaContainer.Metadata;
|
const container = response.MediaContainer;
|
||||||
|
const items = container.Metadata ?? [];
|
||||||
|
|
||||||
|
logger.debug('Plex getRecentlyAdded raw response', {
|
||||||
|
label: 'Plex API',
|
||||||
|
libraryId: id,
|
||||||
|
mediaType,
|
||||||
|
addedAtFilter: options.addedAt,
|
||||||
|
addedAtFilterDate: new Date(options.addedAt).toISOString(),
|
||||||
|
metadataLength: container.Metadata?.length ?? 0,
|
||||||
|
directoryLength: container.Directory?.length ?? 0,
|
||||||
|
itemsReturned: items.length,
|
||||||
|
});
|
||||||
|
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,22 +90,41 @@ class PlexScanner
|
|||||||
if (this.isRecentOnly) {
|
if (this.isRecentOnly) {
|
||||||
for (const library of this.libraries) {
|
for (const library of this.libraries) {
|
||||||
this.currentLibrary = library;
|
this.currentLibrary = library;
|
||||||
this.log(
|
const addedAtOpt = library.lastScan
|
||||||
`Beginning to process recently added for library: ${library.name}`,
|
|
||||||
'info',
|
|
||||||
{ lastScan: library.lastScan }
|
|
||||||
);
|
|
||||||
const libraryItems = await this.plexClient.getRecentlyAdded(
|
|
||||||
library.id,
|
|
||||||
library.lastScan
|
|
||||||
? {
|
? {
|
||||||
// We remove 10 minutes from the last scan as a buffer
|
// We remove 10 minutes from the last scan as a buffer
|
||||||
addedAt: library.lastScan - 1000 * 60 * 10,
|
addedAt: library.lastScan - 1000 * 60 * 10,
|
||||||
}
|
}
|
||||||
|
: undefined;
|
||||||
|
this.log(
|
||||||
|
`Beginning to process recently added for library: ${library.name}`,
|
||||||
|
'info',
|
||||||
|
{
|
||||||
|
lastScan: library.lastScan,
|
||||||
|
addedAtFilter: addedAtOpt?.addedAt,
|
||||||
|
addedAtFilterDate: addedAtOpt
|
||||||
|
? new Date(addedAtOpt.addedAt).toISOString()
|
||||||
: undefined,
|
: undefined,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const libraryItems = await this.plexClient.getRecentlyAdded(
|
||||||
|
library.id,
|
||||||
|
addedAtOpt ?? {
|
||||||
|
addedAt: Date.now() - 1000 * 60 * 60,
|
||||||
|
},
|
||||||
library.type
|
library.type
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.log(
|
||||||
|
`Recently added fetched ${libraryItems.length} items for library: ${library.name}`,
|
||||||
|
'debug',
|
||||||
|
{
|
||||||
|
libraryId: library.id,
|
||||||
|
itemCount: libraryItems.length,
|
||||||
|
lastScanWillUpdateTo: Date.now(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Bundle items up by rating keys
|
// Bundle items up by rating keys
|
||||||
this.items = uniqWith(libraryItems, (mediaA, mediaB) => {
|
this.items = uniqWith(libraryItems, (mediaA, mediaB) => {
|
||||||
if (mediaA.grandparentRatingKey && mediaB.grandparentRatingKey) {
|
if (mediaA.grandparentRatingKey && mediaB.grandparentRatingKey) {
|
||||||
|
|||||||
Reference in New Issue
Block a user