1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed: Imports triggered through API not being marked as imported/removed from client

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
Qstick 2020-04-30 19:40:50 -04:00
parent 73eb83c9dc
commit d36608b4fd
2 changed files with 40 additions and 32 deletions

View File

@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
@ -16,6 +17,7 @@ public interface ICompletedDownloadService
{ {
void Check(TrackedDownload trackedDownload); void Check(TrackedDownload trackedDownload);
void Import(TrackedDownload trackedDownload); void Import(TrackedDownload trackedDownload);
bool VerifyImport(TrackedDownload trackedDownload, List<ImportResult> importResults);
} }
public class CompletedDownloadService : ICompletedDownloadService public class CompletedDownloadService : ICompletedDownloadService
@ -104,6 +106,31 @@ public void Import(TrackedDownload trackedDownload)
var outputPath = trackedDownload.DownloadItem.OutputPath.FullPath; var outputPath = trackedDownload.DownloadItem.OutputPath.FullPath;
var importResults = _downloadedMovieImportService.ProcessPath(outputPath, ImportMode.Auto, trackedDownload.RemoteMovie.Movie, trackedDownload.DownloadItem); 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) var allMoviesImported = importResults.Where(c => c.Result == ImportResultType.Imported)
.Select(c => c.ImportDecision.LocalMovie.Movie) .Select(c => c.ImportDecision.LocalMovie.Movie)
.Any(); .Any();
@ -112,7 +139,7 @@ public void Import(TrackedDownload trackedDownload)
{ {
trackedDownload.State = TrackedDownloadState.Imported; trackedDownload.State = TrackedDownloadState.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
return; return true;
} }
// Double check if all movies were imported by checking the history if at least one // Double check if all movies were imported by checking the history if at least one
@ -130,34 +157,11 @@ public void Import(TrackedDownload trackedDownload)
{ {
trackedDownload.State = TrackedDownloadState.Imported; trackedDownload.State = TrackedDownloadState.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
return; return true;
} }
} }
trackedDownload.State = TrackedDownloadState.ImportPending; return false;
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);
}
} }
} }
} }

View File

@ -5,6 +5,7 @@
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.TrackedDownloads; using NzbDrone.Core.Download.TrackedDownloads;
using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.MediaFiles.MovieImport; using NzbDrone.Core.MediaFiles.MovieImport;
@ -17,16 +18,19 @@ public class DownloadedMovieCommandService : IExecute<DownloadedMoviesScanComman
private readonly IDownloadedMovieImportService _downloadedMovieImportService; private readonly IDownloadedMovieImportService _downloadedMovieImportService;
private readonly ITrackedDownloadService _trackedDownloadService; private readonly ITrackedDownloadService _trackedDownloadService;
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
private readonly ICompletedDownloadService _completedDownloadService;
private readonly Logger _logger; private readonly Logger _logger;
public DownloadedMovieCommandService(IDownloadedMovieImportService downloadedMovieImportService, public DownloadedMovieCommandService(IDownloadedMovieImportService downloadedMovieImportService,
ITrackedDownloadService trackedDownloadService, ITrackedDownloadService trackedDownloadService,
IDiskProvider diskProvider, IDiskProvider diskProvider,
ICompletedDownloadService completedDownloadService,
Logger logger) Logger logger)
{ {
_downloadedMovieImportService = downloadedMovieImportService; _downloadedMovieImportService = downloadedMovieImportService;
_trackedDownloadService = trackedDownloadService; _trackedDownloadService = trackedDownloadService;
_diskProvider = diskProvider; _diskProvider = diskProvider;
_completedDownloadService = completedDownloadService;
_logger = logger; _logger = logger;
} }
@ -46,14 +50,14 @@ private List<ImportResult> ProcessPath(DownloadedMoviesScanCommand message)
{ {
_logger.Debug("External directory scan request for known download {0}. [{1}]", message.DownloadClientId, message.Path); _logger.Debug("External directory scan request for known download {0}. [{1}]", message.DownloadClientId, message.Path);
return _downloadedMovieImportService.ProcessPath(message.Path, message.ImportMode, trackedDownload.RemoteMovie.Movie, trackedDownload.DownloadItem); var importResults = _downloadedMovieImportService.ProcessPath(message.Path, message.ImportMode, trackedDownload.RemoteMovie.Movie, trackedDownload.DownloadItem);
}
else
{
_logger.Warn("External directory scan request for unknown download {0}, attempting normal import. [{1}]", message.DownloadClientId, message.Path);
return _downloadedMovieImportService.ProcessPath(message.Path, message.ImportMode); _completedDownloadService.VerifyImport(trackedDownload, importResults);
return importResults;
} }
_logger.Warn("External directory scan request for unknown download {0}, attempting normal import. [{1}]", message.DownloadClientId, message.Path);
} }
return _downloadedMovieImportService.ProcessPath(message.Path, message.ImportMode); return _downloadedMovieImportService.ProcessPath(message.Path, message.ImportMode);