New: Include renamed file information for Webhook and Custom Scripts

Closes #3927

(cherry picked from commit 3c45349404f59064d1c8db0549401189c456e4c0)
pull/6566/head
Mark McDowall 4 years ago committed by Qstick
parent 425772da1c
commit 94b481a66f

@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic;
using FluentAssertions; using FluentAssertions;
using FluentValidation.Results; using FluentValidation.Results;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
using NzbDrone.Core.Notifications; using NzbDrone.Core.Notifications;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
@ -57,7 +59,7 @@ namespace NzbDrone.Core.Test.NotificationTests
TestLogger.Info("OnDownload was called"); TestLogger.Info("OnDownload was called");
} }
public override void OnMovieRename(Movie movie) public override void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles)
{ {
TestLogger.Info("OnRename was called"); TestLogger.Info("OnRename was called");
} }

@ -60,7 +60,7 @@ namespace NzbDrone.Core.Test.NotificationTests
{ {
(Subject.Definition.Settings as SynologyIndexerSettings).UpdateLibrary = false; (Subject.Definition.Settings as SynologyIndexerSettings).UpdateLibrary = false;
Subject.OnMovieRename(_movie); Subject.OnMovieRename(_movie, new List<RenamedMovieFile>());
Mocker.GetMock<ISynologyIndexerProxy>() Mocker.GetMock<ISynologyIndexerProxy>()
.Verify(v => v.UpdateFolder(_movie.Path), Times.Never()); .Verify(v => v.UpdateFolder(_movie.Path), Times.Never());
@ -90,7 +90,7 @@ namespace NzbDrone.Core.Test.NotificationTests
[Test] [Test]
public void should_update_entire_movie_folder_on_rename() public void should_update_entire_movie_folder_on_rename()
{ {
Subject.OnMovieRename(_movie); Subject.OnMovieRename(_movie, new List<RenamedMovieFile>());
Mocker.GetMock<ISynologyIndexerProxy>() Mocker.GetMock<ISynologyIndexerProxy>()
.Verify(v => v.UpdateFolder(@"C:\Test\".AsOsAgnostic()), Times.Once()); .Verify(v => v.UpdateFolder(@"C:\Test\".AsOsAgnostic()), Times.Once());

@ -1,4 +1,5 @@
using NzbDrone.Common.Messaging; using System.Collections.Generic;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
namespace NzbDrone.Core.MediaFiles.Events namespace NzbDrone.Core.MediaFiles.Events
@ -6,10 +7,12 @@ namespace NzbDrone.Core.MediaFiles.Events
public class MovieRenamedEvent : IEvent public class MovieRenamedEvent : IEvent
{ {
public Movie Movie { get; private set; } public Movie Movie { get; private set; }
public List<RenamedMovieFile> RenamedFiles { get; private set; }
public MovieRenamedEvent(Movie movie) public MovieRenamedEvent(Movie movie, List<RenamedMovieFile> renamedFiles)
{ {
Movie = movie; Movie = movie;
RenamedFiles = renamedFiles;
} }
} }
} }

@ -80,13 +80,14 @@ namespace NzbDrone.Core.MediaFiles
} }
} }
private void RenameFiles(List<MovieFile> movieFiles, Movie movie) private List<RenamedMovieFile> RenameFiles(List<MovieFile> movieFiles, Movie movie)
{ {
var renamed = new List<MovieFile>(); var renamed = new List<RenamedMovieFile>();
foreach (var movieFile in movieFiles) foreach (var movieFile in movieFiles)
{ {
var movieFilePath = Path.Combine(movie.Path, movieFile.RelativePath); var previousRelativePath = movieFile.RelativePath;
var previousPath = Path.Combine(movie.Path, movieFile.RelativePath);
try try
{ {
@ -95,11 +96,16 @@ namespace NzbDrone.Core.MediaFiles
_mediaFileService.Update(movieFile); _mediaFileService.Update(movieFile);
_movieService.UpdateMovie(movie); _movieService.UpdateMovie(movie);
renamed.Add(movieFile); renamed.Add(new RenamedMovieFile
{
MovieFile = movieFile,
PreviousRelativePath = previousRelativePath,
PreviousPath = previousPath
});
_logger.Debug("Renamed movie file: {0}", movieFile); _logger.Debug("Renamed movie file: {0}", movieFile);
_eventAggregator.PublishEvent(new MovieFileRenamedEvent(movie, movieFile, movieFilePath)); _eventAggregator.PublishEvent(new MovieFileRenamedEvent(movie, movieFile, previousPath));
} }
catch (SameFilenameException ex) catch (SameFilenameException ex)
{ {
@ -107,7 +113,7 @@ namespace NzbDrone.Core.MediaFiles
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.Error(ex, "Failed to rename file: {0}", movieFilePath); _logger.Error(ex, "Failed to rename file: {0}", previousPath);
} }
} }
@ -115,8 +121,10 @@ namespace NzbDrone.Core.MediaFiles
{ {
_diskProvider.RemoveEmptySubfolders(movie.Path); _diskProvider.RemoveEmptySubfolders(movie.Path);
_eventAggregator.PublishEvent(new MovieRenamedEvent(movie)); _eventAggregator.PublishEvent(new MovieRenamedEvent(movie, renamed));
} }
return renamed;
} }
public void Execute(RenameFilesCommand message) public void Execute(RenameFilesCommand message)

