From fed2a429c7a3f0eeb83d36a3edbddde9a77a263e Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 15 Nov 2020 17:49:45 -0800 Subject: [PATCH] New: Don't process files during Manual Import if there are more than 100 items Closes #1142 --- .../Manual/ManualImportService.cs | 33 ++++++++++++++++--- .../ManualImport/ManualImportModule.cs | 12 +++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs index 53b77d1db..01b643593 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs @@ -115,8 +115,8 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual SceneSource = SceneSource(series, rootFolder), ExistingFile = series.Path.IsParentPath(path), Size = _diskProvider.GetFileSize(path), - Language = language, - Quality = quality + Language = language == Language.Unknown ? LanguageParser.ParseLanguage(path) : language, + Quality = quality.Quality == Quality.Unknown ? QualityParser.ParseQuality(path) : quality }; return MapItem(_importDecisionMaker.GetDecision(localEpisode, downloadClientItem), rootFolder, downloadId, null); @@ -141,8 +141,8 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual SceneSource = SceneSource(series, rootFolder), ExistingFile = series.Path.IsParentPath(path), Size = _diskProvider.GetFileSize(path), - Language = language, - Quality = quality + Language = language == Language.Unknown ? LanguageParser.ParseLanguage(path) : language, + Quality = quality.Quality == Quality.Unknown ? QualityParser.ParseQuality(path) : quality }; return MapItem(new ImportDecision(localEpisode, new Rejection("Episodes not selected")), rootFolder, downloadId, null); @@ -191,7 +191,14 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual // It will lead to some extra directories being checked for files, but it saves the processing of them and is cleaner than // teaching FilterPaths to know whether it's processing a file or a folder and changing it's filtering based on that. + // If the series is unknown for the directory and there are more than 100 files in the folder don't process the items before returning. var files = _diskScanService.FilterPaths(rootFolder, _diskScanService.GetVideoFiles(baseFolder, false)); + + if (files.Count() > 100) + { + return ProcessDownloadDirectory(rootFolder, files); + } + var subfolders = _diskScanService.FilterPaths(rootFolder, _diskProvider.GetDirectories(baseFolder)); var processedFiles = files.Select(file => ProcessFile(rootFolder, baseFolder, file, downloadId)); @@ -274,6 +281,24 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual }; } + private List ProcessDownloadDirectory(string rootFolder, List videoFiles) + { + var items = new List(); + + foreach (var file in videoFiles) + { + var localEpisode = new LocalEpisode(); + localEpisode.Path = file; + localEpisode.Quality = new QualityModel(Quality.Unknown); + localEpisode.Language = Language.Unknown; + localEpisode.Size = _diskProvider.GetFileSize(file); + + items.Add(MapItem(new ImportDecision(localEpisode), rootFolder, null, null)); + } + + return items; + } + private bool SceneSource(Series series, string folder) { return !(series.Path.PathEquals(folder) || series.Path.IsParentPath(folder)); diff --git a/src/Sonarr.Api.V3/ManualImport/ManualImportModule.cs b/src/Sonarr.Api.V3/ManualImport/ManualImportModule.cs index 1c73a840e..b560969af 100644 --- a/src/Sonarr.Api.V3/ManualImport/ManualImportModule.cs +++ b/src/Sonarr.Api.V3/ManualImport/ManualImportModule.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using Nancy; +using NzbDrone.Core.Languages; using NzbDrone.Core.MediaFiles.EpisodeImport.Manual; using NzbDrone.Core.Qualities; using Sonarr.Api.V3.Episodes; @@ -44,6 +45,17 @@ namespace Sonarr.Api.V3.ManualImport item.Episodes = processedItem.Episodes.ToResource(); item.Rejections = processedItem.Rejections; + // Only set the language/quality if they're unknown + if (item.Language == Language.Unknown) + { + item.Language = processedItem.Language; + } + + if (item.Quality?.Quality == Quality.Unknown) + { + item.Quality = processedItem.Quality; + } + // Clear episode IDs in favour of the full episode item.EpisodeIds = null; }