|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
@ -16,6 +17,7 @@ namespace NzbDrone.Core.Download
|
|
|
|
|
{
|
|
|
|
|
void Check(TrackedDownload trackedDownload);
|
|
|
|
|
void Import(TrackedDownload trackedDownload);
|
|
|
|
|
bool VerifyImport(TrackedDownload trackedDownload, List<ImportResult> importResults);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CompletedDownloadService : ICompletedDownloadService
|
|
|
|
@ -104,6 +106,31 @@ namespace NzbDrone.Core.Download
|
|
|
|
|
var outputPath = trackedDownload.DownloadItem.OutputPath.FullPath;
|
|
|
|
|
var importResults = _downloadedMovieImportService.ProcessPath(outputPath, ImportMode.Auto, trackedDownload.RemoteMovie.Movie, trackedDownload.DownloadItem);
|
|
|
|
|
|
|
|
|
|
if (VerifyImport(trackedDownload, importResults))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trackedDownload.State = TrackedDownloadState.ImportPending;
|
|
|
|
|
|
|
|
|
|
if (importResults.Empty())
|
|
|
|
|
{
|
|
|
|
|
trackedDownload.Warn("No files found are eligible for import in {0}", outputPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (importResults.Any(c => c.Result != ImportResultType.Imported))
|
|
|
|
|
{
|
|
|
|
|
var statusMessages = importResults
|
|
|
|
|
.Where(v => v.Result != ImportResultType.Imported)
|
|
|
|
|
.Select(v => new TrackedDownloadStatusMessage(Path.GetFileName(v.ImportDecision.LocalMovie.Path), v.Errors))
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
trackedDownload.Warn(statusMessages);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool VerifyImport(TrackedDownload trackedDownload, List<ImportResult> importResults)
|
|
|
|
|
{
|
|
|
|
|
var allMoviesImported = importResults.Where(c => c.Result == ImportResultType.Imported)
|
|
|
|
|
.Select(c => c.ImportDecision.LocalMovie.Movie)
|
|
|
|
|
.Any();
|
|
|
|
@ -112,7 +139,7 @@ namespace NzbDrone.Core.Download
|
|
|
|
|
{
|
|
|
|
|
trackedDownload.State = TrackedDownloadState.Imported;
|
|
|
|
|
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
|
|
|
|
|
return;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Double check if all movies were imported by checking the history if at least one
|
|
|
|
@ -130,34 +157,11 @@ namespace NzbDrone.Core.Download
|
|
|
|
|
{
|
|
|
|
|
trackedDownload.State = TrackedDownloadState.Imported;
|
|
|
|
|
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
|
|
|
|
|
return;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trackedDownload.State = TrackedDownloadState.ImportPending;
|
|
|
|
|
|
|
|
|
|
if (importResults.Empty())
|
|
|
|
|
{
|
|
|
|
|
trackedDownload.Warn("No files found are eligible for import in {0}", outputPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (importResults.Any(c => c.Result != ImportResultType.Imported))
|
|
|
|
|
{
|
|
|
|
|
var statusMessages = importResults
|
|
|
|
|
.Where(v => v.Result != ImportResultType.Imported)
|
|
|
|
|
.Select(v =>
|
|
|
|
|
{
|
|
|
|
|
if (v.ImportDecision.LocalMovie == null)
|
|
|
|
|
{
|
|
|
|
|
return new TrackedDownloadStatusMessage("", v.Errors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new TrackedDownloadStatusMessage(Path.GetFileName(v.ImportDecision.LocalMovie.Path), v.Errors);
|
|
|
|
|
})
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
trackedDownload.Warn(statusMessages);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|