@ -0,0 +1,9 @@
namespace NzbDrone.Core.MediaFiles
{
public class RenamedMovieFile
{
public MovieFile MovieFile { get; set; }
public string PreviousPath { get; set; }
public string PreviousRelativePath { get; set; }
}
}

@ -9,6 +9,7 @@ using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
using NzbDrone.Core.HealthCheck; using NzbDrone.Core.HealthCheck;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
@ -100,7 +101,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
ExecuteScript(environmentVariables); ExecuteScript(environmentVariables);
} }
public override void OnMovieRename(Movie movie) public override void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles)
{ {
var environmentVariables = new StringDictionary(); var environmentVariables = new StringDictionary();
@ -113,6 +114,11 @@ namespace NzbDrone.Core.Notifications.CustomScript
environmentVariables.Add("Radarr_Movie_TmdbId", movie.TmdbId.ToString()); environmentVariables.Add("Radarr_Movie_TmdbId", movie.TmdbId.ToString());
environmentVariables.Add("Radarr_Movie_In_Cinemas_Date", movie.InCinemas.ToString() ?? string.Empty); environmentVariables.Add("Radarr_Movie_In_Cinemas_Date", movie.InCinemas.ToString() ?? string.Empty);
environmentVariables.Add("Radarr_Movie_Physical_Release_Date", movie.PhysicalRelease.ToString() ?? string.Empty); environmentVariables.Add("Radarr_Movie_Physical_Release_Date", movie.PhysicalRelease.ToString() ?? string.Empty);
environmentVariables.Add("Radarr_MovieFile_Ids", string.Join(",", renamedFiles.Select(e => e.MovieFile.Id)));
environmentVariables.Add("Radarr_MovieFile_RelativePaths", string.Join("|", renamedFiles.Select(e => e.MovieFile.RelativePath)));
environmentVariables.Add("Radarr_MovieFile_Paths", string.Join("|", renamedFiles.Select(e => e.MovieFile.Path)));
environmentVariables.Add("Radarr_MovieFile_PreviousRelativePaths", string.Join("|", renamedFiles.Select(e => e.PreviousRelativePath)));
environmentVariables.Add("Radarr_MovieFile_PreviousPaths", string.Join("|", renamedFiles.Select(e => e.PreviousPath)));
ExecuteScript(environmentVariables); ExecuteScript(environmentVariables);
} }

@ -5,6 +5,7 @@ using System.Linq;
using FluentValidation.Results; using FluentValidation.Results;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.MediaInfo; using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
using NzbDrone.Core.Notifications.Discord.Payloads; using NzbDrone.Core.Notifications.Discord.Payloads;
@ -213,6 +214,21 @@ namespace NzbDrone.Core.Notifications.Discord
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }
public override void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles)
{
var attachments = new List<Embed>
{
new Embed
{
Title = movie.Title,
}
};
var payload = CreatePayload("Renamed", attachments);
_proxy.SendPayload(payload, Settings);
}
public override void OnMovieDelete(MovieDeleteMessage deleteMessage) public override void OnMovieDelete(MovieDeleteMessage deleteMessage)
{ {
var movie = deleteMessage.Movie; var movie = deleteMessage.Movie;

@ -1,3 +1,5 @@
using System.Collections.Generic;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
@ -9,7 +11,7 @@ namespace NzbDrone.Core.Notifications
void OnGrab(GrabMessage grabMessage); void OnGrab(GrabMessage grabMessage);
void OnDownload(DownloadMessage message); void OnDownload(DownloadMessage message);
void OnMovieRename(Movie movie); void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles);
void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage); void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage);
void OnMovieDelete(MovieDeleteMessage deleteMessage); void OnMovieDelete(MovieDeleteMessage deleteMessage);
void OnHealthIssue(HealthCheck.HealthCheck healthCheck); void OnHealthIssue(HealthCheck.HealthCheck healthCheck);

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using FluentValidation.Results; using FluentValidation.Results;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
namespace NzbDrone.Core.Notifications.Emby namespace NzbDrone.Core.Notifications.Emby
@ -38,7 +39,7 @@ namespace NzbDrone.Core.Notifications.Emby
} }
} }
public override void OnMovieRename(Movie movie) public override void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles)
{ {
if (Settings.UpdateLibrary) if (Settings.UpdateLibrary)
{ {

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FluentValidation.Results; using FluentValidation.Results;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
@ -44,7 +45,7 @@ namespace NzbDrone.Core.Notifications
{ {
} }
public virtual void OnMovieRename(Movie movie) public virtual void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles)
{ {
} }

@ -152,7 +152,7 @@ namespace NzbDrone.Core.Notifications
{ {
if (ShouldHandleMovie(notification.Definition, message.Movie)) if (ShouldHandleMovie(notification.Definition, message.Movie))
{ {
notification.OnMovieRename(message.Movie); notification.OnMovieRename(message.Movie, message.RenamedFiles);
} }
} }
catch (Exception ex) catch (Exception ex)

@ -6,6 +6,7 @@ using NLog;
using NzbDrone.Common.Cache; using NzbDrone.Common.Cache;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Exceptions; using NzbDrone.Core.Exceptions;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
using NzbDrone.Core.Notifications.Plex.PlexTv; using NzbDrone.Core.Notifications.Plex.PlexTv;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
@ -43,7 +44,7 @@ namespace NzbDrone.Core.Notifications.Plex.Server
UpdateIfEnabled(message.Movie); UpdateIfEnabled(message.Movie);
} }
public override void OnMovieRename(Movie movie) public override void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles)
{ {
UpdateIfEnabled(movie); UpdateIfEnabled(movie);
} }

