mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
feat(api): plex Sync (Movies)
Also adds winston logging
This commit is contained in:
@@ -1,8 +1,49 @@
|
||||
import NodePlexAPI from 'plex-api';
|
||||
import { getSettings } from '../lib/settings';
|
||||
|
||||
export interface PlexLibraryItem {
|
||||
ratingKey: string;
|
||||
title: string;
|
||||
guid: string;
|
||||
type: 'movie' | 'show';
|
||||
}
|
||||
|
||||
interface PlexLibraryResponse {
|
||||
MediaContainer: {
|
||||
Metadata: PlexLibraryItem[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface PlexLibrary {
|
||||
type: 'show' | 'movie';
|
||||
key: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
interface PlexLibrariesResponse {
|
||||
MediaContainer: {
|
||||
Directory: PlexLibrary[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface PlexMetadata {
|
||||
ratingKey: string;
|
||||
guid: string;
|
||||
type: 'movie' | 'show';
|
||||
title: string;
|
||||
Guid: {
|
||||
id: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
interface PlexMetadataResponse {
|
||||
MediaContainer: {
|
||||
Metadata: PlexMetadata[];
|
||||
};
|
||||
}
|
||||
|
||||
class PlexAPI {
|
||||
private plexClient: typeof NodePlexAPI;
|
||||
private plexClient: NodePlexAPI;
|
||||
|
||||
constructor({ plexToken }: { plexToken?: string }) {
|
||||
const settings = getSettings();
|
||||
@@ -13,7 +54,7 @@ class PlexAPI {
|
||||
token: plexToken,
|
||||
authenticator: {
|
||||
authenticate: (
|
||||
_plexApi: typeof PlexAPI,
|
||||
_plexApi,
|
||||
cb: (err?: string, token?: string) => void
|
||||
) => {
|
||||
if (!plexToken) {
|
||||
@@ -34,6 +75,36 @@ class PlexAPI {
|
||||
public async getStatus() {
|
||||
return await this.plexClient.query('/');
|
||||
}
|
||||
|
||||
public async getLibraries(): Promise<PlexLibrary[]> {
|
||||
const response = await this.plexClient.query<PlexLibrariesResponse>(
|
||||
'/library/sections'
|
||||
);
|
||||
|
||||
return response.MediaContainer.Directory;
|
||||
}
|
||||
|
||||
public async getLibraryContents(id: string): Promise<PlexLibraryItem[]> {
|
||||
const response = await this.plexClient.query<PlexLibraryResponse>(
|
||||
`/library/sections/${id}/all`
|
||||
);
|
||||
|
||||
return response.MediaContainer.Metadata;
|
||||
}
|
||||
|
||||
public async getMetadata(key: string): Promise<PlexMetadata> {
|
||||
const response = await this.plexClient.query<PlexMetadataResponse>(
|
||||
`/library/metadata/${key}`
|
||||
);
|
||||
|
||||
return response.MediaContainer.Metadata[0];
|
||||
}
|
||||
|
||||
public async getRecentlyAdded() {
|
||||
const response = await this.plexClient.query('/library/recentlyAdded');
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
export default PlexAPI;
|
||||
|
Reference in New Issue
Block a user