From c1a47bd9de332cb4925974690f5a33448b5cc2e6 Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Mon, 12 Jun 2023 04:35:01 -0400 Subject: [PATCH 01/14] fix(ui): corrected issues icon color (#3498) --- src/components/Layout/Sidebar/index.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/Layout/Sidebar/index.tsx b/src/components/Layout/Sidebar/index.tsx index d9f8ffd51..81ebb86c7 100644 --- a/src/components/Layout/Sidebar/index.tsx +++ b/src/components/Layout/Sidebar/index.tsx @@ -71,9 +71,7 @@ const SidebarLinks: SidebarLinkProps[] = [ { href: '/issues', messagesKey: 'issues', - svgIcon: ( - - ), + svgIcon: , activeRegExp: /^\/issues/, requiredPermission: [ Permission.MANAGE_ISSUES, From 2c3f5330764492e1323afd2d1f25e28ad78a2f2f Mon Sep 17 00:00:00 2001 From: Ryan Cohen Date: Tue, 13 Jun 2023 23:15:54 +0900 Subject: [PATCH 02/14] fix: adjust the plex watchlist sync schedule to have fuzziness (#3502) also fixes the schedule making it uneditable --- server/job/schedule.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/server/job/schedule.ts b/server/job/schedule.ts index 998abf1f4..932d6107f 100644 --- a/server/job/schedule.ts +++ b/server/job/schedule.ts @@ -8,6 +8,7 @@ import type { JobId } from '@server/lib/settings'; import { getSettings } from '@server/lib/settings'; import watchlistSync from '@server/lib/watchlistsync'; import logger from '@server/logger'; +import random from 'lodash/random'; import schedule from 'node-schedule'; interface ScheduledJob { @@ -60,21 +61,31 @@ export const startJobs = (): void => { cancelFn: () => plexFullScanner.cancel(), }); - // Run watchlist sync every 5 minutes - scheduledJobs.push({ + // Watchlist Sync + const watchlistSyncJob: ScheduledJob = { id: 'plex-watchlist-sync', name: 'Plex Watchlist Sync', type: 'process', - interval: 'minutes', + interval: 'fixed', cronSchedule: jobs['plex-watchlist-sync'].schedule, - job: schedule.scheduleJob(jobs['plex-watchlist-sync'].schedule, () => { + job: schedule.scheduleJob(new Date(Date.now() + 1000 * 60 * 20), () => { logger.info('Starting scheduled job: Plex Watchlist Sync', { label: 'Jobs', }); watchlistSync.syncWatchlist(); }), + }; + + // To help alleviate load on Plex's servers, we will add some fuzziness to the next schedule + // after each run + watchlistSyncJob.job.on('run', () => { + watchlistSyncJob.job.schedule( + new Date(Math.floor(Date.now() + 1000 * 60 * random(14, 24, true))) + ); }); + scheduledJobs.push(watchlistSyncJob); + // Run full radarr scan every 24 hours scheduledJobs.push({ id: 'radarr-scan', From d0836ce0efd55fccf2546087a0c4f94f7cb2e82a Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Wed, 14 Jun 2023 01:43:08 -0400 Subject: [PATCH 03/14] fix: improved handling of edge case that could cause availability sync to fail (#3497) --- server/lib/availabilitySync.ts | 319 ++++++++++++++++++--------------- 1 file changed, 173 insertions(+), 146 deletions(-) diff --git a/server/lib/availabilitySync.ts b/server/lib/availabilitySync.ts index a9f61fff6..231dd9a20 100644 --- a/server/lib/availabilitySync.ts +++ b/server/lib/availabilitySync.ts @@ -30,23 +30,24 @@ class AvailabilitySync { this.sonarrSeasonsCache = {}; this.radarrServers = settings.radarr.filter((server) => server.syncEnabled); this.sonarrServers = settings.sonarr.filter((server) => server.syncEnabled); - await this.initPlexClient(); - - if (!this.plexClient) { - return; - } - - logger.info(`Starting availability sync...`, { - label: 'AvailabilitySync', - }); - const mediaRepository = getRepository(Media); - const requestRepository = getRepository(MediaRequest); - const seasonRepository = getRepository(Season); - const seasonRequestRepository = getRepository(SeasonRequest); - - const pageSize = 50; try { + await this.initPlexClient(); + + if (!this.plexClient) { + return; + } + + logger.info(`Starting availability sync...`, { + label: 'AvailabilitySync', + }); + const mediaRepository = getRepository(Media); + const requestRepository = getRepository(MediaRequest); + const seasonRepository = getRepository(Season); + const seasonRequestRepository = getRepository(SeasonRequest); + + const pageSize = 50; + for await (const media of this.loadAvailableMediaPaginated(pageSize)) { if (!this.running) { throw new Error('Job aborted'); @@ -239,51 +240,60 @@ class AvailabilitySync { const isTVType = media.mediaType === 'tv'; - const request = await requestRepository.findOne({ - relations: { - media: true, - }, - where: { media: { id: media.id }, is4k: is4k ? true : false }, - }); + try { + const request = await requestRepository.findOne({ + relations: { + media: true, + }, + where: { media: { id: media.id }, is4k: is4k ? true : false }, + }); - logger.info( - `Media ID ${media.id} does not exist in your ${is4k ? '4k' : 'non-4k'} ${ - isTVType ? 'Sonarr' : 'Radarr' - } and Plex instance. Status will be changed to unknown.`, - { label: 'AvailabilitySync' } - ); - - await mediaRepository.update( - media.id, - is4k - ? { - status4k: MediaStatus.UNKNOWN, - serviceId4k: null, - externalServiceId4k: null, - externalServiceSlug4k: null, - ratingKey4k: null, - } - : { - status: MediaStatus.UNKNOWN, - serviceId: null, - externalServiceId: null, - externalServiceSlug: null, - ratingKey: null, - } - ); - - if (isTVType) { - const seasonRepository = getRepository(Season); - - await seasonRepository?.update( - { media: { id: media.id } }, - is4k - ? { status4k: MediaStatus.UNKNOWN } - : { status: MediaStatus.UNKNOWN } + logger.info( + `Media ID ${media.id} does not exist in your ${ + is4k ? '4k' : 'non-4k' + } ${ + isTVType ? 'Sonarr' : 'Radarr' + } and Plex instance. Status will be changed to unknown.`, + { label: 'AvailabilitySync' } ); - } - await requestRepository.delete({ id: request?.id }); + await mediaRepository.update( + media.id, + is4k + ? { + status4k: MediaStatus.UNKNOWN, + serviceId4k: null, + externalServiceId4k: null, + externalServiceSlug4k: null, + ratingKey4k: null, + } + : { + status: MediaStatus.UNKNOWN, + serviceId: null, + externalServiceId: null, + externalServiceSlug: null, + ratingKey: null, + } + ); + + if (isTVType) { + const seasonRepository = getRepository(Season); + + await seasonRepository?.update( + { media: { id: media.id } }, + is4k + ? { status4k: MediaStatus.UNKNOWN } + : { status: MediaStatus.UNKNOWN } + ); + } + + await requestRepository.delete({ id: request?.id }); + } catch (ex) { + logger.debug(`Failure updating media ID ${media.id}`, { + errorMessage: ex.message, + label: 'AvailabilitySync', + }); + } } private async mediaExistsInRadarr( @@ -539,83 +549,90 @@ class AvailabilitySync { } } - const seasonToBeDeleted = await seasonRequestRepository.findOne({ - relations: { - request: { - media: true, - }, - }, - where: { - request: { - is4k: seasonExistsInSonarr ? true : false, - media: { - id: media.id, + try { + const seasonToBeDeleted = await seasonRequestRepository.findOne({ + relations: { + request: { + media: true, }, }, - seasonNumber: season.seasonNumber, - }, - }); + where: { + request: { + is4k: seasonExistsInSonarr ? true : false, + media: { + id: media.id, + }, + }, + seasonNumber: season.seasonNumber, + }, + }); - // If season does not exist, we will change status to unknown and delete related season request - // If parent media request is empty(all related seasons have been removed), parent is automatically deleted - if ( - !seasonExistsInSonarr && - (seasonExistsInSonarr4k || seasonExistsInPlex4k) && - !seasonExistsInPlex - ) { - if (season.status !== MediaStatus.UNKNOWN) { - logger.info( - `Season ${season.seasonNumber}, media ID ${media.id} does not exist in your non-4k Sonarr and Plex instance. Status will be changed to unknown.`, - { label: 'AvailabilitySync' } - ); - await seasonRepository.update(season.id, { - status: MediaStatus.UNKNOWN, - }); - - if (seasonToBeDeleted) { - await seasonRequestRepository.remove(seasonToBeDeleted); - } - - if (media.status === MediaStatus.AVAILABLE) { + // If season does not exist, we will change status to unknown and delete related season request + // If parent media request is empty(all related seasons have been removed), parent is automatically deleted + if ( + !seasonExistsInSonarr && + (seasonExistsInSonarr4k || seasonExistsInPlex4k) && + !seasonExistsInPlex + ) { + if (season.status !== MediaStatus.UNKNOWN) { logger.info( - `Marking media ID ${media.id} as PARTIALLY_AVAILABLE because season removal has occurred.`, + `Season ${season.seasonNumber}, media ID ${media.id} does not exist in your non-4k Sonarr and Plex instance. Status will be changed to unknown.`, { label: 'AvailabilitySync' } ); - await mediaRepository.update(media.id, { - status: MediaStatus.PARTIALLY_AVAILABLE, + await seasonRepository.update(season.id, { + status: MediaStatus.UNKNOWN, }); + + if (seasonToBeDeleted) { + await seasonRequestRepository.remove(seasonToBeDeleted); + } + + if (media.status === MediaStatus.AVAILABLE) { + logger.info( + `Marking media ID ${media.id} as PARTIALLY_AVAILABLE because season removal has occurred.`, + { label: 'AvailabilitySync' } + ); + await mediaRepository.update(media.id, { + status: MediaStatus.PARTIALLY_AVAILABLE, + }); + } } } - } - if ( - (seasonExistsInSonarr || seasonExistsInPlex) && - !seasonExistsInSonarr4k && - !seasonExistsInPlex4k - ) { - if (season.status4k !== MediaStatus.UNKNOWN) { - logger.info( - `Season ${season.seasonNumber}, media ID ${media.id} does not exist in your 4k Sonarr and Plex instance. Status will be changed to unknown.`, - { label: 'AvailabilitySync' } - ); - await seasonRepository.update(season.id, { - status4k: MediaStatus.UNKNOWN, - }); - - if (seasonToBeDeleted) { - await seasonRequestRepository.remove(seasonToBeDeleted); - } - - if (media.status4k === MediaStatus.AVAILABLE) { + if ( + (seasonExistsInSonarr || seasonExistsInPlex) && + !seasonExistsInSonarr4k && + !seasonExistsInPlex4k + ) { + if (season.status4k !== MediaStatus.UNKNOWN) { logger.info( - `Marking media ID ${media.id} as PARTIALLY_AVAILABLE because season removal has occurred.`, + `Season ${season.seasonNumber}, media ID ${media.id} does not exist in your 4k Sonarr and Plex instance. Status will be changed to unknown.`, { label: 'AvailabilitySync' } ); - await mediaRepository.update(media.id, { - status4k: MediaStatus.PARTIALLY_AVAILABLE, + await seasonRepository.update(season.id, { + status4k: MediaStatus.UNKNOWN, }); + + if (seasonToBeDeleted) { + await seasonRequestRepository.remove(seasonToBeDeleted); + } + + if (media.status4k === MediaStatus.AVAILABLE) { + logger.info( + `Marking media ID ${media.id} as PARTIALLY_AVAILABLE because season removal has occurred.`, + { label: 'AvailabilitySync' } + ); + await mediaRepository.update(media.id, { + status4k: MediaStatus.PARTIALLY_AVAILABLE, + }); + } } } + } catch (ex) { + logger.debug(`Failure updating media ID ${media.id}`, { + errorMessage: ex.message, + label: 'AvailabilitySync', + }); } if ( @@ -654,7 +671,10 @@ class AvailabilitySync { } } catch (ex) { if (!ex.message.includes('response code: 404')) { - throw ex; + logger.debug(`Failed to retrieve plex metadata`, { + errorMessage: ex.message, + label: 'AvailabilitySync', + }); } } // Base case if both media versions exist in plex @@ -714,36 +734,43 @@ class AvailabilitySync { let seasonExistsInPlex = false; let seasonExistsInPlex4k = false; - if (ratingKey) { - const children = - this.plexSeasonsCache[ratingKey] ?? - (await this.plexClient?.getChildrenMetadata(ratingKey)) ?? - []; - this.plexSeasonsCache[ratingKey] = children; - const seasonMeta = children?.find( - (child) => child.index === season.seasonNumber - ); + try { + if (ratingKey) { + const children = + this.plexSeasonsCache[ratingKey] ?? + (await this.plexClient?.getChildrenMetadata(ratingKey)) ?? + []; + this.plexSeasonsCache[ratingKey] = children; + const seasonMeta = children?.find( + (child) => child.index === season.seasonNumber + ); - if (seasonMeta) { - seasonExistsInPlex = true; + if (seasonMeta) { + seasonExistsInPlex = true; + } + } + if (ratingKey4k) { + const children4k = + this.plexSeasonsCache[ratingKey4k] ?? + (await this.plexClient?.getChildrenMetadata(ratingKey4k)) ?? + []; + this.plexSeasonsCache[ratingKey4k] = children4k; + const seasonMeta4k = children4k?.find( + (child) => child.index === season.seasonNumber + ); + + if (seasonMeta4k) { + seasonExistsInPlex4k = true; + } + } + } catch (ex) { + if (!ex.message.includes('response code: 404')) { + logger.debug(`Failed to retrieve plex's children metadata`, { + errorMessage: ex.message, + label: 'AvailabilitySync', + }); } } - - if (ratingKey4k) { - const children4k = - this.plexSeasonsCache[ratingKey4k] ?? - (await this.plexClient?.getChildrenMetadata(ratingKey4k)) ?? - []; - this.plexSeasonsCache[ratingKey4k] = children4k; - const seasonMeta4k = children4k?.find( - (child) => child.index === season.seasonNumber - ); - - if (seasonMeta4k) { - seasonExistsInPlex4k = true; - } - } - // Base case if both season versions exist in plex if (seasonExistsInPlex && seasonExistsInPlex4k) { return true; From a761b7dd35a5bd61bb4eb0275b75d1e0977e6a2d Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Wed, 21 Jun 2023 13:18:50 -0400 Subject: [PATCH 04/14] fix: resolved issue with create slider causing incorrect form submission (#3514) --- src/components/Selector/index.tsx | 1 + src/components/Slider/index.tsx | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/components/Selector/index.tsx b/src/components/Selector/index.tsx index 78ae33ea1..7b2165872 100644 --- a/src/components/Selector/index.tsx +++ b/src/components/Selector/index.tsx @@ -437,6 +437,7 @@ export const WatchProviderSelector = ({ {otherProviders.length > 0 && ( @@ -165,6 +166,7 @@ const Slider = ({ }`} onClick={() => slide(Direction.RIGHT)} disabled={scrollPos.isEnd} + type="button" > From 01de972a8fe2ea3c18d5b2f426d01b5b14d142d4 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Thu, 29 Jun 2023 09:34:10 -0700 Subject: [PATCH 05/14] fix(statusbadge): handle missing season/episode number (#3526) --- src/components/StatusBadge/index.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/StatusBadge/index.tsx b/src/components/StatusBadge/index.tsx index 3dbe6e74b..b60b7af04 100644 --- a/src/components/StatusBadge/index.tsx +++ b/src/components/StatusBadge/index.tsx @@ -166,11 +166,11 @@ const StatusBadge = ({ {inProgress && ( <> - {mediaType === 'tv' && ( + {mediaType === 'tv' && downloadItem[0].episode && ( {intl.formatMessage(messages.seasonepisodenumber, { - seasonNumber: downloadItem[0].episode?.seasonNumber, - episodeNumber: downloadItem[0].episode?.episodeNumber, + seasonNumber: downloadItem[0].episode.seasonNumber, + episodeNumber: downloadItem[0].episode.episodeNumber, })} )} @@ -219,11 +219,11 @@ const StatusBadge = ({ {inProgress && ( <> - {mediaType === 'tv' && ( + {mediaType === 'tv' && downloadItem[0].episode && ( {intl.formatMessage(messages.seasonepisodenumber, { - seasonNumber: downloadItem[0].episode?.seasonNumber, - episodeNumber: downloadItem[0].episode?.episodeNumber, + seasonNumber: downloadItem[0].episode.seasonNumber, + episodeNumber: downloadItem[0].episode.episodeNumber, })} )} @@ -272,11 +272,11 @@ const StatusBadge = ({ {inProgress && ( <> - {mediaType === 'tv' && ( + {mediaType === 'tv' && downloadItem[0].episode && ( {intl.formatMessage(messages.seasonepisodenumber, { - seasonNumber: downloadItem[0].episode?.seasonNumber, - episodeNumber: downloadItem[0].episode?.episodeNumber, + seasonNumber: downloadItem[0].episode.seasonNumber, + episodeNumber: downloadItem[0].episode.episodeNumber, })} )} From 2816c66300bf870d493c0665b0e984d60f707dfd Mon Sep 17 00:00:00 2001 From: "Anton K. (ai Doge)" Date: Tue, 18 Jul 2023 01:03:52 -0400 Subject: [PATCH 06/14] fix: resolved user access check issue (#3551) * fix: importing friends update checkUserAccess to use getUsers * refactor(server/api/plextv.ts): clean up removed unused getFriends function, and its interface. renamed friends variable. --- server/api/plextv.ts | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/server/api/plextv.ts b/server/api/plextv.ts index 76ee66188..704926895 100644 --- a/server/api/plextv.ts +++ b/server/api/plextv.ts @@ -82,21 +82,6 @@ interface ServerResponse { }; } -interface FriendResponse { - MediaContainer: { - User: { - $: { - id: string; - title: string; - username: string; - email: string; - thumb: string; - }; - Server?: ServerResponse[]; - }[]; - }; -} - interface UsersResponse { MediaContainer: { User: { @@ -234,19 +219,6 @@ class PlexTvAPI extends ExternalAPI { } } - public async getFriends(): Promise { - const response = await this.axios.get('/pms/friends/all', { - transformResponse: [], - responseType: 'text', - }); - - const parsedXml = (await xml2js.parseStringPromise( - response.data - )) as FriendResponse; - - return parsedXml; - } - public async checkUserAccess(userId: number): Promise { const settings = getSettings(); @@ -255,9 +227,9 @@ class PlexTvAPI extends ExternalAPI { throw new Error('Plex is not configured!'); } - const friends = await this.getFriends(); + const usersResponse = await this.getUsers(); - const users = friends.MediaContainer.User; + const users = usersResponse.MediaContainer.User; const user = users.find((u) => parseInt(u.$.id) === userId); From 68c7b3650ec82437bdb128f72f734e227ad763cb Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 18 Jul 2023 05:17:07 +0000 Subject: [PATCH 07/14] docs: add scorp200 as a contributor for code (#3555) [skip ci] * docs: update README.md * docs: update .all-contributorsrc --------- Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 371872759..f29044994 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -872,6 +872,15 @@ "contributions": [ "code" ] + }, + { + "login": "scorp200", + "name": "Anton K. (ai Doge)", + "avatar_url": "https://avatars.githubusercontent.com/u/9427639?v=4", + "profile": "http://aidoge.xyz", + "contributions": [ + "code" + ] } ], "badgeTemplate": "\"All-orange.svg\"/>", diff --git a/README.md b/README.md index 6fe73c27d..0f6e32413 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Translation status GitHub -All Contributors +All Contributors

@@ -196,6 +196,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Salman Tariq
Salman Tariq

💻 Andrew Kennedy
Andrew Kennedy

💻 Fallenbagel
Fallenbagel

💻 + Anton K. (ai Doge)
Anton K. (ai Doge)

💻 From 83b008c8391459bd02dc74bcdb0d8caf27207bdf Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Mon, 24 Jul 2023 02:33:12 -0400 Subject: [PATCH 08/14] fix: handle issue causing incorrect media to change to unknown (#3516) * fix: handle issue causing incorrect media to change back to unknown * fix: prevent start if plex client is unavailable * fix: initialize radarr and sonarr clients before the scan starts * fix: compensate for multiple *arr servers * fix: added a more reliable season lookup * refactor: modified tuples to increase code readability --- server/lib/availabilitySync.ts | 1120 +++++++++++++++----------------- 1 file changed, 514 insertions(+), 606 deletions(-) diff --git a/server/lib/availabilitySync.ts b/server/lib/availabilitySync.ts index 231dd9a20..0a16302cc 100644 --- a/server/lib/availabilitySync.ts +++ b/server/lib/availabilitySync.ts @@ -1,14 +1,13 @@ import type { PlexMetadata } from '@server/api/plexapi'; import PlexAPI from '@server/api/plexapi'; -import type { RadarrMovie } from '@server/api/servarr/radarr'; -import RadarrAPI from '@server/api/servarr/radarr'; +import RadarrAPI, { type RadarrMovie } from '@server/api/servarr/radarr'; import type { SonarrSeason, SonarrSeries } from '@server/api/servarr/sonarr'; import SonarrAPI from '@server/api/servarr/sonarr'; -import { MediaStatus } from '@server/constants/media'; +import { MediaRequestStatus, MediaStatus } from '@server/constants/media'; import { getRepository } from '@server/datasource'; import Media from '@server/entity/Media'; import MediaRequest from '@server/entity/MediaRequest'; -import Season from '@server/entity/Season'; +import type Season from '@server/entity/Season'; import SeasonRequest from '@server/entity/SeasonRequest'; import { User } from '@server/entity/User'; import type { RadarrSettings, SonarrSettings } from '@server/lib/settings'; @@ -18,8 +17,8 @@ import logger from '@server/logger'; class AvailabilitySync { public running = false; private plexClient: PlexAPI; - private plexSeasonsCache: Record = {}; - private sonarrSeasonsCache: Record = {}; + private plexSeasonsCache: Record; + private sonarrSeasonsCache: Record; private radarrServers: RadarrSettings[]; private sonarrServers: SonarrSettings[]; @@ -32,166 +31,176 @@ class AvailabilitySync { this.sonarrServers = settings.sonarr.filter((server) => server.syncEnabled); try { - await this.initPlexClient(); - - if (!this.plexClient) { - return; - } - logger.info(`Starting availability sync...`, { label: 'AvailabilitySync', }); - const mediaRepository = getRepository(Media); - const requestRepository = getRepository(MediaRequest); - const seasonRepository = getRepository(Season); - const seasonRequestRepository = getRepository(SeasonRequest); - const pageSize = 50; + const userRepository = getRepository(User); + const admin = await userRepository.findOne({ + select: { id: true, plexToken: true }, + where: { id: 1 }, + }); + + if (admin) { + this.plexClient = new PlexAPI({ plexToken: admin.plexToken }); + } else { + logger.error('An admin is not configured.'); + } + for await (const media of this.loadAvailableMediaPaginated(pageSize)) { if (!this.running) { throw new Error('Job aborted'); } - const mediaExists = await this.mediaExists(media); + // Check plex, radarr, and sonarr for that specific media and + // if unavailable, then we change the status accordingly. + // If a non-4k or 4k version exists in at least one of the instances, we will only update that specific version + if (media.mediaType === 'movie') { + let movieExists = false; + let movieExists4k = false; - // We can not delete media so if both versions do not exist, we will change both columns to unknown or null - if (!mediaExists) { - if ( - media.status !== MediaStatus.UNKNOWN || - media.status4k !== MediaStatus.UNKNOWN - ) { - const request = await requestRepository.find({ - relations: { - media: true, - }, - where: { media: { id: media.id } }, - }); + const { existsInPlex } = await this.mediaExistsInPlex(media, false); + const { existsInPlex: existsInPlex4k } = await this.mediaExistsInPlex( + media, + true + ); + const existsInRadarr = await this.mediaExistsInRadarr(media, false); + const existsInRadarr4k = await this.mediaExistsInRadarr(media, true); + + if (existsInPlex || existsInRadarr) { + movieExists = true; logger.info( - `Media ID ${media.id} does not exist in any of your media instances. Status will be changed to unknown.`, - { label: 'AvailabilitySync' } + `The non-4K movie [TMDB ID ${media.tmdbId}] still exists. Preventing removal.`, + { + label: 'AvailabilitySync', + } ); + } - await mediaRepository.update(media.id, { - status: MediaStatus.UNKNOWN, - status4k: MediaStatus.UNKNOWN, - serviceId: null, - serviceId4k: null, - externalServiceId: null, - externalServiceId4k: null, - externalServiceSlug: null, - externalServiceSlug4k: null, - ratingKey: null, - ratingKey4k: null, - }); + if (existsInPlex4k || existsInRadarr4k) { + movieExists4k = true; + logger.info( + `The 4K movie [TMDB ID ${media.tmdbId}] still exists. Preventing removal.`, + { + label: 'AvailabilitySync', + } + ); + } - await requestRepository.remove(request); + if (!movieExists && media.status === MediaStatus.AVAILABLE) { + await this.mediaUpdater(media, false); + } + + if (!movieExists4k && media.status4k === MediaStatus.AVAILABLE) { + await this.mediaUpdater(media, true); } } + // If both versions still exist in plex, we still need + // to check through sonarr to verify season availability if (media.mediaType === 'tv') { - // ok, the show itself exists, but do all it's seasons? - const seasons = await seasonRepository.find({ - where: [ - { status: MediaStatus.AVAILABLE, media: { id: media.id } }, + let showExists = false; + let showExists4k = false; + + const { existsInPlex, seasonsMap: plexSeasonsMap = new Map() } = + await this.mediaExistsInPlex(media, false); + const { + existsInPlex: existsInPlex4k, + seasonsMap: plexSeasonsMap4k = new Map(), + } = await this.mediaExistsInPlex(media, true); + + const { existsInSonarr, seasonsMap: sonarrSeasonsMap } = + await this.mediaExistsInSonarr(media, false); + const { + existsInSonarr: existsInSonarr4k, + seasonsMap: sonarrSeasonsMap4k, + } = await this.mediaExistsInSonarr(media, true); + + if (existsInPlex || existsInSonarr) { + showExists = true; + logger.info( + `The non-4K show [TMDB ID ${media.tmdbId}] still exists. Preventing removal.`, { - status: MediaStatus.PARTIALLY_AVAILABLE, - media: { id: media.id }, - }, - { status4k: MediaStatus.AVAILABLE, media: { id: media.id } }, + label: 'AvailabilitySync', + } + ); + } + + if (existsInPlex4k || existsInSonarr4k) { + showExists4k = true; + logger.info( + `The 4K show [TMDB ID ${media.tmdbId}] still exists. Preventing removal.`, { - status4k: MediaStatus.PARTIALLY_AVAILABLE, - media: { id: media.id }, - }, - ], - }); - - let didDeleteSeasons = false; - for (const season of seasons) { - if ( - !mediaExists && - (season.status !== MediaStatus.UNKNOWN || - season.status4k !== MediaStatus.UNKNOWN) - ) { - await seasonRepository.update( - { id: season.id }, - { - status: MediaStatus.UNKNOWN, - status4k: MediaStatus.UNKNOWN, - } - ); - } else { - const seasonExists = await this.seasonExists(media, season); - - if (!seasonExists) { - logger.info( - `Removing season ${season.seasonNumber}, media ID ${media.id} because it does not exist in any of your media instances.`, - { label: 'AvailabilitySync' } - ); - - if ( - season.status !== MediaStatus.UNKNOWN || - season.status4k !== MediaStatus.UNKNOWN - ) { - await seasonRepository.update( - { id: season.id }, - { - status: MediaStatus.UNKNOWN, - status4k: MediaStatus.UNKNOWN, - } - ); - } - - const seasonToBeDeleted = await seasonRequestRepository.findOne( - { - relations: { - request: { - media: true, - }, - }, - where: { - request: { - media: { - id: media.id, - }, - }, - seasonNumber: season.seasonNumber, - }, - } - ); - - if (seasonToBeDeleted) { - await seasonRequestRepository.remove(seasonToBeDeleted); - } - - didDeleteSeasons = true; + label: 'AvailabilitySync', } - } + ); + } - if (didDeleteSeasons) { - if ( - media.status === MediaStatus.AVAILABLE || - media.status4k === MediaStatus.AVAILABLE - ) { - logger.info( - `Marking media ID ${media.id} as PARTIALLY_AVAILABLE because season removal has occurred.`, - { label: 'AvailabilitySync' } - ); + // Here we will create a final map that will cross compare + // with plex and sonarr. Filtered seasons will go through + // each season and assume the season does not exist. If Plex or + // Sonarr finds that season, we will change the final seasons value + // to true. + const filteredSeasonsMap: Map = new Map(); - if (media.status === MediaStatus.AVAILABLE) { - await mediaRepository.update(media.id, { - status: MediaStatus.PARTIALLY_AVAILABLE, - }); - } + media.seasons + .filter( + (season) => + season.status === MediaStatus.AVAILABLE || + season.status === MediaStatus.PARTIALLY_AVAILABLE + ) + .forEach((season) => + filteredSeasonsMap.set(season.seasonNumber, false) + ); - if (media.status4k === MediaStatus.AVAILABLE) { - await mediaRepository.update(media.id, { - status4k: MediaStatus.PARTIALLY_AVAILABLE, - }); - } - } - } + const finalSeasons = new Map([ + ...filteredSeasonsMap, + ...plexSeasonsMap, + ...sonarrSeasonsMap, + ]); + + const filteredSeasonsMap4k: Map = new Map(); + + media.seasons + .filter( + (season) => + season.status4k === MediaStatus.AVAILABLE || + season.status4k === MediaStatus.PARTIALLY_AVAILABLE + ) + .forEach((season) => + filteredSeasonsMap4k.set(season.seasonNumber, false) + ); + + const finalSeasons4k = new Map([ + ...filteredSeasonsMap4k, + ...plexSeasonsMap4k, + ...sonarrSeasonsMap4k, + ]); + + if ([...finalSeasons.values()].includes(false)) { + await this.seasonUpdater(media, finalSeasons, false); + } + + if ([...finalSeasons4k.values()].includes(false)) { + await this.seasonUpdater(media, finalSeasons4k, true); + } + + if ( + !showExists && + (media.status === MediaStatus.AVAILABLE || + media.status === MediaStatus.PARTIALLY_AVAILABLE) + ) { + await this.mediaUpdater(media, false); + } + + if ( + !showExists4k && + (media.status4k === MediaStatus.AVAILABLE || + media.status4k === MediaStatus.PARTIALLY_AVAILABLE) + ) { + await this.mediaUpdater(media, true); } } } @@ -234,582 +243,481 @@ class AvailabilitySync { } while (mediaPage.length > 0); } + private findMediaStatus( + requests: MediaRequest[], + is4k: boolean + ): MediaStatus { + const filteredRequests = requests.filter( + (request) => request.is4k === is4k + ); + + let mediaStatus: MediaStatus; + + if ( + filteredRequests.some( + (request) => request.status === MediaRequestStatus.APPROVED + ) + ) { + mediaStatus = MediaStatus.PROCESSING; + } else if ( + filteredRequests.some( + (request) => request.status === MediaRequestStatus.PENDING + ) + ) { + mediaStatus = MediaStatus.PENDING; + } else { + mediaStatus = MediaStatus.UNKNOWN; + } + + return mediaStatus; + } + private async mediaUpdater(media: Media, is4k: boolean): Promise { const mediaRepository = getRepository(Media); const requestRepository = getRepository(MediaRequest); - const isTVType = media.mediaType === 'tv'; - try { - const request = await requestRepository.findOne({ - relations: { - media: true, - }, - where: { media: { id: media.id }, is4k: is4k ? true : false }, - }); + // Find all related requests only if + // the related media has an available status + const requests = await requestRepository + .createQueryBuilder('request') + .leftJoinAndSelect('request.media', 'media') + .where('(media.id = :id)', { + id: media.id, + }) + .andWhere( + `(request.is4k = :is4k AND media.${ + is4k ? 'status4k' : 'status' + } IN (:...mediaStatus))`, + { + mediaStatus: [ + MediaStatus.AVAILABLE, + MediaStatus.PARTIALLY_AVAILABLE, + ], + is4k: is4k, + } + ) + .getMany(); + + // Check if a season is processing or pending to + // make sure we set the media to the correct status + let mediaStatus = MediaStatus.UNKNOWN; + + if (media.mediaType === 'tv') { + mediaStatus = this.findMediaStatus(requests, is4k); + } + + media[is4k ? 'status4k' : 'status'] = mediaStatus; + media[is4k ? 'serviceId4k' : 'serviceId'] = + mediaStatus === MediaStatus.PROCESSING + ? media[is4k ? 'serviceId4k' : 'serviceId'] + : null; + media[is4k ? 'externalServiceId4k' : 'externalServiceId'] = + mediaStatus === MediaStatus.PROCESSING + ? media[is4k ? 'externalServiceId4k' : 'externalServiceId'] + : null; + media[is4k ? 'externalServiceSlug4k' : 'externalServiceSlug'] = + mediaStatus === MediaStatus.PROCESSING + ? media[is4k ? 'externalServiceSlug4k' : 'externalServiceSlug'] + : null; + media[is4k ? 'ratingKey4k' : 'ratingKey'] = + mediaStatus === MediaStatus.PROCESSING + ? media[is4k ? 'ratingKey4k' : 'ratingKey'] + : null; logger.info( - `Media ID ${media.id} does not exist in your ${ - is4k ? '4k' : 'non-4k' - } ${ - isTVType ? 'Sonarr' : 'Radarr' + `The ${is4k ? '4K' : 'non-4K'} ${ + media.mediaType === 'movie' ? 'movie' : 'show' + } [TMDB ID ${media.tmdbId}] was not found in any ${ + media.mediaType === 'movie' ? 'Radarr' : 'Sonarr' } and Plex instance. Status will be changed to unknown.`, { label: 'AvailabilitySync' } ); - await mediaRepository.update( - media.id, - is4k - ? { - status4k: MediaStatus.UNKNOWN, - serviceId4k: null, - externalServiceId4k: null, - externalServiceSlug4k: null, - ratingKey4k: null, - } - : { - status: MediaStatus.UNKNOWN, - serviceId: null, - externalServiceId: null, - externalServiceSlug: null, - ratingKey: null, - } + await mediaRepository.save({ media, ...media }); + + // Only delete media request if type is movie. + // Type tv request deletion is handled + // in the season request entity + if (requests.length > 0 && media.mediaType === 'movie') { + await requestRepository.remove(requests); + } + } catch (ex) { + logger.debug( + `Failure updating the ${is4k ? '4K' : 'non-4K'} ${ + media.mediaType === 'tv' ? 'show' : 'movie' + } [TMDB ID ${media.tmdbId}].`, + { + errorMessage: ex.message, + label: 'AvailabilitySync', + } ); + } + } - if (isTVType) { - const seasonRepository = getRepository(Season); + private async seasonUpdater( + media: Media, + seasons: Map, + is4k: boolean + ): Promise { + const mediaRepository = getRepository(Media); + const seasonRequestRepository = getRepository(SeasonRequest); - await seasonRepository?.update( - { media: { id: media.id } }, - is4k - ? { status4k: MediaStatus.UNKNOWN } - : { status: MediaStatus.UNKNOWN } + const seasonsPendingRemoval = new Map( + // Disabled linter as only the value is needed from the filter + // eslint-disable-next-line @typescript-eslint/no-unused-vars + [...seasons].filter(([_, exists]) => !exists) + ); + const seasonKeys = [...seasonsPendingRemoval.keys()]; + + try { + // Need to check and see if there are any related season + // requests. If they are, we will need to delete them. + const seasonRequests = await seasonRequestRepository + .createQueryBuilder('seasonRequest') + .leftJoinAndSelect('seasonRequest.request', 'request') + .leftJoinAndSelect('request.media', 'media') + .where('(media.id = :id)', { id: media.id }) + .andWhere( + '(request.is4k = :is4k AND seasonRequest.seasonNumber IN (:...seasonNumbers))', + { + seasonNumbers: seasonKeys, + is4k: is4k, + } + ) + .getMany(); + + for (const mediaSeason of media.seasons) { + if (seasonsPendingRemoval.has(mediaSeason.seasonNumber)) { + mediaSeason[is4k ? 'status4k' : 'status'] = MediaStatus.UNKNOWN; + } + } + + if (media.status === MediaStatus.AVAILABLE) { + media.status = MediaStatus.PARTIALLY_AVAILABLE; + logger.info( + `Marking the non-4K show [TMDB ID ${media.tmdbId}] as PARTIALLY_AVAILABLE because season removal has occurred.`, + { label: 'AvailabilitySync' } ); } - await requestRepository.delete({ id: request?.id }); + if (media.status4k === MediaStatus.AVAILABLE) { + media.status4k = MediaStatus.PARTIALLY_AVAILABLE; + logger.info( + `Marking the 4K show [TMDB ID ${media.tmdbId}] as PARTIALLY_AVAILABLE because season removal has occurred.`, + { label: 'AvailabilitySync' } + ); + } + + await mediaRepository.save({ media, ...media }); + + if (seasonRequests.length > 0) { + await seasonRequestRepository.remove(seasonRequests); + } + + logger.info( + `The ${is4k ? '4K' : 'non-4K'} season(s) [${seasonKeys}] [TMDB ID ${ + media.tmdbId + }] was not found in any ${ + media.mediaType === 'tv' ? 'Sonarr' : 'Radarr' + } and Plex instance. Status will be changed to unknown.`, + { label: 'AvailabilitySync' } + ); } catch (ex) { - logger.debug(`Failure updating media ID ${media.id}`, { - errorMessage: ex.message, - label: 'AvailabilitySync', - }); + logger.debug( + `Failure updating the ${ + is4k ? '4K' : 'non-4K' + } season(s) [${seasonKeys}], TMDB ID ${media.tmdbId}.`, + { + errorMessage: ex.message, + label: 'AvailabilitySync', + } + ); } } private async mediaExistsInRadarr( media: Media, - existsInPlex: boolean, - existsInPlex4k: boolean + is4k: boolean ): Promise { - let existsInRadarr = true; - let existsInRadarr4k = true; + let existsInRadarr = false; + // Check for availability in all of the available radarr servers + // If any find the media, we will assume the media exists for (const server of this.radarrServers) { - const api = new RadarrAPI({ + const radarrAPI = new RadarrAPI({ apiKey: server.apiKey, url: RadarrAPI.buildUrl(server, '/api/v3'), }); + try { - // Check if both exist or if a single non-4k or 4k exists - // If both do not exist we will return false + let radarr: RadarrMovie | undefined; - let meta: RadarrMovie | undefined; - - if (!server.is4k && media.externalServiceId) { - meta = await api.getMovie({ id: media.externalServiceId }); + if (!server.is4k && media.externalServiceId && !is4k) { + radarr = await radarrAPI.getMovie({ + id: media.externalServiceId, + }); } - if (server.is4k && media.externalServiceId4k) { - meta = await api.getMovie({ id: media.externalServiceId4k }); + if (server.is4k && media.externalServiceId4k && is4k) { + radarr = await radarrAPI.getMovie({ + id: media.externalServiceId4k, + }); } - if (!server.is4k && (!meta || !meta.hasFile)) { - existsInRadarr = false; - } - - if (server.is4k && (!meta || !meta.hasFile)) { - existsInRadarr4k = false; + if (radarr && radarr.hasFile) { + existsInRadarr = true; } } catch (ex) { - logger.debug( - `Failure retrieving media ID ${media.id} from your ${ - !server.is4k ? 'non-4K' : '4K' - } Radarr.`, - { - errorMessage: ex.message, - label: 'AvailabilitySync', - } - ); - if (!server.is4k) { - existsInRadarr = false; - } - - if (server.is4k) { - existsInRadarr4k = false; + if (!ex.message.includes('404')) { + existsInRadarr = true; + logger.debug( + `Failure retrieving the ${is4k ? '4K' : 'non-4K'} movie [TMDB ID ${ + media.tmdbId + }] from Radarr.`, + { + errorMessage: ex.message, + label: 'AvailabilitySync', + } + ); } } } - // If only a single non-4k or 4k exists, then change entity columns accordingly - // Related media request will then be deleted - if ( - !existsInRadarr && - (existsInRadarr4k || existsInPlex4k) && - !existsInPlex - ) { - if (media.status !== MediaStatus.UNKNOWN) { - this.mediaUpdater(media, false); - } - } - - if ( - (existsInRadarr || existsInPlex) && - !existsInRadarr4k && - !existsInPlex4k - ) { - if (media.status4k !== MediaStatus.UNKNOWN) { - this.mediaUpdater(media, true); - } - } - - if (existsInRadarr || existsInRadarr4k || existsInPlex || existsInPlex4k) { - return true; - } - - return false; + return existsInRadarr; } private async mediaExistsInSonarr( media: Media, - existsInPlex: boolean, - existsInPlex4k: boolean - ): Promise { - let existsInSonarr = true; - let existsInSonarr4k = true; + is4k: boolean + ): Promise<{ existsInSonarr: boolean; seasonsMap: Map }> { + let existsInSonarr = false; + let preventSeasonSearch = false; + // Check for availability in all of the available sonarr servers + // If any find the media, we will assume the media exists for (const server of this.sonarrServers) { - const api = new SonarrAPI({ + const sonarrAPI = new SonarrAPI({ apiKey: server.apiKey, url: SonarrAPI.buildUrl(server, '/api/v3'), }); + try { - // Check if both exist or if a single non-4k or 4k exists - // If both do not exist we will return false + let sonarr: SonarrSeries | undefined; - let meta: SonarrSeries | undefined; - - if (!server.is4k && media.externalServiceId) { - meta = await api.getSeriesById(media.externalServiceId); + if (!server.is4k && media.externalServiceId && !is4k) { + sonarr = await sonarrAPI.getSeriesById(media.externalServiceId); this.sonarrSeasonsCache[`${server.id}-${media.externalServiceId}`] = - meta.seasons; + sonarr.seasons; } - if (server.is4k && media.externalServiceId4k) { - meta = await api.getSeriesById(media.externalServiceId4k); + if (server.is4k && media.externalServiceId4k && is4k) { + sonarr = await sonarrAPI.getSeriesById(media.externalServiceId4k); this.sonarrSeasonsCache[`${server.id}-${media.externalServiceId4k}`] = - meta.seasons; + sonarr.seasons; } - if (!server.is4k && (!meta || meta.statistics.episodeFileCount === 0)) { - existsInSonarr = false; - } - - if (server.is4k && (!meta || meta.statistics.episodeFileCount === 0)) { - existsInSonarr4k = false; + if (sonarr && sonarr.statistics.episodeFileCount > 0) { + existsInSonarr = true; } } catch (ex) { - logger.debug( - `Failure retrieving media ID ${media.id} from your ${ - !server.is4k ? 'non-4K' : '4K' - } Sonarr.`, - { - errorMessage: ex.message, - label: 'AvailabilitySync', - } + if (!ex.message.includes('404')) { + existsInSonarr = true; + preventSeasonSearch = true; + logger.debug( + `Failure retrieving the ${is4k ? '4K' : 'non-4K'} show [TMDB ID ${ + media.tmdbId + }] from Sonarr.`, + { + errorMessage: ex.message, + label: 'AvailabilitySync', + } + ); + } + } + } + + // Here we check each season for availability + // If the API returns an error other than a 404, + // we will have to prevent the season check from happening + const seasonsMap: Map = new Map(); + + if (!preventSeasonSearch) { + const filteredSeasons = media.seasons.filter( + (season) => + season[is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE || + season[is4k ? 'status4k' : 'status'] === + MediaStatus.PARTIALLY_AVAILABLE + ); + + for (const season of filteredSeasons) { + const seasonExists = await this.seasonExistsInSonarr( + media, + season, + is4k ); - if (!server.is4k) { - existsInSonarr = false; - } - - if (server.is4k) { - existsInSonarr4k = false; + if (seasonExists) { + seasonsMap.set(season.seasonNumber, true); } } } - // If only a single non-4k or 4k exists, then change entity columns accordingly - // Related media request will then be deleted - if ( - !existsInSonarr && - (existsInSonarr4k || existsInPlex4k) && - !existsInPlex - ) { - if (media.status !== MediaStatus.UNKNOWN) { - this.mediaUpdater(media, false); - } - } - - if ( - (existsInSonarr || existsInPlex) && - !existsInSonarr4k && - !existsInPlex4k - ) { - if (media.status4k !== MediaStatus.UNKNOWN) { - this.mediaUpdater(media, true); - } - } - - if (existsInSonarr || existsInSonarr4k || existsInPlex || existsInPlex4k) { - return true; - } - - return false; + return { existsInSonarr, seasonsMap }; } private async seasonExistsInSonarr( media: Media, season: Season, - seasonExistsInPlex: boolean, - seasonExistsInPlex4k: boolean + is4k: boolean ): Promise { - let seasonExistsInSonarr = true; - let seasonExistsInSonarr4k = true; - - const mediaRepository = getRepository(Media); - const seasonRepository = getRepository(Season); - const seasonRequestRepository = getRepository(SeasonRequest); + let seasonExists = false; + // Check each sonarr instance to see if the media still exists + // If found, we will assume the media exists and prevent removal + // We can use the cache we built when we fetched the series with mediaExistsInSonarr for (const server of this.sonarrServers) { - const api = new SonarrAPI({ - apiKey: server.apiKey, - url: SonarrAPI.buildUrl(server, '/api/v3'), - }); + let sonarrSeasons: SonarrSeason[] | undefined; - try { - // Here we can use the cache we built when we fetched the series with mediaExistsInSonarr - // If the cache does not have data, we will fetch with the api route + if (media.externalServiceId && !is4k) { + sonarrSeasons = + this.sonarrSeasonsCache[`${server.id}-${media.externalServiceId}`]; + } - let seasons: SonarrSeason[] = - this.sonarrSeasonsCache[ - `${server.id}-${ - !server.is4k ? media.externalServiceId : media.externalServiceId4k - }` - ]; + if (media.externalServiceId4k && is4k) { + sonarrSeasons = + this.sonarrSeasonsCache[`${server.id}-${media.externalServiceId4k}`]; + } - if (!server.is4k && media.externalServiceId) { - seasons = - this.sonarrSeasonsCache[ - `${server.id}-${media.externalServiceId}` - ] ?? (await api.getSeriesById(media.externalServiceId)).seasons; - this.sonarrSeasonsCache[`${server.id}-${media.externalServiceId}`] = - seasons; + const seasonIsAvailable = sonarrSeasons?.find( + ({ seasonNumber, statistics }) => + season.seasonNumber === seasonNumber && + statistics?.episodeFileCount && + statistics?.episodeFileCount > 0 + ); + + if (seasonIsAvailable && sonarrSeasons) { + seasonExists = true; + } + } + + return seasonExists; + } + + private async mediaExistsInPlex( + media: Media, + is4k: boolean + ): Promise<{ existsInPlex: boolean; seasonsMap?: Map }> { + const ratingKey = media.ratingKey; + const ratingKey4k = media.ratingKey4k; + let existsInPlex = false; + let preventSeasonSearch = false; + + // Check each plex instance to see if the media still exists + // If found, we will assume the media exists and prevent removal + // We can use the cache we built when we fetched the series with mediaExistsInPlex + try { + let plexMedia: PlexMetadata | undefined; + + if (ratingKey && !is4k) { + plexMedia = await this.plexClient?.getMetadata(ratingKey); + + if (media.mediaType === 'tv') { + this.plexSeasonsCache[ratingKey] = + await this.plexClient?.getChildrenMetadata(ratingKey); } + } - if (server.is4k && media.externalServiceId4k) { - seasons = - this.sonarrSeasonsCache[ - `${server.id}-${media.externalServiceId4k}` - ] ?? (await api.getSeriesById(media.externalServiceId4k)).seasons; - this.sonarrSeasonsCache[`${server.id}-${media.externalServiceId4k}`] = - seasons; + if (ratingKey4k && is4k) { + plexMedia = await this.plexClient?.getMetadata(ratingKey4k); + + if (media.mediaType === 'tv') { + this.plexSeasonsCache[ratingKey4k] = + await this.plexClient?.getChildrenMetadata(ratingKey4k); } + } - const seasonIsUnavailable = seasons?.find( - ({ seasonNumber, statistics }) => - season.seasonNumber === seasonNumber && - statistics?.episodeFileCount === 0 - ); - - if (!server.is4k && seasonIsUnavailable) { - seasonExistsInSonarr = false; - } - - if (server.is4k && seasonIsUnavailable) { - seasonExistsInSonarr4k = false; - } - } catch (ex) { + if (plexMedia) { + existsInPlex = true; + } + } catch (ex) { + if (!ex.message.includes('404')) { + existsInPlex = true; + preventSeasonSearch = true; logger.debug( - `Failure retrieving media ID ${media.id} from your ${ - !server.is4k ? 'non-4K' : '4K' - } Sonarr.`, + `Failure retrieving the ${is4k ? '4K' : 'non-4K'} ${ + media.mediaType === 'tv' ? 'show' : 'movie' + } [TMDB ID ${media.tmdbId}] from Plex.`, { errorMessage: ex.message, label: 'AvailabilitySync', } ); - - if (!server.is4k) { - seasonExistsInSonarr = false; - } - - if (server.is4k) { - seasonExistsInSonarr4k = false; - } - } - } - - try { - const seasonToBeDeleted = await seasonRequestRepository.findOne({ - relations: { - request: { - media: true, - }, - }, - where: { - request: { - is4k: seasonExistsInSonarr ? true : false, - media: { - id: media.id, - }, - }, - seasonNumber: season.seasonNumber, - }, - }); - - // If season does not exist, we will change status to unknown and delete related season request - // If parent media request is empty(all related seasons have been removed), parent is automatically deleted - if ( - !seasonExistsInSonarr && - (seasonExistsInSonarr4k || seasonExistsInPlex4k) && - !seasonExistsInPlex - ) { - if (season.status !== MediaStatus.UNKNOWN) { - logger.info( - `Season ${season.seasonNumber}, media ID ${media.id} does not exist in your non-4k Sonarr and Plex instance. Status will be changed to unknown.`, - { label: 'AvailabilitySync' } - ); - await seasonRepository.update(season.id, { - status: MediaStatus.UNKNOWN, - }); - - if (seasonToBeDeleted) { - await seasonRequestRepository.remove(seasonToBeDeleted); - } - - if (media.status === MediaStatus.AVAILABLE) { - logger.info( - `Marking media ID ${media.id} as PARTIALLY_AVAILABLE because season removal has occurred.`, - { label: 'AvailabilitySync' } - ); - await mediaRepository.update(media.id, { - status: MediaStatus.PARTIALLY_AVAILABLE, - }); - } - } - } - - if ( - (seasonExistsInSonarr || seasonExistsInPlex) && - !seasonExistsInSonarr4k && - !seasonExistsInPlex4k - ) { - if (season.status4k !== MediaStatus.UNKNOWN) { - logger.info( - `Season ${season.seasonNumber}, media ID ${media.id} does not exist in your 4k Sonarr and Plex instance. Status will be changed to unknown.`, - { label: 'AvailabilitySync' } - ); - await seasonRepository.update(season.id, { - status4k: MediaStatus.UNKNOWN, - }); - - if (seasonToBeDeleted) { - await seasonRequestRepository.remove(seasonToBeDeleted); - } - - if (media.status4k === MediaStatus.AVAILABLE) { - logger.info( - `Marking media ID ${media.id} as PARTIALLY_AVAILABLE because season removal has occurred.`, - { label: 'AvailabilitySync' } - ); - await mediaRepository.update(media.id, { - status4k: MediaStatus.PARTIALLY_AVAILABLE, - }); - } - } - } - } catch (ex) { - logger.debug(`Failure updating media ID ${media.id}`, { - errorMessage: ex.message, - label: 'AvailabilitySync', - }); - } - - if ( - seasonExistsInSonarr || - seasonExistsInSonarr4k || - seasonExistsInPlex || - seasonExistsInPlex4k - ) { - return true; - } - - return false; - } - - private async mediaExists(media: Media): Promise { - const ratingKey = media.ratingKey; - const ratingKey4k = media.ratingKey4k; - - let existsInPlex = false; - let existsInPlex4k = false; - - // Check each plex instance to see if media exists - try { - if (ratingKey) { - const meta = await this.plexClient?.getMetadata(ratingKey); - if (meta) { - existsInPlex = true; - } - } - - if (ratingKey4k) { - const meta4k = await this.plexClient?.getMetadata(ratingKey4k); - if (meta4k) { - existsInPlex4k = true; - } - } - } catch (ex) { - if (!ex.message.includes('response code: 404')) { - logger.debug(`Failed to retrieve plex metadata`, { - errorMessage: ex.message, - label: 'AvailabilitySync', - }); - } - } - // Base case if both media versions exist in plex - if (existsInPlex && existsInPlex4k) { - return true; - } - - // We then check radarr or sonarr has that specific media. If not, then we will move to delete - // If a non-4k or 4k version exists in at least one of the instances, we will only update that specific version - if (media.mediaType === 'movie') { - const existsInRadarr = await this.mediaExistsInRadarr( - media, - existsInPlex, - existsInPlex4k - ); - - // If true, media exists in at least one radarr or plex instance. - if (existsInRadarr) { - logger.warn( - `${media.id} exists in at least one Radarr or Plex instance. Media will be updated if set to available.`, - { - label: 'AvailabilitySync', - } - ); - - return true; } } + // Here we check each season in plex for availability + // If the API returns an error other than a 404, + // we will have to prevent the season check from happening if (media.mediaType === 'tv') { - const existsInSonarr = await this.mediaExistsInSonarr( - media, - existsInPlex, - existsInPlex4k - ); + const seasonsMap: Map = new Map(); - // If true, media exists in at least one sonarr or plex instance. - if (existsInSonarr) { - logger.warn( - `${media.id} exists in at least one Sonarr or Plex instance. Media will be updated if set to available.`, - { - label: 'AvailabilitySync', - } + if (!preventSeasonSearch) { + const filteredSeasons = media.seasons.filter( + (season) => + season[is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE || + season[is4k ? 'status4k' : 'status'] === + MediaStatus.PARTIALLY_AVAILABLE ); - return true; + for (const season of filteredSeasons) { + const seasonExists = await this.seasonExistsInPlex( + media, + season, + is4k + ); + + if (seasonExists) { + seasonsMap.set(season.seasonNumber, true); + } + } } + + return { existsInPlex, seasonsMap }; } - return false; + return { existsInPlex }; } - private async seasonExists(media: Media, season: Season) { + private async seasonExistsInPlex( + media: Media, + season: Season, + is4k: boolean + ): Promise { const ratingKey = media.ratingKey; const ratingKey4k = media.ratingKey4k; - let seasonExistsInPlex = false; - let seasonExistsInPlex4k = false; - try { - if (ratingKey) { - const children = - this.plexSeasonsCache[ratingKey] ?? - (await this.plexClient?.getChildrenMetadata(ratingKey)) ?? - []; - this.plexSeasonsCache[ratingKey] = children; - const seasonMeta = children?.find( - (child) => child.index === season.seasonNumber - ); + // Check each plex instance to see if the season exists + let plexSeasons: PlexMetadata[] | undefined; - if (seasonMeta) { - seasonExistsInPlex = true; - } - } - if (ratingKey4k) { - const children4k = - this.plexSeasonsCache[ratingKey4k] ?? - (await this.plexClient?.getChildrenMetadata(ratingKey4k)) ?? - []; - this.plexSeasonsCache[ratingKey4k] = children4k; - const seasonMeta4k = children4k?.find( - (child) => child.index === season.seasonNumber - ); - - if (seasonMeta4k) { - seasonExistsInPlex4k = true; - } - } - } catch (ex) { - if (!ex.message.includes('response code: 404')) { - logger.debug(`Failed to retrieve plex's children metadata`, { - errorMessage: ex.message, - label: 'AvailabilitySync', - }); - } - } - // Base case if both season versions exist in plex - if (seasonExistsInPlex && seasonExistsInPlex4k) { - return true; + if (ratingKey && !is4k) { + plexSeasons = this.plexSeasonsCache[ratingKey]; } - const existsInSonarr = await this.seasonExistsInSonarr( - media, - season, - seasonExistsInPlex, - seasonExistsInPlex4k + if (ratingKey4k && is4k) { + plexSeasons = this.plexSeasonsCache[ratingKey4k]; + } + + const seasonIsAvailable = plexSeasons?.find( + (plexSeason) => plexSeason.index === season.seasonNumber ); - if (existsInSonarr) { - logger.warn( - `Season ${season.seasonNumber}, media ID ${media.id} exists in at least one Sonarr or Plex instance. Media will be updated if set to available.`, - { - label: 'AvailabilitySync', - } - ); - - return true; + if (seasonIsAvailable) { + seasonExistsInPlex = true; } - return false; - } - - private async initPlexClient() { - const userRepository = getRepository(User); - const admin = await userRepository.findOne({ - select: { id: true, plexToken: true }, - where: { id: 1 }, - }); - - if (!admin) { - logger.warning('No admin configured. Availability sync skipped.'); - return; - } - - this.plexClient = new PlexAPI({ plexToken: admin.plexToken }); + return seasonExistsInPlex; } } From b4191f9c65b7ff08764e61d18e7a75bc8d4b3325 Mon Sep 17 00:00:00 2001 From: Marco Faggian Date: Fri, 28 Jul 2023 13:51:19 +0200 Subject: [PATCH 09/14] feat(rating): added IMDB Radarr proxy (#3496) * feat(rating): added imdb radarr proxy Signed-off-by: marcofaggian * refactor(rating/imdb): rm export unused interfaces Signed-off-by: marcofaggian * docs(rating/imdb): rt to imdb Signed-off-by: marcofaggian * refactor(rating/imdb): specified error message Signed-off-by: marcofaggian * refactor(rating/imdb): rm line break Signed-off-by: marcofaggian * refactor(rating): conform to types patter Signed-off-by: marcofaggian * chore(rating/imdb): added line to translation file Signed-off-by: marcofaggian * feat(rating/imdb): ratings to ratingscombined Signed-off-by: marcofaggian * fix(rating/imdb): reinstating ratings route Signed-off-by: marcofaggian * docs(ratings): openapi ratings Signed-off-by: marcofaggian * chore(ratings): undo openapi ratings apex Signed-off-by: marcofaggian --------- Signed-off-by: marcofaggian --- overseerr-api.yml | 57 +++++++ server/api/rating/imdbRadarrProxy.ts | 195 ++++++++++++++++++++++ server/api/{ => rating}/rottentomatoes.ts | 8 +- server/api/ratings.ts | 7 + server/lib/cache.ts | 5 + server/routes/movie.ts | 56 ++++++- server/routes/tv.ts | 2 +- src/components/MovieDetails/index.tsx | 92 ++++++---- src/components/TvDetails/index.tsx | 2 +- src/i18n/locale/en.json | 1 + 10 files changed, 385 insertions(+), 40 deletions(-) create mode 100644 server/api/rating/imdbRadarrProxy.ts rename server/api/{ => rating}/rottentomatoes.ts (93%) create mode 100644 server/api/ratings.ts diff --git a/overseerr-api.yml b/overseerr-api.yml index c8b528859..f3a1cc74b 100644 --- a/overseerr-api.yml +++ b/overseerr-api.yml @@ -5338,6 +5338,63 @@ paths: audienceRating: type: string enum: ['Spilled', 'Upright'] + /movie/{movieId}/ratingscombined: + get: + summary: Get RT and IMDB movie ratings combined + description: Returns ratings from RottenTomatoes and IMDB based on the provided movieId in a JSON object. + tags: + - movies + parameters: + - in: path + name: movieId + required: true + schema: + type: number + example: 337401 + responses: + '200': + description: Ratings returned + content: + application/json: + schema: + type: object + properties: + rt: + type: object + properties: + title: + type: string + example: Mulan + year: + type: number + example: 2020 + url: + type: string + example: 'http://www.rottentomatoes.com/m/mulan_2020/' + criticsScore: + type: number + example: 85 + criticsRating: + type: string + enum: ['Rotten', 'Fresh', 'Certified Fresh'] + audienceScore: + type: number + example: 65 + audienceRating: + type: string + enum: ['Spilled', 'Upright'] + imdb: + type: object + properties: + title: + type: string + example: I am Legend + url: + type: string + example: 'https://www.imdb.com/title/tt0480249' + criticsScore: + type: number + example: 6.5 /tv/{tvId}: get: summary: Get TV details diff --git a/server/api/rating/imdbRadarrProxy.ts b/server/api/rating/imdbRadarrProxy.ts new file mode 100644 index 000000000..0d8ec79fb --- /dev/null +++ b/server/api/rating/imdbRadarrProxy.ts @@ -0,0 +1,195 @@ +import ExternalAPI from '@server/api/externalapi'; +import cacheManager from '@server/lib/cache'; + +type IMDBRadarrProxyResponse = IMDBMovie[]; + +interface IMDBMovie { + ImdbId: string; + Overview: string; + Title: string; + OriginalTitle: string; + TitleSlug: string; + Ratings: Rating[]; + MovieRatings: MovieRatings; + Runtime: number; + Images: Image[]; + Genres: string[]; + Popularity: number; + Premier: string; + InCinema: string; + PhysicalRelease: any; + DigitalRelease: string; + Year: number; + AlternativeTitles: AlternativeTitle[]; + Translations: Translation[]; + Recommendations: Recommendation[]; + Credits: Credits; + Studio: string; + YoutubeTrailerId: string; + Certifications: Certification[]; + Status: any; + Collection: Collection; + OriginalLanguage: string; + Homepage: string; + TmdbId: number; +} + +interface Rating { + Count: number; + Value: number; + Origin: string; + Type: string; +} + +interface MovieRatings { + Tmdb: Tmdb; + Imdb: Imdb; + Metacritic: Metacritic; + RottenTomatoes: RottenTomatoes; +} + +interface Tmdb { + Count: number; + Value: number; + Type: string; +} + +interface Imdb { + Count: number; + Value: number; + Type: string; +} + +interface Metacritic { + Count: number; + Value: number; + Type: string; +} + +interface RottenTomatoes { + Count: number; + Value: number; + Type: string; +} + +interface Image { + CoverType: string; + Url: string; +} + +interface AlternativeTitle { + Title: string; + Type: string; + Language: string; +} + +interface Translation { + Title: string; + Overview: string; + Language: string; +} + +interface Recommendation { + TmdbId: number; + Title: string; +} + +interface Credits { + Cast: Cast[]; + Crew: Crew[]; +} + +interface Cast { + Name: string; + Order: number; + Character: string; + TmdbId: number; + CreditId: string; + Images: Image2[]; +} + +interface Image2 { + CoverType: string; + Url: string; +} + +interface Crew { + Name: string; + Job: string; + Department: string; + TmdbId: number; + CreditId: string; + Images: Image3[]; +} + +interface Image3 { + CoverType: string; + Url: string; +} + +interface Certification { + Country: string; + Certification: string; +} + +interface Collection { + Name: string; + Images: any; + Overview: any; + Translations: any; + Parts: any; + TmdbId: number; +} + +export interface IMDBRating { + title: string; + url: string; + criticsScore: number; +} + +/** + * This is a best-effort API. The IMDB API is technically + * private and getting access costs money/requires approval. + * + * Radarr hosts a public proxy that's in use by all Radarr instances. + */ +class IMDBRadarrProxy extends ExternalAPI { + constructor() { + super('https://api.radarr.video/v1', { + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + nodeCache: cacheManager.getCache('imdb').data, + }); + } + + /** + * Ask the Radarr IMDB Proxy for the movie + * + * @param IMDBid Id of IMDB movie + */ + public async getMovieRatings(IMDBid: string): Promise { + try { + const data = await this.get( + `/movie/imdb/${IMDBid}` + ); + + if (!data?.length || data[0].ImdbId !== IMDBid) { + return null; + } + + return { + title: data[0].Title, + url: `https://www.imdb.com/title/${data[0].ImdbId}`, + criticsScore: data[0].MovieRatings.Imdb.Value, + }; + } catch (e) { + throw new Error( + `[IMDB RADARR PROXY API] Failed to retrieve movie ratings: ${e.message}` + ); + } + } +} + +export default IMDBRadarrProxy; diff --git a/server/api/rottentomatoes.ts b/server/api/rating/rottentomatoes.ts similarity index 93% rename from server/api/rottentomatoes.ts rename to server/api/rating/rottentomatoes.ts index 99a74eb1b..1cf9d6d8e 100644 --- a/server/api/rottentomatoes.ts +++ b/server/api/rating/rottentomatoes.ts @@ -1,6 +1,6 @@ +import ExternalAPI from '@server/api/externalapi'; import cacheManager from '@server/lib/cache'; import { getSettings } from '@server/lib/settings'; -import ExternalAPI from './externalapi'; interface RTAlgoliaSearchResponse { results: { @@ -144,6 +144,9 @@ class RottenTomatoes extends ExternalAPI { ? 'Fresh' : 'Rotten', criticsScore: movie.rottenTomatoes.criticsScore, + audienceRating: + movie.rottenTomatoes.audienceScore >= 60 ? 'Upright' : 'Spilled', + audienceScore: movie.rottenTomatoes.audienceScore, year: Number(movie.releaseYear), }; } catch (e) { @@ -192,6 +195,9 @@ class RottenTomatoes extends ExternalAPI { criticsRating: tvshow.rottenTomatoes.criticsScore >= 60 ? 'Fresh' : 'Rotten', criticsScore: tvshow.rottenTomatoes.criticsScore, + audienceRating: + tvshow.rottenTomatoes.audienceScore >= 60 ? 'Upright' : 'Spilled', + audienceScore: tvshow.rottenTomatoes.audienceScore, year: Number(tvshow.releaseYear), }; } catch (e) { diff --git a/server/api/ratings.ts b/server/api/ratings.ts new file mode 100644 index 000000000..1fe1354cf --- /dev/null +++ b/server/api/ratings.ts @@ -0,0 +1,7 @@ +import { type IMDBRating } from '@server/api/rating/imdbRadarrProxy'; +import { type RTRating } from '@server/api/rating/rottentomatoes'; + +export interface RatingResponse { + rt?: RTRating; + imdb?: IMDBRating; +} diff --git a/server/lib/cache.ts b/server/lib/cache.ts index e81466629..011205e7f 100644 --- a/server/lib/cache.ts +++ b/server/lib/cache.ts @@ -5,6 +5,7 @@ export type AvailableCacheIds = | 'radarr' | 'sonarr' | 'rt' + | 'imdb' | 'github' | 'plexguid' | 'plextv'; @@ -51,6 +52,10 @@ class CacheManager { stdTtl: 43200, checkPeriod: 60 * 30, }), + imdb: new Cache('imdb', 'IMDB Radarr Proxy', { + stdTtl: 43200, + checkPeriod: 60 * 30, + }), github: new Cache('github', 'GitHub API', { stdTtl: 21600, checkPeriod: 60 * 30, diff --git a/server/routes/movie.ts b/server/routes/movie.ts index f11cead8c..e39e2e86e 100644 --- a/server/routes/movie.ts +++ b/server/routes/movie.ts @@ -1,4 +1,6 @@ -import RottenTomatoes from '@server/api/rottentomatoes'; +import IMDBRadarrProxy from '@server/api/rating/imdbRadarrProxy'; +import RottenTomatoes from '@server/api/rating/rottentomatoes'; +import { type RatingResponse } from '@server/api/ratings'; import TheMovieDb from '@server/api/themoviedb'; import { MediaType } from '@server/constants/media'; import Media from '@server/entity/Media'; @@ -116,6 +118,9 @@ movieRoutes.get('/:id/similar', async (req, res, next) => { } }); +/** + * Endpoint backed by RottenTomatoes + */ movieRoutes.get('/:id/ratings', async (req, res, next) => { const tmdb = new TheMovieDb(); const rtapi = new RottenTomatoes(); @@ -151,4 +156,53 @@ movieRoutes.get('/:id/ratings', async (req, res, next) => { } }); +/** + * Endpoint combining RottenTomatoes and IMDB + */ +movieRoutes.get('/:id/ratingscombined', async (req, res, next) => { + const tmdb = new TheMovieDb(); + const rtapi = new RottenTomatoes(); + const imdbApi = new IMDBRadarrProxy(); + + try { + const movie = await tmdb.getMovie({ + movieId: Number(req.params.id), + }); + + const rtratings = await rtapi.getMovieRatings( + movie.title, + Number(movie.release_date.slice(0, 4)) + ); + + let imdbRatings; + if (movie.imdb_id) { + imdbRatings = await imdbApi.getMovieRatings(movie.imdb_id); + } + + if (!rtratings && !imdbRatings) { + return next({ + status: 404, + message: 'No ratings found.', + }); + } + + const ratings: RatingResponse = { + ...(rtratings ? { rt: rtratings } : {}), + ...(imdbRatings ? { imdb: imdbRatings } : {}), + }; + + return res.status(200).json(ratings); + } catch (e) { + logger.debug('Something went wrong retrieving movie ratings', { + label: 'API', + errorMessage: e.message, + movieId: req.params.id, + }); + return next({ + status: 500, + message: 'Unable to retrieve movie ratings.', + }); + } +}); + export default movieRoutes; diff --git a/server/routes/tv.ts b/server/routes/tv.ts index d45e40620..95c8dc11c 100644 --- a/server/routes/tv.ts +++ b/server/routes/tv.ts @@ -1,4 +1,4 @@ -import RottenTomatoes from '@server/api/rottentomatoes'; +import RottenTomatoes from '@server/api/rating/rottentomatoes'; import TheMovieDb from '@server/api/themoviedb'; import { MediaType } from '@server/constants/media'; import Media from '@server/entity/Media'; diff --git a/src/components/MovieDetails/index.tsx b/src/components/MovieDetails/index.tsx index 1b142d4de..eaaa902e8 100644 --- a/src/components/MovieDetails/index.tsx +++ b/src/components/MovieDetails/index.tsx @@ -2,6 +2,7 @@ import RTAudFresh from '@app/assets/rt_aud_fresh.svg'; import RTAudRotten from '@app/assets/rt_aud_rotten.svg'; import RTFresh from '@app/assets/rt_fresh.svg'; import RTRotten from '@app/assets/rt_rotten.svg'; +import ImdbLogo from '@app/assets/services/imdb.svg'; import TmdbLogo from '@app/assets/tmdb_logo.svg'; import Button from '@app/components/Common/Button'; import CachedImage from '@app/components/Common/CachedImage'; @@ -40,7 +41,7 @@ import { ChevronDoubleDownIcon, ChevronDoubleUpIcon, } from '@heroicons/react/24/solid'; -import type { RTRating } from '@server/api/rottentomatoes'; +import { type RatingResponse } from '@server/api/ratings'; import { IssueStatus } from '@server/constants/issue'; import { MediaStatus } from '@server/constants/media'; import type { MovieDetails as MovieDetailsType } from '@server/models/Movie'; @@ -86,6 +87,7 @@ const messages = defineMessages({ rtcriticsscore: 'Rotten Tomatoes Tomatometer', rtaudiencescore: 'Rotten Tomatoes Audience Score', tmdbuserscore: 'TMDB User Score', + imdbuserscore: 'IMDB User Score', }); interface MovieDetailsProps { @@ -120,8 +122,8 @@ const MovieDetails = ({ movie }: MovieDetailsProps) => { ), }); - const { data: ratingData } = useSWR( - `/api/v1/movie/${router.query.movieId}/ratings` + const { data: ratingData } = useSWR( + `/api/v1/movie/${router.query.movieId}/ratingscombined` ); const sortedCrew = useMemo( @@ -511,44 +513,62 @@ const MovieDetails = ({ movie }: MovieDetailsProps) => { )}
{(!!data.voteCount || - (ratingData?.criticsRating && !!ratingData?.criticsScore) || - (ratingData?.audienceRating && !!ratingData?.audienceScore)) && ( + (ratingData?.rt?.criticsRating && + !!ratingData?.rt?.criticsScore) || + (ratingData?.rt?.audienceRating && + !!ratingData?.rt?.audienceScore) || + ratingData?.imdb?.criticsScore) && (
- {ratingData?.criticsRating && !!ratingData?.criticsScore && ( - + {ratingData?.rt?.criticsRating && + !!ratingData?.rt?.criticsScore && ( + + + {ratingData.rt.criticsRating === 'Rotten' ? ( + + ) : ( + + )} + {ratingData.rt.criticsScore}% + + + )} + {ratingData?.rt?.audienceRating && + !!ratingData?.rt?.audienceScore && ( + + + {ratingData.rt.audienceRating === 'Spilled' ? ( + + ) : ( + + )} + {ratingData.rt.audienceScore}% + + + )} + {ratingData?.imdb?.criticsScore && ( + - {ratingData.criticsRating === 'Rotten' ? ( - - ) : ( - - )} - {ratingData.criticsScore}% - - - )} - {ratingData?.audienceRating && !!ratingData?.audienceScore && ( - - - {ratingData.audienceRating === 'Spilled' ? ( - - ) : ( - - )} - {ratingData.audienceScore}% + + {ratingData.imdb.criticsScore} )} @@ -797,7 +817,7 @@ const MovieDetails = ({ movie }: MovieDetailsProps) => { tmdbId={data.id} tvdbId={data.externalIds.tvdbId} imdbId={data.externalIds.imdbId} - rtUrl={ratingData?.url} + rtUrl={ratingData?.rt?.url} plexUrl={data.mediaInfo?.plexUrl ?? data.mediaInfo?.plexUrl4k} />
diff --git a/src/components/TvDetails/index.tsx b/src/components/TvDetails/index.tsx index c450ef4ad..2f44a7d8c 100644 --- a/src/components/TvDetails/index.tsx +++ b/src/components/TvDetails/index.tsx @@ -40,7 +40,7 @@ import { PlayIcon, } from '@heroicons/react/24/outline'; import { ChevronDownIcon } from '@heroicons/react/24/solid'; -import type { RTRating } from '@server/api/rottentomatoes'; +import type { RTRating } from '@server/api/rating/rottentomatoes'; import { ANIME_KEYWORD_ID } from '@server/api/themoviedb/constants'; import { IssueStatus } from '@server/constants/issue'; import { MediaRequestStatus, MediaStatus } from '@server/constants/media'; diff --git a/src/i18n/locale/en.json b/src/i18n/locale/en.json index 24a537a07..83d3d8421 100644 --- a/src/i18n/locale/en.json +++ b/src/i18n/locale/en.json @@ -256,6 +256,7 @@ "components.MovieDetails.budget": "Budget", "components.MovieDetails.cast": "Cast", "components.MovieDetails.digitalrelease": "Digital Release", + "components.MovieDetails.imdbuserscore": "IMDB User Score", "components.MovieDetails.managemovie": "Manage Movie", "components.MovieDetails.mark4kavailable": "Mark as Available in 4K", "components.MovieDetails.markavailable": "Mark as Available", From 46e21c4e3e890ebc37ffcbb862148d07c79372d0 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 28 Jul 2023 20:52:03 +0900 Subject: [PATCH 10/14] docs: add marcofaggian as a contributor for code (#3563) [skip ci] * docs: update README.md * docs: update .all-contributorsrc --------- Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index f29044994..53ca949de 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -881,6 +881,15 @@ "contributions": [ "code" ] + }, + { + "login": "marcofaggian", + "name": "Marco Faggian", + "avatar_url": "https://avatars.githubusercontent.com/u/19221001?v=4", + "profile": "https://marcofaggian.com", + "contributions": [ + "code" + ] } ], "badgeTemplate": "\"All-orange.svg\"/>", diff --git a/README.md b/README.md index 0f6e32413..4c7db12e3 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Translation status GitHub -All Contributors +All Contributors

@@ -197,6 +197,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Andrew Kennedy
Andrew Kennedy

💻 Fallenbagel
Fallenbagel

💻 Anton K. (ai Doge)
Anton K. (ai Doge)

💻 + Marco Faggian
Marco Faggian

💻 From cb63bf217b9e8810a5210b4bf475b2a96583cc84 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Fri, 28 Jul 2023 09:41:52 -0500 Subject: [PATCH 11/14] fix: Include all defaults in payload (#3538) * fix: Include all defaults in payload * style(src/components/settings/notifications/notificationswebhook/index.tsx): prettier format format changes from previous commit using prettier. line length requirement now met. * fix(server/lib/settings.ts): update default settings for first install --- server/lib/settings.ts | 2 +- .../Notifications/NotificationsWebhook/index.tsx | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/server/lib/settings.ts b/server/lib/settings.ts index c3981fe90..36dbb1097 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -378,7 +378,7 @@ class Settings { options: { webhookUrl: '', jsonPayload: - 'IntcbiAgICBcIm5vdGlmaWNhdGlvbl90eXBlXCI6IFwie3tub3RpZmljYXRpb25fdHlwZX19XCIsXG4gICAgXCJldmVudFwiOiBcInt7ZXZlbnR9fVwiLFxuICAgIFwic3ViamVjdFwiOiBcInt7c3ViamVjdH19XCIsXG4gICAgXCJtZXNzYWdlXCI6IFwie3ttZXNzYWdlfX1cIixcbiAgICBcImltYWdlXCI6IFwie3tpbWFnZX19XCIsXG4gICAgXCJ7e21lZGlhfX1cIjoge1xuICAgICAgICBcIm1lZGlhX3R5cGVcIjogXCJ7e21lZGlhX3R5cGV9fVwiLFxuICAgICAgICBcInRtZGJJZFwiOiBcInt7bWVkaWFfdG1kYmlkfX1cIixcbiAgICAgICAgXCJ0dmRiSWRcIjogXCJ7e21lZGlhX3R2ZGJpZH19XCIsXG4gICAgICAgIFwic3RhdHVzXCI6IFwie3ttZWRpYV9zdGF0dXN9fVwiLFxuICAgICAgICBcInN0YXR1czRrXCI6IFwie3ttZWRpYV9zdGF0dXM0a319XCJcbiAgICB9LFxuICAgIFwie3tyZXF1ZXN0fX1cIjoge1xuICAgICAgICBcInJlcXVlc3RfaWRcIjogXCJ7e3JlcXVlc3RfaWR9fVwiLFxuICAgICAgICBcInJlcXVlc3RlZEJ5X2VtYWlsXCI6IFwie3tyZXF1ZXN0ZWRCeV9lbWFpbH19XCIsXG4gICAgICAgIFwicmVxdWVzdGVkQnlfdXNlcm5hbWVcIjogXCJ7e3JlcXVlc3RlZEJ5X3VzZXJuYW1lfX1cIixcbiAgICAgICAgXCJyZXF1ZXN0ZWRCeV9hdmF0YXJcIjogXCJ7e3JlcXVlc3RlZEJ5X2F2YXRhcn19XCJcbiAgICB9LFxuICAgIFwie3tpc3N1ZX19XCI6IHtcbiAgICAgICAgXCJpc3N1ZV9pZFwiOiBcInt7aXNzdWVfaWR9fVwiLFxuICAgICAgICBcImlzc3VlX3R5cGVcIjogXCJ7e2lzc3VlX3R5cGV9fVwiLFxuICAgICAgICBcImlzc3VlX3N0YXR1c1wiOiBcInt7aXNzdWVfc3RhdHVzfX1cIixcbiAgICAgICAgXCJyZXBvcnRlZEJ5X2VtYWlsXCI6IFwie3tyZXBvcnRlZEJ5X2VtYWlsfX1cIixcbiAgICAgICAgXCJyZXBvcnRlZEJ5X3VzZXJuYW1lXCI6IFwie3tyZXBvcnRlZEJ5X3VzZXJuYW1lfX1cIixcbiAgICAgICAgXCJyZXBvcnRlZEJ5X2F2YXRhclwiOiBcInt7cmVwb3J0ZWRCeV9hdmF0YXJ9fVwiXG4gICAgfSxcbiAgICBcInt7Y29tbWVudH19XCI6IHtcbiAgICAgICAgXCJjb21tZW50X21lc3NhZ2VcIjogXCJ7e2NvbW1lbnRfbWVzc2FnZX19XCIsXG4gICAgICAgIFwiY29tbWVudGVkQnlfZW1haWxcIjogXCJ7e2NvbW1lbnRlZEJ5X2VtYWlsfX1cIixcbiAgICAgICAgXCJjb21tZW50ZWRCeV91c2VybmFtZVwiOiBcInt7Y29tbWVudGVkQnlfdXNlcm5hbWV9fVwiLFxuICAgICAgICBcImNvbW1lbnRlZEJ5X2F2YXRhclwiOiBcInt7Y29tbWVudGVkQnlfYXZhdGFyfX1cIlxuICAgIH0sXG4gICAgXCJ7e2V4dHJhfX1cIjogW11cbn0i', + 'IntcbiAgXCJub3RpZmljYXRpb25fdHlwZVwiOiBcInt7bm90aWZpY2F0aW9uX3R5cGV9fVwiLFxuICBcImV2ZW50XCI6IFwie3tldmVudH19XCIsXG4gIFwic3ViamVjdFwiOiBcInt7c3ViamVjdH19XCIsXG4gIFwibWVzc2FnZVwiOiBcInt7bWVzc2FnZX19XCIsXG4gIFwiaW1hZ2VcIjogXCJ7e2ltYWdlfX1cIixcbiAgXCJ7e21lZGlhfX1cIjoge1xuICAgIFwibWVkaWFfdHlwZVwiOiBcInt7bWVkaWFfdHlwZX19XCIsXG4gICAgXCJ0bWRiSWRcIjogXCJ7e21lZGlhX3RtZGJpZH19XCIsXG4gICAgXCJ0dmRiSWRcIjogXCJ7e21lZGlhX3R2ZGJpZH19XCIsXG4gICAgXCJzdGF0dXNcIjogXCJ7e21lZGlhX3N0YXR1c319XCIsXG4gICAgXCJzdGF0dXM0a1wiOiBcInt7bWVkaWFfc3RhdHVzNGt9fVwiXG4gIH0sXG4gIFwie3tyZXF1ZXN0fX1cIjoge1xuICAgIFwicmVxdWVzdF9pZFwiOiBcInt7cmVxdWVzdF9pZH19XCIsXG4gICAgXCJyZXF1ZXN0ZWRCeV9lbWFpbFwiOiBcInt7cmVxdWVzdGVkQnlfZW1haWx9fVwiLFxuICAgIFwicmVxdWVzdGVkQnlfdXNlcm5hbWVcIjogXCJ7e3JlcXVlc3RlZEJ5X3VzZXJuYW1lfX1cIixcbiAgICBcInJlcXVlc3RlZEJ5X2F2YXRhclwiOiBcInt7cmVxdWVzdGVkQnlfYXZhdGFyfX1cIixcbiAgICBcInJlcXVlc3RlZEJ5X3NldHRpbmdzX2Rpc2NvcmRJZFwiOiBcInt7cmVxdWVzdGVkQnlfc2V0dGluZ3NfZGlzY29yZElkfX1cIixcbiAgICBcInJlcXVlc3RlZEJ5X3NldHRpbmdzX3RlbGVncmFtQ2hhdElkXCI6IFwie3tyZXF1ZXN0ZWRCeV9zZXR0aW5nc190ZWxlZ3JhbUNoYXRJZH19XCJcbiAgfSxcbiAgXCJ7e2lzc3VlfX1cIjoge1xuICAgIFwiaXNzdWVfaWRcIjogXCJ7e2lzc3VlX2lkfX1cIixcbiAgICBcImlzc3VlX3R5cGVcIjogXCJ7e2lzc3VlX3R5cGV9fVwiLFxuICAgIFwiaXNzdWVfc3RhdHVzXCI6IFwie3tpc3N1ZV9zdGF0dXN9fVwiLFxuICAgIFwicmVwb3J0ZWRCeV9lbWFpbFwiOiBcInt7cmVwb3J0ZWRCeV9lbWFpbH19XCIsXG4gICAgXCJyZXBvcnRlZEJ5X3VzZXJuYW1lXCI6IFwie3tyZXBvcnRlZEJ5X3VzZXJuYW1lfX1cIixcbiAgICBcInJlcG9ydGVkQnlfYXZhdGFyXCI6IFwie3tyZXBvcnRlZEJ5X2F2YXRhcn19XCIsXG4gICAgXCJyZXBvcnRlZEJ5X3NldHRpbmdzX2Rpc2NvcmRJZFwiOiBcInt7cmVwb3J0ZWRCeV9zZXR0aW5nc19kaXNjb3JkSWR9fVwiLFxuICAgIFwicmVwb3J0ZWRCeV9zZXR0aW5nc190ZWxlZ3JhbUNoYXRJZFwiOiBcInt7cmVwb3J0ZWRCeV9zZXR0aW5nc190ZWxlZ3JhbUNoYXRJZH19XCJcbiAgfSxcbiAgXCJ7e2NvbW1lbnR9fVwiOiB7XG4gICAgXCJjb21tZW50X21lc3NhZ2VcIjogXCJ7e2NvbW1lbnRfbWVzc2FnZX19XCIsXG4gICAgXCJjb21tZW50ZWRCeV9lbWFpbFwiOiBcInt7Y29tbWVudGVkQnlfZW1haWx9fVwiLFxuICAgIFwiY29tbWVudGVkQnlfdXNlcm5hbWVcIjogXCJ7e2NvbW1lbnRlZEJ5X3VzZXJuYW1lfX1cIixcbiAgICBcImNvbW1lbnRlZEJ5X2F2YXRhclwiOiBcInt7Y29tbWVudGVkQnlfYXZhdGFyfX1cIixcbiAgICBcImNvbW1lbnRlZEJ5X3NldHRpbmdzX2Rpc2NvcmRJZFwiOiBcInt7Y29tbWVudGVkQnlfc2V0dGluZ3NfZGlzY29yZElkfX1cIixcbiAgICBcImNvbW1lbnRlZEJ5X3NldHRpbmdzX3RlbGVncmFtQ2hhdElkXCI6IFwie3tjb21tZW50ZWRCeV9zZXR0aW5nc190ZWxlZ3JhbUNoYXRJZH19XCJcbiAgfSxcbiAgXCJ7e2V4dHJhfX1cIjogW11cbn0i', }, }, webpush: { diff --git a/src/components/Settings/Notifications/NotificationsWebhook/index.tsx b/src/components/Settings/Notifications/NotificationsWebhook/index.tsx index 14f1e672e..fcddfdbdf 100644 --- a/src/components/Settings/Notifications/NotificationsWebhook/index.tsx +++ b/src/components/Settings/Notifications/NotificationsWebhook/index.tsx @@ -39,6 +39,9 @@ const defaultPayload = { requestedBy_email: '{{requestedBy_email}}', requestedBy_username: '{{requestedBy_username}}', requestedBy_avatar: '{{requestedBy_avatar}}', + requestedBy_settings_discordId: '{{requestedBy_settings_discordId}}', + requestedBy_settings_telegramChatId: + '{{requestedBy_settings_telegramChatId}}', }, '{{issue}}': { issue_id: '{{issue_id}}', @@ -47,12 +50,18 @@ const defaultPayload = { reportedBy_email: '{{reportedBy_email}}', reportedBy_username: '{{reportedBy_username}}', reportedBy_avatar: '{{reportedBy_avatar}}', + reportedBy_settings_discordId: '{{reportedBy_settings_discordId}}', + reportedBy_settings_telegramChatId: + '{{reportedBy_settings_telegramChatId}}', }, '{{comment}}': { comment_message: '{{comment_message}}', commentedBy_email: '{{commentedBy_email}}', commentedBy_username: '{{commentedBy_username}}', commentedBy_avatar: '{{commentedBy_avatar}}', + commentedBy_settings_discordId: '{{commentedBy_settings_discordId}}', + commentedBy_settings_telegramChatId: + '{{commentedBy_settings_telegramChatId}}', }, '{{extra}}': [], }; From a686d31e4d7b64812fdb5d2049d7b4d38990f4f5 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 28 Jul 2023 23:42:29 +0900 Subject: [PATCH 12/14] docs: add nemchik as a contributor for code (#3565) [skip ci] * docs: update README.md * docs: update .all-contributorsrc --------- Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 53ca949de..b5166196f 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -890,6 +890,15 @@ "contributions": [ "code" ] + }, + { + "login": "nemchik", + "name": "Eric Nemchik", + "avatar_url": "https://avatars.githubusercontent.com/u/725456?v=4", + "profile": "http://nemchik.com/", + "contributions": [ + "code" + ] } ], "badgeTemplate": "\"All-orange.svg\"/>", diff --git a/README.md b/README.md index 4c7db12e3..2369a0cda 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Translation status GitHub -All Contributors +All Contributors

@@ -198,6 +198,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Fallenbagel
Fallenbagel

💻 Anton K. (ai Doge)
Anton K. (ai Doge)

💻 Marco Faggian
Marco Faggian

💻 + Eric Nemchik
Eric Nemchik

💻 From f7b4dfcac472d08c54779a14fc1ad3c90927df26 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Fri, 4 Aug 2023 16:26:03 -0700 Subject: [PATCH 13/14] fix(tautulli): only test connection if hostname is defined (#3573) --- server/routes/settings/index.ts | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/server/routes/settings/index.ts b/server/routes/settings/index.ts index 8023ba960..98fe0f776 100644 --- a/server/routes/settings/index.ts +++ b/server/routes/settings/index.ts @@ -254,25 +254,27 @@ settingsRoutes.post('/tautulli', async (req, res, next) => { Object.assign(settings.tautulli, req.body); - try { - const tautulliClient = new TautulliAPI(settings.tautulli); + if (settings.tautulli.hostname) { + try { + const tautulliClient = new TautulliAPI(settings.tautulli); - const result = await tautulliClient.getInfo(); + const result = await tautulliClient.getInfo(); - if (!semver.gte(semver.coerce(result?.tautulli_version) ?? '', '2.9.0')) { - throw new Error('Tautulli version not supported'); + if (!semver.gte(semver.coerce(result?.tautulli_version) ?? '', '2.9.0')) { + throw new Error('Tautulli version not supported'); + } + + settings.save(); + } catch (e) { + logger.error('Something went wrong testing Tautulli connection', { + label: 'API', + errorMessage: e.message, + }); + return next({ + status: 500, + message: 'Unable to connect to Tautulli.', + }); } - - settings.save(); - } catch (e) { - logger.error('Something went wrong testing Tautulli connection', { - label: 'API', - errorMessage: e.message, - }); - return next({ - status: 500, - message: 'Unable to connect to Tautulli.', - }); } return res.status(200).json(settings.tautulli); From 317110855e6096d6c9af80d1b469565bb8314e9f Mon Sep 17 00:00:00 2001 From: Ryan Cohen Date: Sun, 6 Aug 2023 16:15:03 +0900 Subject: [PATCH 14/14] ci: remove docker caching to save space after build (#3574) --- .github/workflows/ci.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c670f6b9..4914d3375 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,13 +39,6 @@ jobs: uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - name: Log in to Docker Hub uses: docker/login-action@v2 with: @@ -71,15 +64,6 @@ jobs: sctx/overseerr:${{ github.sha }} ghcr.io/sct/overseerr:develop ghcr.io/sct/overseerr:${{ github.sha }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max - - # Temporary fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache discord: name: Send Discord Notification