From 36338310dfe7322b2e1561895ce48f382a558fef Mon Sep 17 00:00:00 2001 From: jack-mil <62065280+jack-mil@users.noreply.github.com> Date: Mon, 17 Jul 2023 23:46:36 -0400 Subject: [PATCH] New: Show Custom Format score in Manual Import (cherry picked from commit 972e1408993fc4656196087c6646f23d222e41f5) Closes #8839 --- .../Interactive/InteractiveImportRow.tsx | 10 ++++++++-- frontend/src/Store/Actions/interactiveImportActions.js | 4 ++++ .../MediaFiles/MovieImport/Manual/ManualImportItem.cs | 1 + .../MovieImport/Manual/ManualImportService.cs | 1 + .../ManualImport/ManualImportController.cs | 3 +++ .../ManualImport/ManualImportReprocessResource.cs | 4 +++- src/Radarr.Api.V3/ManualImport/ManualImportResource.cs | 7 ++++++- 7 files changed, 26 insertions(+), 4 deletions(-) diff --git a/frontend/src/InteractiveImport/Interactive/InteractiveImportRow.tsx b/frontend/src/InteractiveImport/Interactive/InteractiveImportRow.tsx index e5fa6cf44..6e4f1629f 100644 --- a/frontend/src/InteractiveImport/Interactive/InteractiveImportRow.tsx +++ b/frontend/src/InteractiveImport/Interactive/InteractiveImportRow.tsx @@ -25,6 +25,7 @@ import { import { SelectStateInputProps } from 'typings/props'; import Rejection from 'typings/Rejection'; import formatBytes from 'Utilities/Number/formatBytes'; +import formatCustomFormatScore from 'Utilities/Number/formatCustomFormatScore'; import translate from 'Utilities/String/translate'; import InteractiveImportRowCellPlaceholder from './InteractiveImportRowCellPlaceholder'; import styles from './InteractiveImportRow.css'; @@ -45,6 +46,7 @@ interface InteractiveImportRowProps { languages?: Language[]; size: number; customFormats?: object[]; + customFormatScore?: number; rejections: Rejection[]; columns: Column[]; movieFileId?: number; @@ -66,6 +68,7 @@ function InteractiveImportRow(props: InteractiveImportRowProps) { releaseGroup, size, customFormats, + customFormatScore, rejections, isSelected, modalTitle, @@ -293,8 +296,11 @@ function InteractiveImportRow(props: InteractiveImportRowProps) { {customFormats?.length ? ( } - title={translate('Formats')} + anchor={formatCustomFormatScore( + customFormatScore, + customFormats.length + )} + title={translate('CustomFormats')} body={
diff --git a/frontend/src/Store/Actions/interactiveImportActions.js b/frontend/src/Store/Actions/interactiveImportActions.js index 6cf355c27..854aeb1ec 100644 --- a/frontend/src/Store/Actions/interactiveImportActions.js +++ b/frontend/src/Store/Actions/interactiveImportActions.js @@ -47,6 +47,10 @@ export const defaultState = { quality: function(item, direction) { return item.qualityWeight || 0; + }, + + customFormats: function(item, direction) { + return item.customFormatScore; } } }; diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportItem.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportItem.cs index 2f19a99f4..516c0dd5e 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportItem.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportItem.cs @@ -19,6 +19,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Manual public string ReleaseGroup { get; set; } public string DownloadId { get; set; } public List CustomFormats { get; set; } + public int CustomFormatScore { get; set; } public IEnumerable Rejections { get; set; } public Movie Movie { get; set; } diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportService.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportService.cs index b2175cb18..786ff182d 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Manual/ManualImportService.cs @@ -312,6 +312,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Manual item.Movie = decision.LocalMovie.Movie; item.CustomFormats = _formatCalculator.ParseCustomFormat(decision.LocalMovie); + item.CustomFormatScore = item.Movie.Profile?.CalculateCustomFormatScore(item.CustomFormats) ?? 0; } item.Quality = decision.LocalMovie.Quality; diff --git a/src/Radarr.Api.V3/ManualImport/ManualImportController.cs b/src/Radarr.Api.V3/ManualImport/ManualImportController.cs index 7914fc59d..cd6de2743 100644 --- a/src/Radarr.Api.V3/ManualImport/ManualImportController.cs +++ b/src/Radarr.Api.V3/ManualImport/ManualImportController.cs @@ -5,6 +5,7 @@ using NzbDrone.Common.Extensions; using NzbDrone.Core.Languages; using NzbDrone.Core.MediaFiles.MovieImport.Manual; using NzbDrone.Core.Qualities; +using Radarr.Api.V3.CustomFormats; using Radarr.Api.V3.Movies; using Radarr.Http; @@ -35,6 +36,8 @@ namespace Radarr.Api.V3.ManualImport item.Movie = processedItem.Movie.ToResource(0); item.Rejections = processedItem.Rejections; + item.CustomFormats = processedItem.CustomFormats.ToResource(false); + item.CustomFormatScore = processedItem.CustomFormatScore; if (item.Languages?.Count <= 1 && (item.Languages?.SingleOrDefault() ?? Language.Unknown) == Language.Unknown && processedItem.Languages.Any()) diff --git a/src/Radarr.Api.V3/ManualImport/ManualImportReprocessResource.cs b/src/Radarr.Api.V3/ManualImport/ManualImportReprocessResource.cs index 4999ae42d..5733f145e 100644 --- a/src/Radarr.Api.V3/ManualImport/ManualImportReprocessResource.cs +++ b/src/Radarr.Api.V3/ManualImport/ManualImportReprocessResource.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Languages; using NzbDrone.Core.Qualities; +using Radarr.Api.V3.CustomFormats; using Radarr.Api.V3.Movies; using Radarr.Http.REST; @@ -16,7 +17,8 @@ namespace Radarr.Api.V3.ManualImport public List Languages { get; set; } public string ReleaseGroup { get; set; } public string DownloadId { get; set; } - + public List CustomFormats { get; set; } + public int CustomFormatScore { get; set; } public IEnumerable Rejections { get; set; } } } diff --git a/src/Radarr.Api.V3/ManualImport/ManualImportResource.cs b/src/Radarr.Api.V3/ManualImport/ManualImportResource.cs index ac2b86f57..a51c41a48 100644 --- a/src/Radarr.Api.V3/ManualImport/ManualImportResource.cs +++ b/src/Radarr.Api.V3/ManualImport/ManualImportResource.cs @@ -25,6 +25,7 @@ namespace Radarr.Api.V3.ManualImport public int QualityWeight { get; set; } public string DownloadId { get; set; } public List CustomFormats { get; set; } + public int CustomFormatScore { get; set; } public IEnumerable Rejections { get; set; } } @@ -37,6 +38,9 @@ namespace Radarr.Api.V3.ManualImport return null; } + var customFormats = model.CustomFormats; + var customFormatScore = model.Movie?.Profile?.CalculateCustomFormatScore(customFormats) ?? 0; + return new ManualImportResource { Id = HashConverter.GetHashInt31(model.Path), @@ -49,7 +53,8 @@ namespace Radarr.Api.V3.ManualImport ReleaseGroup = model.ReleaseGroup, Quality = model.Quality, Languages = model.Languages, - CustomFormats = model.CustomFormats.ToResource(false), + CustomFormats = customFormats.ToResource(false), + CustomFormatScore = customFormatScore, // QualityWeight DownloadId = model.DownloadId,