|
|
@ -3,9 +3,10 @@ using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
using NLog.Fluent;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Core.Books;
|
|
|
|
using NzbDrone.Common.Instrumentation.Extensions;
|
|
|
|
using NzbDrone.Core.Download.TrackedDownloads;
|
|
|
|
using NzbDrone.Core.Download.TrackedDownloads;
|
|
|
|
using NzbDrone.Core.History;
|
|
|
|
using NzbDrone.Core.History;
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
@ -27,7 +28,6 @@ namespace NzbDrone.Core.Download
|
|
|
|
private readonly IEventAggregator _eventAggregator;
|
|
|
|
private readonly IEventAggregator _eventAggregator;
|
|
|
|
private readonly IHistoryService _historyService;
|
|
|
|
private readonly IHistoryService _historyService;
|
|
|
|
private readonly IDownloadedBooksImportService _downloadedTracksImportService;
|
|
|
|
private readonly IDownloadedBooksImportService _downloadedTracksImportService;
|
|
|
|
private readonly IAuthorService _authorService;
|
|
|
|
|
|
|
|
private readonly IProvideImportItemService _importItemService;
|
|
|
|
private readonly IProvideImportItemService _importItemService;
|
|
|
|
private readonly ITrackedDownloadAlreadyImported _trackedDownloadAlreadyImported;
|
|
|
|
private readonly ITrackedDownloadAlreadyImported _trackedDownloadAlreadyImported;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly Logger _logger;
|
|
|
@ -36,7 +36,6 @@ namespace NzbDrone.Core.Download
|
|
|
|
IHistoryService historyService,
|
|
|
|
IHistoryService historyService,
|
|
|
|
IProvideImportItemService importItemService,
|
|
|
|
IProvideImportItemService importItemService,
|
|
|
|
IDownloadedBooksImportService downloadedTracksImportService,
|
|
|
|
IDownloadedBooksImportService downloadedTracksImportService,
|
|
|
|
IAuthorService authorService,
|
|
|
|
|
|
|
|
ITrackedDownloadAlreadyImported trackedDownloadAlreadyImported,
|
|
|
|
ITrackedDownloadAlreadyImported trackedDownloadAlreadyImported,
|
|
|
|
Logger logger)
|
|
|
|
Logger logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -44,7 +43,6 @@ namespace NzbDrone.Core.Download
|
|
|
|
_historyService = historyService;
|
|
|
|
_historyService = historyService;
|
|
|
|
_importItemService = importItemService;
|
|
|
|
_importItemService = importItemService;
|
|
|
|
_downloadedTracksImportService = downloadedTracksImportService;
|
|
|
|
_downloadedTracksImportService = downloadedTracksImportService;
|
|
|
|
_authorService = authorService;
|
|
|
|
|
|
|
|
_trackedDownloadAlreadyImported = trackedDownloadAlreadyImported;
|
|
|
|
_trackedDownloadAlreadyImported = trackedDownloadAlreadyImported;
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -151,8 +149,8 @@ namespace NzbDrone.Core.Download
|
|
|
|
// and an episode is removed, but later comes back with a different ID then Sonarr will treat it as incomplete.
|
|
|
|
// and an episode is removed, but later comes back with a different ID then Sonarr will treat it as incomplete.
|
|
|
|
// Since imports should be relatively fast and these types of data changes are infrequent this should be quite
|
|
|
|
// Since imports should be relatively fast and these types of data changes are infrequent this should be quite
|
|
|
|
// safe, but commenting for future benefit.
|
|
|
|
// safe, but commenting for future benefit.
|
|
|
|
if (importResults.Any(c => c.Result == ImportResultType.Imported))
|
|
|
|
var atLeastOneEpisodeImported = importResults.Any(c => c.Result == ImportResultType.Imported);
|
|
|
|
{
|
|
|
|
|
|
|
|
var historyItems = _historyService.FindByDownloadId(trackedDownload.DownloadItem.DownloadId)
|
|
|
|
var historyItems = _historyService.FindByDownloadId(trackedDownload.DownloadItem.DownloadId)
|
|
|
|
.OrderByDescending(h => h.Date)
|
|
|
|
.OrderByDescending(h => h.Date)
|
|
|
|
.ToList();
|
|
|
|
.ToList();
|
|
|
@ -160,6 +158,8 @@ namespace NzbDrone.Core.Download
|
|
|
|
var allEpisodesImportedInHistory = _trackedDownloadAlreadyImported.IsImported(trackedDownload, historyItems);
|
|
|
|
var allEpisodesImportedInHistory = _trackedDownloadAlreadyImported.IsImported(trackedDownload, historyItems);
|
|
|
|
|
|
|
|
|
|
|
|
if (allEpisodesImportedInHistory)
|
|
|
|
if (allEpisodesImportedInHistory)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (atLeastOneEpisodeImported)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Debug("All books were imported in history for {0}", trackedDownload.DownloadItem.Title);
|
|
|
|
_logger.Debug("All books were imported in history for {0}", trackedDownload.DownloadItem.Title);
|
|
|
|
trackedDownload.State = TrackedDownloadState.Imported;
|
|
|
|
trackedDownload.State = TrackedDownloadState.Imported;
|
|
|
@ -168,8 +168,18 @@ namespace NzbDrone.Core.Download
|
|
|
|
.Select(x => x.AuthorId)
|
|
|
|
.Select(x => x.AuthorId)
|
|
|
|
.MostCommon();
|
|
|
|
.MostCommon();
|
|
|
|
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteBook?.Author.Id ?? importedAuthorId));
|
|
|
|
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteBook?.Author.Id ?? importedAuthorId));
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.Debug()
|
|
|
|
|
|
|
|
.Message("No Episodes were just imported, but all episodes were previously imported, possible issue with download history.")
|
|
|
|
|
|
|
|
.Property("AuthorId", trackedDownload.RemoteBook.Author.Id)
|
|
|
|
|
|
|
|
.Property("DownloadId", trackedDownload.DownloadItem.DownloadId)
|
|
|
|
|
|
|
|
.Property("Title", trackedDownload.DownloadItem.Title)
|
|
|
|
|
|
|
|
.Property("Path", trackedDownload.DownloadItem.OutputPath.ToString())
|
|
|
|
|
|
|
|
.WriteSentryWarn("DownloadHistoryIncomplete")
|
|
|
|
|
|
|
|
.Write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Not all books have been imported for {0}", trackedDownload.DownloadItem.Title);
|
|
|
|
_logger.Debug("Not all books have been imported for {0}", trackedDownload.DownloadItem.Title);
|
|
|
|