@ -4,6 +4,7 @@ using System.IO;
using System.Linq; using System.Linq;
using FluentValidation.Results; using FluentValidation.Results;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
using NzbDrone.Core.Notifications.Slack.Payloads; using NzbDrone.Core.Notifications.Slack.Payloads;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
@ -56,7 +57,7 @@ namespace NzbDrone.Core.Notifications.Slack
_proxy.SendPayload(payload, Settings); _proxy.SendPayload(payload, Settings);
} }
public override void OnMovieRename(Movie movie) public override void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles)
{ {
var attachments = new List<Attachment> var attachments = new List<Attachment>
{ {

@ -3,6 +3,7 @@ using System.IO;
using FluentValidation.Results; using FluentValidation.Results;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
namespace NzbDrone.Core.Notifications.Synology namespace NzbDrone.Core.Notifications.Synology
@ -38,7 +39,7 @@ namespace NzbDrone.Core.Notifications.Synology
} }
} }
public override void OnMovieRename(Movie movie) public override void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles)
{ {
if (Settings.UpdateLibrary) if (Settings.UpdateLibrary)
{ {

@ -3,6 +3,7 @@ using System.IO;
using System.Linq; using System.Linq;
using FluentValidation.Results; using FluentValidation.Results;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
@ -64,12 +65,13 @@ namespace NzbDrone.Core.Notifications.Webhook
_proxy.SendWebhook(payload, Settings); _proxy.SendWebhook(payload, Settings);
} }
public override void OnMovieRename(Movie movie) public override void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles)
{ {
var payload = new WebhookRenamePayload var payload = new WebhookRenamePayload
{ {
EventType = WebhookEventType.Rename, EventType = WebhookEventType.Rename,
Movie = new WebhookMovie(movie) Movie = new WebhookMovie(movie),
RenamedMovieFiles = renamedFiles.ConvertAll(x => new WebhookRenamedMovieFile(x))
}; };
_proxy.SendWebhook(payload, Settings); _proxy.SendWebhook(payload, Settings);

@ -1,7 +1,10 @@
using System.Collections.Generic;
namespace NzbDrone.Core.Notifications.Webhook namespace NzbDrone.Core.Notifications.Webhook
{ {
public class WebhookRenamePayload : WebhookPayload public class WebhookRenamePayload : WebhookPayload
{ {
public WebhookMovie Movie { get; set; } public WebhookMovie Movie { get; set; }
public List<WebhookRenamedMovieFile> RenamedMovieFiles { get; set; }
} }
} }

@ -0,0 +1,17 @@
using NzbDrone.Core.MediaFiles;
namespace NzbDrone.Core.Notifications.Webhook
{
public class WebhookRenamedMovieFile : WebhookMovieFile
{
public WebhookRenamedMovieFile(RenamedMovieFile renamedMovie)
: base(renamedMovie.MovieFile)
{
PreviousRelativePath = renamedMovie.PreviousRelativePath;
PreviousPath = renamedMovie.PreviousPath;
}
public string PreviousRelativePath { get; set; }
public string PreviousPath { get; set; }
}
}

@ -4,6 +4,7 @@ using System.Net.Sockets;
using FluentValidation.Results; using FluentValidation.Results;
using NLog; using NLog;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
namespace NzbDrone.Core.Notifications.Xbmc namespace NzbDrone.Core.Notifications.Xbmc
@ -36,7 +37,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
UpdateAndCleanMovie(message.Movie, message.OldMovieFiles.Any()); UpdateAndCleanMovie(message.Movie, message.OldMovieFiles.Any());
} }
public override void OnMovieRename(Movie movie) public override void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFiles)
{ {
UpdateAndCleanMovie(movie); UpdateAndCleanMovie(movie);
} }

Loading…
Cancel
Save