mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-18 16:29:41 +02:00
New: Add release info to webhook/custom script import events
Closes #8293
This commit is contained in:
parent
b5bf5eae26
commit
9ec1235b62
@ -1,10 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.MediaFiles.MovieImport.Specifications;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
@ -40,6 +38,7 @@ public void Setup()
|
||||
_localMovie = Builder<LocalMovie>.CreateNew()
|
||||
.With(l => l.Path = @"C:\Test\Unsorted\Series.Title.S01E01.720p.HDTV-Sonarr\S01E05.mkv".AsOsAgnostic())
|
||||
.With(l => l.Movie = _movie1)
|
||||
.With(l => l.Release = null)
|
||||
.Build();
|
||||
|
||||
_downloadClientItem = Builder<DownloadClientItem>.CreateNew().Build();
|
||||
@ -47,19 +46,8 @@ public void Setup()
|
||||
|
||||
private void GivenHistoryForMovies(params Movie[] movies)
|
||||
{
|
||||
var history = new List<MovieHistory>();
|
||||
|
||||
foreach (var movie in movies)
|
||||
{
|
||||
history.Add(Builder<MovieHistory>.CreateNew()
|
||||
.With(h => h.EventType = MovieHistoryEventType.Grabbed)
|
||||
.With(h => h.MovieId = movie.Id)
|
||||
.Build());
|
||||
}
|
||||
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||
.Returns(history);
|
||||
_localMovie.Release = new GrabbedReleaseInfo();
|
||||
_localMovie.Release.MovieIds = movies.Select(e => e.Id).ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -77,7 +65,7 @@ public void should_be_accepted_if_no_download_client_item()
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_accepted_if_no_grab_history()
|
||||
public void should_be_accepted_if_no_grab_release_info()
|
||||
{
|
||||
GivenHistoryForMovies();
|
||||
|
||||
@ -85,7 +73,7 @@ public void should_be_accepted_if_no_grab_history()
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_accepted_if_file_episode_matches_single_grab_history()
|
||||
public void should_be_accepted_if_file_episode_matches_single_grab_release_info()
|
||||
{
|
||||
GivenHistoryForMovies(_movie1);
|
||||
|
||||
@ -93,7 +81,7 @@ public void should_be_accepted_if_file_episode_matches_single_grab_history()
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_rejected_if_file_episode_does_not_match_single_grab_history()
|
||||
public void should_be_rejected_if_file_episode_does_not_match_single_grab_release_info()
|
||||
{
|
||||
GivenHistoryForMovies(_movie2);
|
||||
|
||||
|
@ -0,0 +1,52 @@
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators
|
||||
{
|
||||
public class AggregateReleaseInfo : IAggregateLocalMovie
|
||||
{
|
||||
private readonly IHistoryService _historyService;
|
||||
|
||||
public AggregateReleaseInfo(IHistoryService historyService)
|
||||
{
|
||||
_historyService = historyService;
|
||||
}
|
||||
|
||||
public LocalMovie Aggregate(LocalMovie localMovie, DownloadClientItem downloadClientItem)
|
||||
{
|
||||
if (downloadClientItem == null)
|
||||
{
|
||||
return localMovie;
|
||||
}
|
||||
|
||||
var grabbedHistories = _historyService.FindByDownloadId(downloadClientItem.DownloadId)
|
||||
.Where(h => h.EventType == MovieHistoryEventType.Grabbed)
|
||||
.ToList();
|
||||
|
||||
if (grabbedHistories.Empty())
|
||||
{
|
||||
return localMovie;
|
||||
}
|
||||
|
||||
var movieIds = grabbedHistories.Select(h => h.MovieId).Distinct().ToList();
|
||||
var grabbedHistory = grabbedHistories.First();
|
||||
var releaseInfo = new GrabbedReleaseInfo();
|
||||
|
||||
grabbedHistory.Data.TryGetValue("indexer", out var indexer);
|
||||
grabbedHistory.Data.TryGetValue("size", out var sizeString);
|
||||
long.TryParse(sizeString, out var size);
|
||||
|
||||
releaseInfo.Title = grabbedHistory.SourceTitle;
|
||||
releaseInfo.Indexer = indexer;
|
||||
releaseInfo.Size = size;
|
||||
releaseInfo.MovieIds = movieIds;
|
||||
|
||||
localMovie.Release = releaseInfo;
|
||||
|
||||
return localMovie;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,14 +12,10 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Specifications
|
||||
public class MatchesGrabSpecification : IImportDecisionEngineSpecification
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
private readonly IParsingService _parsingService;
|
||||
private readonly IHistoryService _historyService;
|
||||
|
||||
public MatchesGrabSpecification(IParsingService parsingService, IHistoryService historyService, Logger logger)
|
||||
public MatchesGrabSpecification(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_parsingService = parsingService;
|
||||
_historyService = historyService;
|
||||
}
|
||||
|
||||
public Decision IsSatisfiedBy(LocalMovie localMovie, DownloadClientItem downloadClientItem)
|
||||
@ -29,25 +25,18 @@ public Decision IsSatisfiedBy(LocalMovie localMovie, DownloadClientItem download
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
if (downloadClientItem == null)
|
||||
var releaseInfo = localMovie.Release;
|
||||
|
||||
if (releaseInfo == null || releaseInfo.MovieIds.Empty())
|
||||
{
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
var grabbedHistory = _historyService.FindByDownloadId(downloadClientItem.DownloadId)
|
||||
.Where(h => h.EventType == MovieHistoryEventType.Grabbed)
|
||||
.ToList();
|
||||
|
||||
if (grabbedHistory.Empty())
|
||||
{
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
if (grabbedHistory.All(o => o.MovieId != localMovie.Movie.Id))
|
||||
if (releaseInfo.MovieIds.All(o => o != localMovie.Movie.Id))
|
||||
{
|
||||
_logger.Debug("Unexpected movie(s) in file: {0}", localMovie.Movie.ToString());
|
||||
|
||||
return Decision.Reject("Movie {0} was not found in the grabbed release: {1}", localMovie.Movie.ToString(), grabbedHistory.First().SourceTitle);
|
||||
return Decision.Reject("Movie {0} was not found in the grabbed release: {1}", localMovie.Movie.ToString(), releaseInfo.Title);
|
||||
}
|
||||
|
||||
return Decision.Accept();
|
||||
|
@ -122,6 +122,9 @@ public override void OnDownload(DownloadMessage message)
|
||||
environmentVariables.Add("Radarr_MovieFile_MediaInfo_VideoDynamicRangeType", MediaInfoFormatter.FormatVideoDynamicRangeType(movieFile.MediaInfo));
|
||||
environmentVariables.Add("Radarr_MovieFile_CustomFormat", string.Join("|", message.MovieInfo.CustomFormats));
|
||||
environmentVariables.Add("Radarr_MovieFile_CustomFormatScore", message.MovieInfo.CustomFormatScore.ToString());
|
||||
environmentVariables.Add("Radarr_Release_Indexer", message.Release?.Indexer);
|
||||
environmentVariables.Add("Radarr_Release_Size", message.Release?.Size.ToString());
|
||||
environmentVariables.Add("Radarr_Release_Title", message.Release?.Title);
|
||||
|
||||
if (message.OldMovieFiles.Any())
|
||||
{
|
||||
|
@ -16,6 +16,7 @@ public class DownloadMessage
|
||||
public string SourcePath { get; set; }
|
||||
public DownloadClientItemClientInfo DownloadClientInfo { get; set; }
|
||||
public string DownloadId { get; set; }
|
||||
public GrabbedReleaseInfo Release { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
@ -136,7 +136,8 @@ public void Handle(MovieFileImportedEvent message)
|
||||
OldMovieFiles = message.OldFiles,
|
||||
SourcePath = message.MovieInfo.Path,
|
||||
DownloadClientInfo = message.DownloadClientInfo,
|
||||
DownloadId = message.DownloadId
|
||||
DownloadId = message.DownloadId,
|
||||
Release = message.MovieInfo.Release
|
||||
};
|
||||
|
||||
foreach (var notification in _notificationFactory.OnDownloadEnabled())
|
||||
|
@ -53,6 +53,7 @@ protected WebhookImportPayload BuildOnDownloadPayload(DownloadMessage message)
|
||||
Movie = new WebhookMovie(message.Movie),
|
||||
RemoteMovie = new WebhookRemoteMovie(message.Movie),
|
||||
MovieFile = new WebhookMovieFile(movieFile),
|
||||
Release = new WebhookGrabbedRelease(message.Release),
|
||||
IsUpgrade = message.OldMovieFiles.Any(),
|
||||
DownloadClient = message.DownloadClientInfo?.Name,
|
||||
DownloadClientType = message.DownloadClientInfo?.Type,
|
||||
|
@ -0,0 +1,27 @@
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Webhook
|
||||
{
|
||||
public class WebhookGrabbedRelease
|
||||
{
|
||||
public WebhookGrabbedRelease()
|
||||
{
|
||||
}
|
||||
|
||||
public WebhookGrabbedRelease(GrabbedReleaseInfo release)
|
||||
{
|
||||
if (release == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReleaseTitle = release.Title;
|
||||
Indexer = release.Indexer;
|
||||
Size = release.Size;
|
||||
}
|
||||
|
||||
public string ReleaseTitle { get; set; }
|
||||
public string Indexer { get; set; }
|
||||
public long Size { get; set; }
|
||||
}
|
||||
}
|
@ -13,5 +13,6 @@ public class WebhookImportPayload : WebhookPayload
|
||||
public string DownloadId { get; set; }
|
||||
public List<WebhookMovieFile> DeletedFiles { get; set; }
|
||||
public WebhookCustomFormatInfo CustomFormatInfo { get; set; }
|
||||
public WebhookGrabbedRelease Release { get; set; }
|
||||
}
|
||||
}
|
||||
|
13
src/NzbDrone.Core/Parser/Model/GrabbedReleaseInfo.cs
Normal file
13
src/NzbDrone.Core/Parser/Model/GrabbedReleaseInfo.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Parser.Model
|
||||
{
|
||||
public class GrabbedReleaseInfo
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string Indexer { get; set; }
|
||||
public long Size { get; set; }
|
||||
|
||||
public List<int> MovieIds { get; set; }
|
||||
}
|
||||
}
|
@ -31,6 +31,7 @@ public LocalMovie()
|
||||
public bool OtherVideoFiles { get; set; }
|
||||
public List<CustomFormat> CustomFormats { get; set; }
|
||||
public int CustomFormatScore { get; set; }
|
||||
public GrabbedReleaseInfo Release { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user