mirror of
https://github.com/sct/overseerr.git
synced 2025-10-02 00:33:09 +02:00
fix(plex sync): catch errors that occur during processMovie
this also removes the unique constraint on imdbId re #244 #246 #250
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
"start": "NODE_ENV=production node dist/index.js",
|
"start": "NODE_ENV=production node dist/index.js",
|
||||||
"i18n:extract": "extract-messages -l=en -o src/i18n/locale -d en --flat true --overwriteDefault false './src/**/!(*.test).{ts,tsx}'",
|
"i18n:extract": "extract-messages -l=en -o src/i18n/locale -d en --flat true --overwriteDefault false './src/**/!(*.test).{ts,tsx}'",
|
||||||
"migration:generate": "ts-node --project server/tsconfig.json ./node_modules/.bin/typeorm migration:generate",
|
"migration:generate": "ts-node --project server/tsconfig.json ./node_modules/.bin/typeorm migration:generate",
|
||||||
|
"migration:create": "ts-node --project server/tsconfig.json ./node_modules/.bin/typeorm migration:create",
|
||||||
"migration:run": "ts-node --project server/tsconfig.json ./node_modules/.bin/typeorm migration:run",
|
"migration:run": "ts-node --project server/tsconfig.json ./node_modules/.bin/typeorm migration:run",
|
||||||
"format": "prettier --write ."
|
"format": "prettier --write ."
|
||||||
},
|
},
|
||||||
|
@@ -51,64 +51,81 @@ class JobPlexSync {
|
|||||||
|
|
||||||
private async processMovie(plexitem: PlexLibraryItem) {
|
private async processMovie(plexitem: PlexLibraryItem) {
|
||||||
const mediaRepository = getRepository(Media);
|
const mediaRepository = getRepository(Media);
|
||||||
if (plexitem.guid.match(plexRegex)) {
|
try {
|
||||||
const metadata = await this.plexClient.getMetadata(plexitem.ratingKey);
|
if (plexitem.guid.match(plexRegex)) {
|
||||||
const newMedia = new Media();
|
const metadata = await this.plexClient.getMetadata(plexitem.ratingKey);
|
||||||
|
const newMedia = new Media();
|
||||||
|
|
||||||
metadata.Guid.forEach((ref) => {
|
if (!metadata.Guid) {
|
||||||
if (ref.id.match(imdbRegex)) {
|
logger.debug('No Guid metadata for this title. Skipping', {
|
||||||
newMedia.imdbId = ref.id.match(imdbRegex)?.[1] ?? undefined;
|
label: 'Plex Sync',
|
||||||
} else if (ref.id.match(tmdbRegex)) {
|
ratingKey: plexitem.ratingKey,
|
||||||
const tmdbMatch = ref.id.match(tmdbRegex)?.[1];
|
});
|
||||||
newMedia.tmdbId = Number(tmdbMatch);
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
const existing = await this.getExisting(newMedia.tmdbId);
|
metadata.Guid.forEach((ref) => {
|
||||||
|
if (ref.id.match(imdbRegex)) {
|
||||||
if (existing && existing.status === MediaStatus.AVAILABLE) {
|
newMedia.imdbId = ref.id.match(imdbRegex)?.[1] ?? undefined;
|
||||||
this.log(`Title exists and is already available ${metadata.title}`);
|
} else if (ref.id.match(tmdbRegex)) {
|
||||||
} else if (existing && existing.status !== MediaStatus.AVAILABLE) {
|
const tmdbMatch = ref.id.match(tmdbRegex)?.[1];
|
||||||
existing.status = MediaStatus.AVAILABLE;
|
newMedia.tmdbId = Number(tmdbMatch);
|
||||||
mediaRepository.save(existing);
|
}
|
||||||
this.log(
|
|
||||||
`Request for ${metadata.title} exists. Setting status AVAILABLE`,
|
|
||||||
'info'
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
newMedia.status = MediaStatus.AVAILABLE;
|
|
||||||
newMedia.mediaType = MediaType.MOVIE;
|
|
||||||
await mediaRepository.save(newMedia);
|
|
||||||
this.log(`Saved ${plexitem.title}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const matchedid = plexitem.guid.match(/imdb:\/\/(tt[0-9]+)/);
|
|
||||||
|
|
||||||
if (matchedid?.[1]) {
|
|
||||||
const tmdbMovie = await this.tmdb.getMovieByImdbId({
|
|
||||||
imdbId: matchedid[1],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const existing = await this.getExisting(tmdbMovie.id);
|
const existing = await this.getExisting(newMedia.tmdbId);
|
||||||
|
|
||||||
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 ${metadata.title}`);
|
||||||
} else if (existing && existing.status !== MediaStatus.AVAILABLE) {
|
} else if (existing && existing.status !== MediaStatus.AVAILABLE) {
|
||||||
existing.status = MediaStatus.AVAILABLE;
|
existing.status = MediaStatus.AVAILABLE;
|
||||||
await mediaRepository.save(existing);
|
mediaRepository.save(existing);
|
||||||
this.log(
|
this.log(
|
||||||
`Request for ${plexitem.title} exists. Setting status AVAILABLE`,
|
`Request for ${metadata.title} exists. Setting status AVAILABLE`,
|
||||||
'info'
|
'info'
|
||||||
);
|
);
|
||||||
} else if (tmdbMovie) {
|
} else {
|
||||||
const newMedia = new Media();
|
|
||||||
newMedia.imdbId = tmdbMovie.external_ids.imdb_id;
|
|
||||||
newMedia.tmdbId = tmdbMovie.id;
|
|
||||||
newMedia.status = MediaStatus.AVAILABLE;
|
newMedia.status = MediaStatus.AVAILABLE;
|
||||||
newMedia.mediaType = MediaType.MOVIE;
|
newMedia.mediaType = MediaType.MOVIE;
|
||||||
await mediaRepository.save(newMedia);
|
await mediaRepository.save(newMedia);
|
||||||
this.log(`Saved ${tmdbMovie.title}`);
|
this.log(`Saved ${plexitem.title}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const matchedid = plexitem.guid.match(/imdb:\/\/(tt[0-9]+)/);
|
||||||
|
|
||||||
|
if (matchedid?.[1]) {
|
||||||
|
const tmdbMovie = await this.tmdb.getMovieByImdbId({
|
||||||
|
imdbId: matchedid[1],
|
||||||
|
});
|
||||||
|
|
||||||
|
const existing = await this.getExisting(tmdbMovie.id);
|
||||||
|
if (existing && existing.status === MediaStatus.AVAILABLE) {
|
||||||
|
this.log(`Title exists and is already available ${plexitem.title}`);
|
||||||
|
} else if (existing && existing.status !== MediaStatus.AVAILABLE) {
|
||||||
|
existing.status = MediaStatus.AVAILABLE;
|
||||||
|
await mediaRepository.save(existing);
|
||||||
|
this.log(
|
||||||
|
`Request for ${plexitem.title} exists. Setting status AVAILABLE`,
|
||||||
|
'info'
|
||||||
|
);
|
||||||
|
} else if (tmdbMovie) {
|
||||||
|
const newMedia = new Media();
|
||||||
|
newMedia.imdbId = tmdbMovie.external_ids.imdb_id;
|
||||||
|
newMedia.tmdbId = tmdbMovie.id;
|
||||||
|
newMedia.status = MediaStatus.AVAILABLE;
|
||||||
|
newMedia.mediaType = MediaType.MOVIE;
|
||||||
|
await mediaRepository.save(newMedia);
|
||||||
|
this.log(`Saved ${tmdbMovie.title}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.log(
|
||||||
|
`Failed to process plex item. ratingKey: ${
|
||||||
|
plexitem.parentRatingKey ?? plexitem.ratingKey
|
||||||
|
}`,
|
||||||
|
'error'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
server/migration/1607928251245-DropImdbIdConstraint.ts
Normal file
20
server/migration/1607928251245-DropImdbIdConstraint.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { MigrationInterface, QueryRunner, TableUnique } from 'typeorm';
|
||||||
|
|
||||||
|
export class DropImdbIdConstraint1607928251245 implements MigrationInterface {
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.dropUniqueConstraint(
|
||||||
|
'media',
|
||||||
|
'UQ_7ff2d11f6a83cb52386eaebe74b'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.createUniqueConstraint(
|
||||||
|
'media',
|
||||||
|
new TableUnique({
|
||||||
|
name: 'UQ_7ff2d11f6a83cb52386eaebe74b',
|
||||||
|
columnNames: ['imdbId'],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user