Fixed: Regression causing Manual Import to ignore user provided information.

This commit is contained in:
Taloth Saldono 2018-06-20 21:17:48 +02:00 committed by Taloth
parent c92fb4d9c0
commit 9b9597093c
5 changed files with 61 additions and 37 deletions

View File

@ -13,6 +13,7 @@ namespace NzbDrone.Api.ManualImport
{ {
public string Path { get; set; } public string Path { get; set; }
public string RelativePath { get; set; } public string RelativePath { get; set; }
public string FolderName { get; set; }
public string Name { get; set; } public string Name { get; set; }
public long Size { get; set; } public long Size { get; set; }
public SeriesResource Series { get; set; } public SeriesResource Series { get; set; }
@ -36,6 +37,7 @@ namespace NzbDrone.Api.ManualImport
Path = model.Path, Path = model.Path,
RelativePath = model.RelativePath, RelativePath = model.RelativePath,
FolderName = model.FolderName,
Name = model.Name, Name = model.Name,
Size = model.Size, Size = model.Size,
Series = model.Series.ToResource(), Series = model.Series.ToResource(),

View File

@ -6,6 +6,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
public class ManualImportFile public class ManualImportFile
{ {
public string Path { get; set; } public string Path { get; set; }
public string FolderName { get; set; }
public int SeriesId { get; set; } public int SeriesId { get; set; }
public List<int> EpisodeIds { get; set; } public List<int> EpisodeIds { get; set; }
public QualityModel Quality { get; set; } public QualityModel Quality { get; set; }

View File

@ -9,6 +9,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
{ {
public string Path { get; set; } public string Path { get; set; }
public string RelativePath { get; set; } public string RelativePath { get; set; }
public string FolderName { get; set; }
public string Name { get; set; } public string Name { get; set; }
public long Size { get; set; } public long Size { get; set; }
public Series Series { get; set; } public Series Series { get; set; }

View File

@ -90,16 +90,17 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
return new List<ManualImportItem>(); return new List<ManualImportItem>();
} }
return new List<ManualImportItem> { ProcessFile(path, downloadId) }; var rootFolder = Path.GetDirectoryName(path);
return new List<ManualImportItem> { ProcessFile(rootFolder, rootFolder, path, downloadId) };
} }
return ProcessFolder(path, downloadId); return ProcessFolder(path, path, downloadId);
} }
private List<ManualImportItem> ProcessFolder(string folder, string downloadId) private List<ManualImportItem> ProcessFolder(string rootFolder, string baseFolder, string downloadId)
{ {
DownloadClientItem downloadClientItem = null; DownloadClientItem downloadClientItem = null;
var directoryInfo = new DirectoryInfo(folder); var directoryInfo = new DirectoryInfo(baseFolder);
var series = _parsingService.GetSeries(directoryInfo.Name); var series = _parsingService.GetSeries(directoryInfo.Name);
if (downloadId.IsNotNullOrWhiteSpace()) if (downloadId.IsNotNullOrWhiteSpace())
@ -115,27 +116,26 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
if (series == null) 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 folderInfo = Parser.Parser.ParseTitle(directoryInfo.Name);
var seriesFiles = _diskScanService.GetVideoFiles(folder).ToList(); var seriesFiles = _diskScanService.GetVideoFiles(baseFolder).ToList();
var decisions = _importDecisionMaker.GetImportDecisions(seriesFiles, series, downloadClientItem, folderInfo, SceneSource(series, folder)); 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; DownloadClientItem downloadClientItem = null;
var relativeFile = folder.GetRelativePath(file); var relativeFile = baseFolder.GetRelativePath(file);
var series = _parsingService.GetSeries(relativeFile.Split('\\', '/')[0]); var series = _parsingService.GetSeries(relativeFile.Split('\\', '/')[0]);
if (series == null) if (series == null)
@ -171,23 +171,25 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
localEpisode.Quality = QualityParser.ParseQuality(file); localEpisode.Quality = QualityParser.ParseQuality(file);
localEpisode.Size = _diskProvider.GetFileSize(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<string> {file}, var importDecisions = _importDecisionMaker.GetImportDecisions(new List<string> {file},
series, downloadClientItem, null, SceneSource(series, folder)); series, downloadClientItem, null, SceneSource(series, baseFolder));
return importDecisions.Any() ? MapItem(importDecisions.First(), folder, downloadId) : new ManualImportItem if (importDecisions.Any())
{ {
DownloadId = downloadId, return MapItem(importDecisions.First(), rootFolder, downloadId, null);
Path = file, }
RelativePath = folder.GetRelativePath(file),
Name = Path.GetFileNameWithoutExtension(file), return new ManualImportItem
Rejections = new List<Rejection> {
{ DownloadId = downloadId,
new Rejection("Unable to process file") Path = file,
} RelativePath = rootFolder.GetRelativePath(file),
}; Name = Path.GetFileNameWithoutExtension(file),
Rejections = new List<Rejection>()
};
} }
private bool SceneSource(Series series, string folder) 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)); 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(); var item = new ManualImportItem();
item.Path = decision.LocalEpisode.Path; 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.Name = Path.GetFileNameWithoutExtension(decision.LocalEpisode.Path);
item.DownloadId = downloadId; item.DownloadId = downloadId;
@ -250,14 +253,13 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
var series = _seriesService.GetSeries(file.SeriesId); var series = _seriesService.GetSeries(file.SeriesId);
var episodes = _episodeService.GetEpisodes(file.EpisodeIds); var episodes = _episodeService.GetEpisodes(file.EpisodeIds);
var fileEpisodeInfo = Parser.Parser.ParsePath(file.Path) ?? new ParsedEpisodeInfo(); var fileEpisodeInfo = Parser.Parser.ParsePath(file.Path) ?? new ParsedEpisodeInfo();
var mediaInfo = _videoFileInfoReader.GetMediaInfo(file.Path);
var existingFile = series.Path.IsParentPath(file.Path); var existingFile = series.Path.IsParentPath(file.Path);
TrackedDownload trackedDownload = null;
var localEpisode = new LocalEpisode var localEpisode = new LocalEpisode
{ {
ExistingFile = false, ExistingFile = false,
Episodes = episodes, Episodes = episodes,
MediaInfo = mediaInfo,
FileEpisodeInfo = fileEpisodeInfo, FileEpisodeInfo = fileEpisodeInfo,
Path = file.Path, Path = file.Path,
Quality = file.Quality, Quality = file.Quality,
@ -265,20 +267,37 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
Size = 0 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); 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); var importDecision = new ImportDecision(localEpisode);
if (file.DownloadId.IsNullOrWhiteSpace()) if (trackedDownload == null)
{ {
imported.AddRange(_importApprovedEpisodes.Import(new List<ImportDecision> { importDecision }, !existingFile, null, message.ImportMode)); imported.AddRange(_importApprovedEpisodes.Import(new List<ImportDecision> { importDecision }, !existingFile, null, message.ImportMode));
} }
else else
{ {
var trackedDownload = _trackedDownloadService.Find(file.DownloadId);
var importResult = _importApprovedEpisodes.Import(new List<ImportDecision> { importDecision }, true, trackedDownload.DownloadItem, message.ImportMode).First(); var importResult = _importApprovedEpisodes.Import(new List<ImportDecision> { importDecision }, true, trackedDownload.DownloadItem, message.ImportMode).First();
imported.Add(importResult); imported.Add(importResult);

View File

@ -211,6 +211,7 @@ module.exports = Marionette.Layout.extend({
files : _.map(selected, function (file) { files : _.map(selected, function (file) {
return { return {
path : file.get('path'), path : file.get('path'),
folderName : file.get('folderName'),
seriesId : file.get('series').id, seriesId : file.get('series').id,
episodeIds : _.map(file.get('episodes'), 'id'), episodeIds : _.map(file.get('episodes'), 'id'),
quality : file.get('quality'), quality : file.get('quality'),