mirror of
https://github.com/Readarr/Readarr
synced 2026-01-17 13:03:38 +01:00
Fixed: Manual import for unknown series items will properly mark as imported
Fixes: #277 (cherry picked from commit 3ffcf114682f9b1730f54706ecbf1bf237206bb1)
This commit is contained in:
parent
842f80d567
commit
95d93dfa09
6 changed files with 39 additions and 15 deletions
|
|
@ -23,6 +23,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
|
|||
public class ImportFixture : CoreTest<CompletedDownloadService>
|
||||
{
|
||||
private TrackedDownload _trackedDownload;
|
||||
private Author _author;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
|
|
@ -42,6 +43,9 @@ public void Setup()
|
|||
.With(c => c.RemoteBook = remoteBook)
|
||||
.Build();
|
||||
|
||||
_author = Builder<Author>.CreateNew()
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IDownloadClient>()
|
||||
.SetupGet(c => c.Definition)
|
||||
.Returns(new DownloadClientDefinition { Id = 1, Name = "testClient" });
|
||||
|
|
@ -190,8 +194,8 @@ public void should_mark_as_imported_if_all_tracks_were_imported_but_extra_files_
|
|||
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Author>(), It.IsAny<DownloadClientItem>()))
|
||||
.Returns(new List<ImportResult>
|
||||
{
|
||||
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic() })),
|
||||
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic() }), "Test Failure")
|
||||
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic(), Author = _author })),
|
||||
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic(), Author = _author }), "Test Failure")
|
||||
});
|
||||
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
|
|
@ -286,11 +290,11 @@ public void should_mark_as_imported_if_all_tracks_were_imported()
|
|||
{
|
||||
new ImportResult(
|
||||
new ImportDecision<LocalBook>(
|
||||
new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic() })),
|
||||
new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic(), Author = _author })),
|
||||
|
||||
new ImportResult(
|
||||
new ImportDecision<LocalBook>(
|
||||
new LocalBook { Path = @"C:\TestPath\Droned.S01E02.mkv".AsOsAgnostic() }))
|
||||
new LocalBook { Path = @"C:\TestPath\Droned.S01E02.mkv".AsOsAgnostic(), Author = _author }))
|
||||
});
|
||||
|
||||
Subject.Import(_trackedDownload);
|
||||
|
|
@ -311,15 +315,18 @@ public void should_mark_as_imported_if_all_episodes_were_imported_including_hist
|
|||
{
|
||||
new ImportResult(
|
||||
new ImportDecision<LocalBook>(
|
||||
new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv", Book = books[0] })),
|
||||
new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv", Book = books[0], Author = _author })),
|
||||
|
||||
new ImportResult(
|
||||
new ImportDecision<LocalBook>(
|
||||
new LocalBook { Path = @"C:\TestPath\Droned.S01E02.mkv", Book = books[1] }), "Test Failure")
|
||||
new LocalBook { Path = @"C:\TestPath\Droned.S01E02.mkv", Book = books[1], Author = _author }), "Test Failure")
|
||||
});
|
||||
|
||||
var history = Builder<EntityHistory>.CreateListOfSize(2)
|
||||
.BuildList();
|
||||
.All()
|
||||
.With(x => x.EventType = EntityHistoryEventType.BookFileImported)
|
||||
.With(x => x.AuthorId = 1)
|
||||
.BuildList();
|
||||
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||
|
|
@ -343,7 +350,7 @@ public void should_mark_as_imported_if_the_download_can_be_tracked_using_the_sou
|
|||
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Author>(), It.IsAny<DownloadClientItem>()))
|
||||
.Returns(new List<ImportResult>
|
||||
{
|
||||
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic() }))
|
||||
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic(), Author = _author }))
|
||||
});
|
||||
|
||||
Subject.Import(_trackedDownload);
|
||||
|
|
|
|||
|
|
@ -130,7 +130,11 @@ public bool VerifyImport(TrackedDownload trackedDownload, List<ImportResult> imp
|
|||
if (allItemsImported)
|
||||
{
|
||||
trackedDownload.State = TrackedDownloadState.Imported;
|
||||
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
|
||||
|
||||
var importedAuthorId = importResults.Where(x => x.Result == ImportResultType.Imported)
|
||||
.Select(c => c.ImportDecision.Item.Author.Id)
|
||||
.MostCommon();
|
||||
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteBook?.Author.Id ?? importedAuthorId));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +157,11 @@ public bool VerifyImport(TrackedDownload trackedDownload, List<ImportResult> imp
|
|||
if (allEpisodesImportedInHistory)
|
||||
{
|
||||
trackedDownload.State = TrackedDownloadState.Imported;
|
||||
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
|
||||
|
||||
var importedAuthorId = historyItems.Where(x => x.EventType == EntityHistoryEventType.BookFileImported)
|
||||
.Select(x => x.AuthorId)
|
||||
.MostCommon();
|
||||
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteBook?.Author.Id ?? importedAuthorId));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Download.TrackedDownloads;
|
||||
|
||||
namespace NzbDrone.Core.Download
|
||||
|
|
@ -6,10 +6,12 @@ namespace NzbDrone.Core.Download
|
|||
public class DownloadCompletedEvent : IEvent
|
||||
{
|
||||
public TrackedDownload TrackedDownload { get; private set; }
|
||||
public int AuthorId { get; set; }
|
||||
|
||||
public DownloadCompletedEvent(TrackedDownload trackedDownload)
|
||||
public DownloadCompletedEvent(TrackedDownload trackedDownload, int authorId)
|
||||
{
|
||||
TrackedDownload = trackedDownload;
|
||||
AuthorId = authorId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ private void RemoveCompletedDownloads()
|
|||
|
||||
foreach (var trackedDownload in trackedDownloads)
|
||||
{
|
||||
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
|
||||
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload,
|
||||
trackedDownload.RemoteBook.Author.Id));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,6 +93,12 @@ public DownloadHistory GetLatestDownloadHistoryItem(string downloadId)
|
|||
|
||||
public void Handle(BookGrabbedEvent message)
|
||||
{
|
||||
// Don't store grabbed events for clients that don't download IDs
|
||||
if (message.DownloadId.IsNullOrWhiteSpace())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var history = new DownloadHistory
|
||||
{
|
||||
EventType = DownloadHistoryEventType.DownloadGrabbed,
|
||||
|
|
@ -179,7 +185,7 @@ public void Handle(DownloadCompletedEvent message)
|
|||
var history = new DownloadHistory
|
||||
{
|
||||
EventType = DownloadHistoryEventType.DownloadImported,
|
||||
AuthorId = message.TrackedDownload.RemoteBook.Author.Id,
|
||||
AuthorId = message.AuthorId,
|
||||
DownloadId = message.TrackedDownload.DownloadItem.DownloadId,
|
||||
SourceTitle = message.TrackedDownload.DownloadItem.OutputPath.ToString(),
|
||||
Date = DateTime.UtcNow,
|
||||
|
|
|
|||
|
|
@ -389,7 +389,7 @@ public void Execute(ManualImportCommand message)
|
|||
if (allItemsImported)
|
||||
{
|
||||
trackedDownload.State = TrackedDownloadState.Imported;
|
||||
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
|
||||
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, imported.First().ImportDecision.Item.Author.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue