From 9b9597093c69e632791d30df1897199911b0d32a Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Wed, 20 Jun 2018 21:17:48 +0200 Subject: [PATCH] Fixed: Regression causing Manual Import to ignore user provided information. --- .../ManualImport/ManualImportResource.cs | 2 + .../EpisodeImport/Manual/ManualImportFile.cs | 1 + .../EpisodeImport/Manual/ManualImportItem.cs | 1 + .../Manual/ManualImportService.cs | 93 +++++++++++-------- src/UI/ManualImport/ManualImportLayout.js | 1 + 5 files changed, 61 insertions(+), 37 deletions(-) diff --git a/src/NzbDrone.Api/ManualImport/ManualImportResource.cs b/src/NzbDrone.Api/ManualImport/ManualImportResource.cs index bc7b87408..1a779a410 100644 --- a/src/NzbDrone.Api/ManualImport/ManualImportResource.cs +++ b/src/NzbDrone.Api/ManualImport/ManualImportResource.cs @@ -13,6 +13,7 @@ namespace NzbDrone.Api.ManualImport { public string Path { get; set; } public string RelativePath { get; set; } + public string FolderName { get; set; } public string Name { get; set; } public long Size { get; set; } public SeriesResource Series { get; set; } @@ -36,6 +37,7 @@ namespace NzbDrone.Api.ManualImport Path = model.Path, RelativePath = model.RelativePath, + FolderName = model.FolderName, Name = model.Name, Size = model.Size, Series = model.Series.ToResource(), diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportFile.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportFile.cs index 4c9fecc7c..f0d42b21d 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportFile.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportFile.cs @@ -6,6 +6,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual public class ManualImportFile { public string Path { get; set; } + public string FolderName { get; set; } public int SeriesId { get; set; } public List EpisodeIds { get; set; } public QualityModel Quality { get; set; } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportItem.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportItem.cs index bd3954816..6f055d7d2 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportItem.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportItem.cs @@ -9,6 +9,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual { public string Path { get; set; } public string RelativePath { get; set; } + public string FolderName { get; set; } public string Name { get; set; } public long Size { get; set; } public Series Series { get; set; } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs index bb80a0569..40ae716fe 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs @@ -90,16 +90,17 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual return new List(); } - return new List { ProcessFile(path, downloadId) }; + var rootFolder = Path.GetDirectoryName(path); + return new List { ProcessFile(rootFolder, rootFolder, path, downloadId) }; } - return ProcessFolder(path, downloadId); + return ProcessFolder(path, path, downloadId); } - private List ProcessFolder(string folder, string downloadId) + private List ProcessFolder(string rootFolder, string baseFolder, string downloadId) { DownloadClientItem downloadClientItem = null; - var directoryInfo = new DirectoryInfo(folder); + var directoryInfo = new DirectoryInfo(baseFolder); var series = _parsingService.GetSeries(directoryInfo.Name); if (downloadId.IsNotNullOrWhiteSpace()) @@ -115,27 +116,26 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual if (series == null) { - var files = _diskScanService.FilterFiles(folder, _diskScanService.GetVideoFiles(folder)); + var files = _diskScanService.FilterFiles(baseFolder, _diskScanService.GetVideoFiles(baseFolder, false)); + var subfolders = _diskScanService.FilterFiles(baseFolder, _diskProvider.GetDirectories(baseFolder)); - return files.Select(file => ProcessFile(file, downloadId, folder)).Where(i => i != null).ToList(); + var processedFiles = files.Select(file => ProcessFile(rootFolder, baseFolder, file, downloadId)); + var processedFolders = subfolders.SelectMany(subfolder => ProcessFolder(rootFolder, subfolder, downloadId)); + + return processedFiles.Concat(processedFolders).Where(i => i != null).ToList(); } var folderInfo = Parser.Parser.ParseTitle(directoryInfo.Name); - var seriesFiles = _diskScanService.GetVideoFiles(folder).ToList(); - var decisions = _importDecisionMaker.GetImportDecisions(seriesFiles, series, downloadClientItem, folderInfo, SceneSource(series, folder)); + var seriesFiles = _diskScanService.GetVideoFiles(baseFolder).ToList(); + var decisions = _importDecisionMaker.GetImportDecisions(seriesFiles, series, downloadClientItem, folderInfo, SceneSource(series, baseFolder)); - return decisions.Select(decision => MapItem(decision, folder, downloadId)).ToList(); + return decisions.Select(decision => MapItem(decision, rootFolder, downloadId, directoryInfo.Name)).ToList(); } - private ManualImportItem ProcessFile(string file, string downloadId, string folder = null) + private ManualImportItem ProcessFile(string rootFolder, string baseFolder, string file, string downloadId) { - if (folder.IsNullOrWhiteSpace()) - { - folder = new FileInfo(file).Directory.FullName; - } - DownloadClientItem downloadClientItem = null; - var relativeFile = folder.GetRelativePath(file); + var relativeFile = baseFolder.GetRelativePath(file); var series = _parsingService.GetSeries(relativeFile.Split('\\', '/')[0]); if (series == null) @@ -171,23 +171,25 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual localEpisode.Quality = QualityParser.ParseQuality(file); localEpisode.Size = _diskProvider.GetFileSize(file); - return MapItem(new ImportDecision(localEpisode, new Rejection("Unknown Series")), folder, downloadId); + return MapItem(new ImportDecision(localEpisode, new Rejection("Unknown Series")), rootFolder, downloadId, null); } var importDecisions = _importDecisionMaker.GetImportDecisions(new List {file}, - series, downloadClientItem, null, SceneSource(series, folder)); + series, downloadClientItem, null, SceneSource(series, baseFolder)); - return importDecisions.Any() ? MapItem(importDecisions.First(), folder, downloadId) : new ManualImportItem - { - DownloadId = downloadId, - Path = file, - RelativePath = folder.GetRelativePath(file), - Name = Path.GetFileNameWithoutExtension(file), - Rejections = new List - { - new Rejection("Unable to process file") - } - }; + if (importDecisions.Any()) + { + return MapItem(importDecisions.First(), rootFolder, downloadId, null); + } + + return new ManualImportItem + { + DownloadId = downloadId, + Path = file, + RelativePath = rootFolder.GetRelativePath(file), + Name = Path.GetFileNameWithoutExtension(file), + Rejections = new List() + }; } private bool SceneSource(Series series, string folder) @@ -195,12 +197,13 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual return !(series.Path.PathEquals(folder) || series.Path.IsParentPath(folder)); } - private ManualImportItem MapItem(ImportDecision decision, string folder, string downloadId) + private ManualImportItem MapItem(ImportDecision decision, string rootFolder, string downloadId, string folderName) { var item = new ManualImportItem(); item.Path = decision.LocalEpisode.Path; - item.RelativePath = folder.GetRelativePath(decision.LocalEpisode.Path); + item.FolderName = folderName; + item.RelativePath = rootFolder.GetRelativePath(decision.LocalEpisode.Path); item.Name = Path.GetFileNameWithoutExtension(decision.LocalEpisode.Path); item.DownloadId = downloadId; @@ -250,14 +253,13 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual var series = _seriesService.GetSeries(file.SeriesId); var episodes = _episodeService.GetEpisodes(file.EpisodeIds); var fileEpisodeInfo = Parser.Parser.ParsePath(file.Path) ?? new ParsedEpisodeInfo(); - var mediaInfo = _videoFileInfoReader.GetMediaInfo(file.Path); var existingFile = series.Path.IsParentPath(file.Path); + TrackedDownload trackedDownload = null; var localEpisode = new LocalEpisode { ExistingFile = false, Episodes = episodes, - MediaInfo = mediaInfo, FileEpisodeInfo = fileEpisodeInfo, Path = file.Path, Quality = file.Quality, @@ -265,20 +267,37 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual Size = 0 }; - //TODO: Cleanup non-tracked downloads + if (file.DownloadId.IsNotNullOrWhiteSpace()) + { + trackedDownload = _trackedDownloadService.Find(file.DownloadId); + if (trackedDownload != null) + { + localEpisode.DownloadClientEpisodeInfo = trackedDownload.RemoteEpisode.ParsedEpisodeInfo; + } + } + + if (file.FolderName.IsNotNullOrWhiteSpace()) + { + localEpisode.FolderEpisodeInfo = Parser.Parser.ParseTitle(file.FolderName); + } localEpisode = _augmentingService.Augment(localEpisode, false); + // Apply the user-chosen values. + localEpisode.Series = series; + localEpisode.Episodes = episodes; + localEpisode.Quality = file.Quality; + + //TODO: Cleanup non-tracked downloads + var importDecision = new ImportDecision(localEpisode); - if (file.DownloadId.IsNullOrWhiteSpace()) + if (trackedDownload == null) { imported.AddRange(_importApprovedEpisodes.Import(new List { importDecision }, !existingFile, null, message.ImportMode)); } - else { - var trackedDownload = _trackedDownloadService.Find(file.DownloadId); var importResult = _importApprovedEpisodes.Import(new List { importDecision }, true, trackedDownload.DownloadItem, message.ImportMode).First(); imported.Add(importResult); diff --git a/src/UI/ManualImport/ManualImportLayout.js b/src/UI/ManualImport/ManualImportLayout.js index fbcfa96de..54664209f 100644 --- a/src/UI/ManualImport/ManualImportLayout.js +++ b/src/UI/ManualImport/ManualImportLayout.js @@ -211,6 +211,7 @@ module.exports = Marionette.Layout.extend({ files : _.map(selected, function (file) { return { path : file.get('path'), + folderName : file.get('folderName'), seriesId : file.get('series').id, episodeIds : _.map(file.get('episodes'), 'id'), quality : file.get('quality'),