From b455708f2e07dda034314dd8498cc39cf7694da8 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 9 Jan 2024 02:07:56 +0200 Subject: [PATCH] Add release source for releases Towards #2130 --- .../PendingReleaseServiceFixture.cs | 2 +- .../DecisionEngine/DownloadDecisionMaker.cs | 28 ++++++++++++++++--- .../Download/Pending/PendingRelease.cs | 6 ++++ .../Download/Pending/PendingReleaseService.cs | 7 ++++- src/NzbDrone.Core/History/EntityHistory.cs | 1 + src/NzbDrone.Core/History/HistoryService.cs | 6 ++-- src/NzbDrone.Core/Parser/Model/RemoteBook.cs | 11 ++++++++ 7 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/Pending/PendingReleaseServiceTests/PendingReleaseServiceFixture.cs b/src/NzbDrone.Core.Test/Download/Pending/PendingReleaseServiceTests/PendingReleaseServiceFixture.cs index 5933db2e4..1b559c46e 100644 --- a/src/NzbDrone.Core.Test/Download/Pending/PendingReleaseServiceTests/PendingReleaseServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/Pending/PendingReleaseServiceTests/PendingReleaseServiceFixture.cs @@ -37,7 +37,7 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests results.Should().NotBeEmpty(); Mocker.GetMock() - .Verify(v => v.GetRssDecision(It.Is>(d => d.Count == 0)), Times.Never()); + .Verify(v => v.GetRssDecision(It.Is>(d => d.Count == 0), It.IsAny()), Times.Never()); } [Test] diff --git a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index 90b2e38f5..1dea59003 100644 --- a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -17,7 +17,7 @@ namespace NzbDrone.Core.DecisionEngine { public interface IMakeDownloadDecision { - List GetRssDecision(List reports); + List GetRssDecision(List reports, bool pushedRelease = false); List GetSearchDecision(List reports, SearchCriteriaBase searchCriteriaBase); } @@ -42,17 +42,17 @@ namespace NzbDrone.Core.DecisionEngine _logger = logger; } - public List GetRssDecision(List reports) + public List GetRssDecision(List reports, bool pushedRelease = false) { return GetBookDecisions(reports).ToList(); } public List GetSearchDecision(List reports, SearchCriteriaBase searchCriteriaBase) { - return GetBookDecisions(reports, searchCriteriaBase).ToList(); + return GetBookDecisions(reports, false, searchCriteriaBase).ToList(); } - private IEnumerable GetBookDecisions(List reports, SearchCriteriaBase searchCriteria = null) + private IEnumerable GetBookDecisions(List reports, bool pushedRelease = false, SearchCriteriaBase searchCriteria = null) { if (reports.Any()) { @@ -206,6 +206,26 @@ namespace NzbDrone.Core.DecisionEngine if (decision != null) { + var source = pushedRelease ? ReleaseSourceType.ReleasePush : ReleaseSourceType.Rss; + + if (searchCriteria != null) + { + if (searchCriteria.InteractiveSearch) + { + source = ReleaseSourceType.InteractiveSearch; + } + else if (searchCriteria.UserInvokedSearch) + { + source = ReleaseSourceType.UserInvokedSearch; + } + else + { + source = ReleaseSourceType.Search; + } + } + + decision.RemoteBook.ReleaseSource = source; + if (decision.Rejections.Any()) { _logger.Debug("Release rejected for the following reasons: {0}", string.Join(", ", decision.Rejections)); diff --git a/src/NzbDrone.Core/Download/Pending/PendingRelease.cs b/src/NzbDrone.Core/Download/Pending/PendingRelease.cs index b382d411c..6a6580342 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingRelease.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingRelease.cs @@ -12,8 +12,14 @@ namespace NzbDrone.Core.Download.Pending public ParsedBookInfo ParsedBookInfo { get; set; } public ReleaseInfo Release { get; set; } public PendingReleaseReason Reason { get; set; } + public PendingReleaseAdditionalInfo AdditionalInfo { get; set; } //Not persisted public RemoteBook RemoteBook { get; set; } } + + public class PendingReleaseAdditionalInfo + { + public ReleaseSourceType ReleaseSource { get; set; } + } } diff --git a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs index db51a324e..0c10bcf7f 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs @@ -320,6 +320,7 @@ namespace NzbDrone.Core.Download.Pending { Author = author, Books = books, + ReleaseSource = release.AdditionalInfo?.ReleaseSource ?? ReleaseSourceType.Unknown, ParsedBookInfo = release.ParsedBookInfo, Release = release.Release }; @@ -342,7 +343,11 @@ namespace NzbDrone.Core.Download.Pending Release = decision.RemoteBook.Release, Title = decision.RemoteBook.Release.Title, Added = DateTime.UtcNow, - Reason = reason + Reason = reason, + AdditionalInfo = new PendingReleaseAdditionalInfo + { + ReleaseSource = decision.RemoteBook.ReleaseSource + } }); _eventAggregator.PublishEvent(new PendingReleasesUpdatedEvent()); diff --git a/src/NzbDrone.Core/History/EntityHistory.cs b/src/NzbDrone.Core/History/EntityHistory.cs index 6bc31a860..ce50ceaef 100644 --- a/src/NzbDrone.Core/History/EntityHistory.cs +++ b/src/NzbDrone.Core/History/EntityHistory.cs @@ -9,6 +9,7 @@ namespace NzbDrone.Core.History public class EntityHistory : ModelBase { public const string DOWNLOAD_CLIENT = "downloadClient"; + public const string RELEASE_SOURCE = "releaseSource"; public EntityHistory() { diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index 5fc83ab26..0225837bd 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -162,15 +162,15 @@ namespace NzbDrone.Core.History history.Data.Add("Guid", message.Book.Release.Guid); history.Data.Add("Protocol", ((int)message.Book.Release.DownloadProtocol).ToString()); history.Data.Add("DownloadForced", (!message.Book.DownloadAllowed).ToString()); + history.Data.Add("CustomFormatScore", message.Book.CustomFormatScore.ToString()); + history.Data.Add("ReleaseSource", message.Book.ReleaseSource.ToString()); if (!message.Book.ParsedBookInfo.ReleaseHash.IsNullOrWhiteSpace()) { history.Data.Add("ReleaseHash", message.Book.ParsedBookInfo.ReleaseHash); } - var torrentRelease = message.Book.Release as TorrentInfo; - - if (torrentRelease != null) + if (message.Book.Release is TorrentInfo torrentRelease) { history.Data.Add("TorrentInfoHash", torrentRelease.InfoHash); } diff --git a/src/NzbDrone.Core/Parser/Model/RemoteBook.cs b/src/NzbDrone.Core/Parser/Model/RemoteBook.cs index b1080162e..1c2f3bb3f 100644 --- a/src/NzbDrone.Core/Parser/Model/RemoteBook.cs +++ b/src/NzbDrone.Core/Parser/Model/RemoteBook.cs @@ -17,6 +17,7 @@ namespace NzbDrone.Core.Parser.Model public TorrentSeedConfiguration SeedConfiguration { get; set; } public List CustomFormats { get; set; } public int CustomFormatScore { get; set; } + public ReleaseSourceType ReleaseSource { get; set; } public RemoteBook() { @@ -34,4 +35,14 @@ namespace NzbDrone.Core.Parser.Model return Release.Title; } } + + public enum ReleaseSourceType + { + Unknown = 0, + Rss = 1, + Search = 2, + UserInvokedSearch = 3, + InteractiveSearch = 4, + ReleasePush = 5 + } }