mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-04-25 06:47:09 -04:00
Fixed: Imports triggered through API not being marked as imported/removed from client
Fixes #3717
This commit is contained in:
parent
75be036a87
commit
0b1e99991e
2 changed files with 40 additions and 24 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
@ -17,6 +18,7 @@ namespace NzbDrone.Core.Download
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -106,6 +108,31 @@ namespace NzbDrone.Core.Download
|
||||||
var importResults = _downloadedEpisodesImportService.ProcessPath(outputPath, ImportMode.Auto,
|
var importResults = _downloadedEpisodesImportService.ProcessPath(outputPath, ImportMode.Auto,
|
||||||
trackedDownload.RemoteEpisode.Series, trackedDownload.DownloadItem);
|
trackedDownload.RemoteEpisode.Series, 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.LocalEpisode.Path), v.Errors))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
trackedDownload.Warn(statusMessages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool VerifyImport(TrackedDownload trackedDownload, List<ImportResult> importResults)
|
||||||
|
{
|
||||||
var allEpisodesImported = importResults.Where(c => c.Result == ImportResultType.Imported)
|
var allEpisodesImported = importResults.Where(c => c.Result == ImportResultType.Imported)
|
||||||
.SelectMany(c => c.ImportDecision.LocalEpisode.Episodes)
|
.SelectMany(c => c.ImportDecision.LocalEpisode.Episodes)
|
||||||
.Count() >= Math.Max(1,
|
.Count() >= Math.Max(1,
|
||||||
|
@ -115,7 +142,7 @@ namespace NzbDrone.Core.Download
|
||||||
{
|
{
|
||||||
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 episodes were imported by checking the history if at least one
|
// Double check if all episodes were imported by checking the history if at least one
|
||||||
|
@ -139,26 +166,11 @@ namespace NzbDrone.Core.Download
|
||||||
{
|
{
|
||||||
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 => new TrackedDownloadStatusMessage(Path.GetFileName(v.ImportDecision.LocalEpisode.Path), v.Errors))
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
trackedDownload.Warn(statusMessages);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ using NLog;
|
||||||
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.EpisodeImport;
|
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||||
|
@ -17,16 +18,19 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
private readonly IDownloadedEpisodesImportService _downloadedEpisodesImportService;
|
private readonly IDownloadedEpisodesImportService _downloadedEpisodesImportService;
|
||||||
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 DownloadedEpisodesCommandService(IDownloadedEpisodesImportService downloadedEpisodesImportService,
|
public DownloadedEpisodesCommandService(IDownloadedEpisodesImportService downloadedEpisodesImportService,
|
||||||
ITrackedDownloadService trackedDownloadService,
|
ITrackedDownloadService trackedDownloadService,
|
||||||
IDiskProvider diskProvider,
|
IDiskProvider diskProvider,
|
||||||
|
ICompletedDownloadService completedDownloadService,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_downloadedEpisodesImportService = downloadedEpisodesImportService;
|
_downloadedEpisodesImportService = downloadedEpisodesImportService;
|
||||||
_trackedDownloadService = trackedDownloadService;
|
_trackedDownloadService = trackedDownloadService;
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
|
_completedDownloadService = completedDownloadService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,14 +50,14 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
{
|
{
|
||||||
_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 _downloadedEpisodesImportService.ProcessPath(message.Path, message.ImportMode, trackedDownload.RemoteEpisode.Series, trackedDownload.DownloadItem);
|
var importResults = _downloadedEpisodesImportService.ProcessPath(message.Path, message.ImportMode, trackedDownload.RemoteEpisode.Series, trackedDownload.DownloadItem);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Warn("External directory scan request for unknown download {0}, attempting normal import. [{1}]", message.DownloadClientId, message.Path);
|
|
||||||
|
|
||||||
return _downloadedEpisodesImportService.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 _downloadedEpisodesImportService.ProcessPath(message.Path, message.ImportMode);
|
return _downloadedEpisodesImportService.ProcessPath(message.Path, message.ImportMode);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue