New: Don't process files during Manual Import if there are more than 100 items

Closes #1142
This commit is contained in:
Mark McDowall 2020-11-15 17:49:45 -08:00
parent ad9e709d96
commit fed2a429c7
2 changed files with 41 additions and 4 deletions

View File

@ -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<ManualImportItem> ProcessDownloadDirectory(string rootFolder, List<string> videoFiles)
{
var items = new List<ManualImportItem>();
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));

View File

@ -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;
}