1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-20 18:02:44 +01:00

Fixed: Download Client not sending on Import or Upgrade notifications (#6908)

* Fixed: Download client and ID for custom scripts

Based on Sonarr Commit eea3419849

* fixup! test

Co-authored-by: Qstick <qstick@gmail.com>
This commit is contained in:
Robin Dadswell 2022-01-07 04:04:10 +00:00 committed by GitHub
parent 3a48f07702
commit a33b861cec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 61 deletions

View File

@ -176,7 +176,7 @@ public void should_return_docker_path_mapping_error_if_on_docker_and_root_missin
public void should_return_ok_on_movie_imported_event()
{
GivenFolderExists(_downloadRootPath);
var importEvent = new MovieImportedEvent(new LocalMovie(), new MovieFile(), true, new DownloadClientItem(), _downloadItem.DownloadId);
var importEvent = new MovieImportedEvent(new LocalMovie(), new MovieFile(), new List<MovieFile>(), true, new DownloadClientItem());
Subject.Check(importEvent).ShouldBeOk();
}

View File

@ -91,7 +91,7 @@ public void should_use_file_name_for_source_title_if_scene_name_is_null()
DownloadId = "abcd"
};
Subject.Handle(new MovieImportedEvent(localMovie, movieFile, true, downloadClientItem, "abcd"));
Subject.Handle(new MovieImportedEvent(localMovie, movieFile, new List<MovieFile>(), true, downloadClientItem));
Mocker.GetMock<IHistoryRepository>()
.Verify(v => v.Insert(It.Is<MovieHistory>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localMovie.Path))));

View File

@ -1,26 +0,0 @@
using System.Collections.Generic;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.Events
{
public class MovieDownloadedEvent : IEvent
{
public LocalMovie Movie { get; private set; }
public MovieFile MovieFile { get; private set; }
public List<MovieFile> OldFiles { get; private set; }
public string DownloadId { get; private set; }
public MovieDownloadedEvent(LocalMovie movie, MovieFile movieFile, List<MovieFile> oldFiles, DownloadClientItem downloadClientItem)
{
Movie = movie;
MovieFile = movieFile;
OldFiles = oldFiles;
if (downloadClientItem != null)
{
DownloadId = downloadClientItem.DownloadId;
}
}
}
}

View File

@ -1,3 +1,4 @@
using System.Collections.Generic;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model;
@ -8,24 +9,22 @@ public class MovieImportedEvent : IEvent
{
public LocalMovie MovieInfo { get; private set; }
public MovieFile ImportedMovie { get; private set; }
public List<MovieFile> OldFiles { get; private set; }
public bool NewDownload { get; private set; }
public DownloadClientItemClientInfo DownloadClientInfo { get; set; }
public string DownloadId { get; private set; }
public MovieImportedEvent(LocalMovie movieInfo, MovieFile importedMovie, bool newDownload)
public MovieImportedEvent(LocalMovie movieInfo, MovieFile importedMovie, List<MovieFile> oldFiles, bool newDownload, DownloadClientItem downloadClientItem)
{
MovieInfo = movieInfo;
ImportedMovie = importedMovie;
OldFiles = oldFiles;
NewDownload = newDownload;
}
public MovieImportedEvent(LocalMovie movieInfo, MovieFile importedMovie, bool newDownload, DownloadClientItem downloadClientItem, string downloadId)
if (downloadClientItem != null)
{
MovieInfo = movieInfo;
ImportedMovie = importedMovie;
NewDownload = newDownload;
DownloadClientInfo = downloadClientItem.DownloadClientInfo;
DownloadId = downloadId;
DownloadId = downloadClientItem.DownloadId;
}
}
}
}

View File

@ -144,19 +144,7 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
_extraService.ImportMovie(localMovie, movieFile, copyOnly);
}
if (downloadClientItem != null)
{
_eventAggregator.PublishEvent(new MovieImportedEvent(localMovie, movieFile, newDownload, downloadClientItem, downloadClientItem.DownloadId));
}
else
{
_eventAggregator.PublishEvent(new MovieImportedEvent(localMovie, movieFile, newDownload));
}
if (newDownload)
{
_eventAggregator.PublishEvent(new MovieDownloadedEvent(localMovie, movieFile, oldFiles, downloadClientItem));
}
_eventAggregator.PublishEvent(new MovieImportedEvent(localMovie, movieFile, oldFiles, newDownload, downloadClientItem));
}
catch (RootFolderNotFoundException e)
{

View File

@ -17,7 +17,7 @@ namespace NzbDrone.Core.Notifications
public class NotificationService
: IHandle<MovieRenamedEvent>,
IHandle<MovieGrabbedEvent>,
IHandle<MovieDownloadedEvent>,
IHandle<MovieImportedEvent>,
IHandle<MoviesDeletedEvent>,
IHandle<MovieFileDeletedEvent>,
IHandle<HealthCheckFailedEvent>,
@ -117,21 +117,29 @@ public void Handle(MovieGrabbedEvent message)
}
}
public void Handle(MovieDownloadedEvent message)
public void Handle(MovieImportedEvent message)
{
var downloadMessage = new DownloadMessage();
downloadMessage.Message = GetMessage(message.Movie.Movie, message.Movie.Quality);
downloadMessage.MovieFile = message.MovieFile;
downloadMessage.Movie = message.Movie.Movie;
downloadMessage.OldMovieFiles = message.OldFiles;
downloadMessage.SourcePath = message.Movie.Path;
downloadMessage.DownloadId = message.DownloadId;
if (!message.NewDownload)
{
return;
}
var downloadMessage = new DownloadMessage
{
Message = GetMessage(message.MovieInfo.Movie, message.MovieInfo.Quality),
MovieFile = message.ImportedMovie,
Movie = message.MovieInfo.Movie,
OldMovieFiles = message.OldFiles,
SourcePath = message.MovieInfo.Path,
DownloadClient = message.DownloadClientInfo?.Name,
DownloadId = message.DownloadId
};
foreach (var notification in _notificationFactory.OnDownloadEnabled())
{
try
{
if (ShouldHandleMovie(notification.Definition, message.Movie.Movie))
if (ShouldHandleMovie(notification.Definition, message.MovieInfo.Movie))
{
if (downloadMessage.OldMovieFiles.Empty() || ((NotificationDefinition)notification.Definition).OnUpgrade)
{