mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
@@ -1,7 +1,10 @@
|
|||||||
import { getRepository } from 'typeorm';
|
import { getRepository } from 'typeorm';
|
||||||
import { User } from '../../entity/User';
|
import { User } from '../../entity/User';
|
||||||
import PlexAPI, { PlexLibraryItem } from '../../api/plexapi';
|
import PlexAPI, { PlexLibraryItem } from '../../api/plexapi';
|
||||||
import TheMovieDb, { TmdbTvDetails } from '../../api/themoviedb';
|
import TheMovieDb, {
|
||||||
|
TmdbMovieDetails,
|
||||||
|
TmdbTvDetails,
|
||||||
|
} from '../../api/themoviedb';
|
||||||
import Media from '../../entity/Media';
|
import Media from '../../entity/Media';
|
||||||
import { MediaStatus, MediaType } from '../../constants/media';
|
import { MediaStatus, MediaType } from '../../constants/media';
|
||||||
import logger from '../../logger';
|
import logger from '../../logger';
|
||||||
@@ -93,14 +96,26 @@ class JobPlexSync {
|
|||||||
this.log(`Saved ${plexitem.title}`);
|
this.log(`Saved ${plexitem.title}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const matchedid = plexitem.guid.match(/imdb:\/\/(tt[0-9]+)/);
|
let tmdbMovieId: number | undefined;
|
||||||
|
let tmdbMovie: TmdbMovieDetails | undefined;
|
||||||
|
|
||||||
if (matchedid?.[1]) {
|
const imdbMatch = plexitem.guid.match(imdbRegex);
|
||||||
const tmdbMovie = await this.tmdb.getMovieByImdbId({
|
const tmdbMatch = plexitem.guid.match(tmdbRegex);
|
||||||
imdbId: matchedid[1],
|
|
||||||
|
if (imdbMatch) {
|
||||||
|
tmdbMovie = await this.tmdb.getMovieByImdbId({
|
||||||
|
imdbId: imdbMatch[1],
|
||||||
});
|
});
|
||||||
|
tmdbMovieId = tmdbMovie.id;
|
||||||
|
} else if (tmdbMatch) {
|
||||||
|
tmdbMovieId = Number(tmdbMatch[1]);
|
||||||
|
}
|
||||||
|
|
||||||
const existing = await this.getExisting(tmdbMovie.id);
|
if (!tmdbMovieId) {
|
||||||
|
throw new Error('Unable to find TMDB ID');
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await this.getExisting(tmdbMovieId);
|
||||||
if (existing && existing.status === MediaStatus.AVAILABLE) {
|
if (existing && existing.status === MediaStatus.AVAILABLE) {
|
||||||
this.log(`Title exists and is already available ${plexitem.title}`);
|
this.log(`Title exists and is already available ${plexitem.title}`);
|
||||||
} else if (existing && existing.status !== MediaStatus.AVAILABLE) {
|
} else if (existing && existing.status !== MediaStatus.AVAILABLE) {
|
||||||
@@ -110,7 +125,12 @@ class JobPlexSync {
|
|||||||
`Request for ${plexitem.title} exists. Setting status AVAILABLE`,
|
`Request for ${plexitem.title} exists. Setting status AVAILABLE`,
|
||||||
'info'
|
'info'
|
||||||
);
|
);
|
||||||
} else if (tmdbMovie) {
|
} else {
|
||||||
|
// If we have a tmdb movie guid but it didn't already exist, only then
|
||||||
|
// do we request the movie from tmdb (to reduce api requests)
|
||||||
|
if (!tmdbMovie) {
|
||||||
|
tmdbMovie = await this.tmdb.getMovie({ movieId: tmdbMovieId });
|
||||||
|
}
|
||||||
const newMedia = new Media();
|
const newMedia = new Media();
|
||||||
newMedia.imdbId = tmdbMovie.external_ids.imdb_id;
|
newMedia.imdbId = tmdbMovie.external_ids.imdb_id;
|
||||||
newMedia.tmdbId = tmdbMovie.id;
|
newMedia.tmdbId = tmdbMovie.id;
|
||||||
@@ -120,13 +140,14 @@ class JobPlexSync {
|
|||||||
this.log(`Saved ${tmdbMovie.title}`);
|
this.log(`Saved ${tmdbMovie.title}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.log(
|
this.log(
|
||||||
`Failed to process plex item. ratingKey: ${
|
`Failed to process plex item. ratingKey: ${plexitem.ratingKey}`,
|
||||||
plexitem.parentRatingKey ?? plexitem.ratingKey
|
'error',
|
||||||
}`,
|
{
|
||||||
'error'
|
errorMessage: e.message,
|
||||||
|
plexitem,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user