diff --git a/src/NzbDrone.Core.Test/NotificationTests/NotificationBaseFixture.cs b/src/NzbDrone.Core.Test/NotificationTests/NotificationBaseFixture.cs index 3d5388eaa..67327a852 100644 --- a/src/NzbDrone.Core.Test/NotificationTests/NotificationBaseFixture.cs +++ b/src/NzbDrone.Core.Test/NotificationTests/NotificationBaseFixture.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using FluentAssertions; using FluentValidation.Results; using NUnit.Framework; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Notifications; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Tv; @@ -60,7 +62,7 @@ namespace NzbDrone.Core.Test.NotificationTests TestLogger.Info("OnDownload was called"); } - public override void OnRename(Series series) + public override void OnRename(Series series, List renamedFiles) { TestLogger.Info("OnRename was called"); } diff --git a/src/NzbDrone.Core.Test/NotificationTests/SynologyIndexerFixture.cs b/src/NzbDrone.Core.Test/NotificationTests/SynologyIndexerFixture.cs index 724bfb0d7..b2bb853e1 100644 --- a/src/NzbDrone.Core.Test/NotificationTests/SynologyIndexerFixture.cs +++ b/src/NzbDrone.Core.Test/NotificationTests/SynologyIndexerFixture.cs @@ -60,7 +60,7 @@ namespace NzbDrone.Core.Test.NotificationTests { (Subject.Definition.Settings as SynologyIndexerSettings).UpdateLibrary = false; - Subject.OnRename(_series); + Subject.OnRename(_series, new List()); Mocker.GetMock() .Verify(v => v.UpdateFolder(_series.Path), Times.Never()); @@ -90,7 +90,7 @@ namespace NzbDrone.Core.Test.NotificationTests [Test] public void should_update_entire_series_folder_on_rename() { - Subject.OnRename(_series); + Subject.OnRename(_series, new List()); Mocker.GetMock() .Verify(v => v.UpdateFolder(@"C:\Test\".AsOsAgnostic()), Times.Once()); diff --git a/src/NzbDrone.Core/MediaFiles/Events/SeriesRenamedEvent.cs b/src/NzbDrone.Core/MediaFiles/Events/SeriesRenamedEvent.cs index 8cfe96b89..9b2b82151 100644 --- a/src/NzbDrone.Core/MediaFiles/Events/SeriesRenamedEvent.cs +++ b/src/NzbDrone.Core/MediaFiles/Events/SeriesRenamedEvent.cs @@ -1,4 +1,5 @@ -using NzbDrone.Common.Messaging; +using System.Collections.Generic; +using NzbDrone.Common.Messaging; using NzbDrone.Core.Tv; namespace NzbDrone.Core.MediaFiles.Events @@ -6,10 +7,12 @@ namespace NzbDrone.Core.MediaFiles.Events public class SeriesRenamedEvent : IEvent { public Series Series { get; private set; } + public List RenamedFiles { get; private set; } - public SeriesRenamedEvent(Series series) + public SeriesRenamedEvent(Series series, List renamedFiles) { Series = series; + RenamedFiles = renamedFiles; } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs b/src/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs index 9ffdaa26c..bd16f2d87 100644 --- a/src/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs +++ b/src/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs @@ -107,13 +107,14 @@ namespace NzbDrone.Core.MediaFiles } } - private void RenameFiles(List episodeFiles, Series series) + private List RenameFiles(List episodeFiles, Series series) { - var renamed = new List(); + var renamed = new List(); foreach (var episodeFile in episodeFiles) { - var episodeFilePath = Path.Combine(series.Path, episodeFile.RelativePath); + var previousRelativePath = episodeFile.RelativePath; + var previousPath = Path.Combine(series.Path, episodeFile.RelativePath); try { @@ -121,11 +122,17 @@ namespace NzbDrone.Core.MediaFiles _episodeFileMover.MoveEpisodeFile(episodeFile, series); _mediaFileService.Update(episodeFile); - renamed.Add(episodeFile); + + renamed.Add(new RenamedEpisodeFile + { + EpisodeFile = episodeFile, + PreviousRelativePath = previousRelativePath, + PreviousPath = previousPath + }); _logger.Debug("Renamed episode file: {0}", episodeFile); - _eventAggregator.PublishEvent(new EpisodeFileRenamedEvent(series, episodeFile, episodeFilePath)); + _eventAggregator.PublishEvent(new EpisodeFileRenamedEvent(series, episodeFile, previousPath)); } catch (SameFilenameException ex) { @@ -133,7 +140,7 @@ namespace NzbDrone.Core.MediaFiles } catch (Exception ex) { - _logger.Error(ex, "Failed to rename file {0}", episodeFilePath); + _logger.Error(ex, "Failed to rename file {0}", previousPath); } } @@ -141,8 +148,10 @@ namespace NzbDrone.Core.MediaFiles { _diskProvider.RemoveEmptySubfolders(series.Path); - _eventAggregator.PublishEvent(new SeriesRenamedEvent(series)); + _eventAggregator.PublishEvent(new SeriesRenamedEvent(series, renamed)); } + + return renamed; } public void Execute(RenameFilesCommand message) diff --git a/src/NzbDrone.Core/MediaFiles/RenamedEpisodeFile.cs b/src/NzbDrone.Core/MediaFiles/RenamedEpisodeFile.cs new file mode 100644 index 000000000..444e8328d --- /dev/null +++ b/src/NzbDrone.Core/MediaFiles/RenamedEpisodeFile.cs @@ -0,0 +1,9 @@ +namespace NzbDrone.Core.MediaFiles +{ + public class RenamedEpisodeFile + { + public EpisodeFile EpisodeFile { get; set; } + public string PreviousPath { get; set; } + public string PreviousRelativePath { get; set; } + } +} diff --git a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs index 8a830887f..38e0e36bd 100644 --- a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs +++ b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs @@ -9,6 +9,7 @@ using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; using NzbDrone.Common.Processes; using NzbDrone.Core.HealthCheck; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Tv; using NzbDrone.Core.Validation; @@ -111,7 +112,7 @@ namespace NzbDrone.Core.Notifications.CustomScript ExecuteScript(environmentVariables); } - public override void OnRename(Series series) + public override void OnRename(Series series, List renamedFiles) { var environmentVariables = new StringDictionary(); @@ -123,6 +124,11 @@ namespace NzbDrone.Core.Notifications.CustomScript environmentVariables.Add("Sonarr_Series_TvMazeId", series.TvMazeId.ToString()); environmentVariables.Add("Sonarr_Series_ImdbId", series.ImdbId ?? string.Empty); environmentVariables.Add("Sonarr_Series_Type", series.SeriesType.ToString()); + environmentVariables.Add("Sonarr_EpisodeFile_Ids", string.Join(",", renamedFiles.Select(e => e.EpisodeFile.Id))); + environmentVariables.Add("Sonarr_EpisodeFile_RelativePaths", string.Join("|", renamedFiles.Select(e => e.EpisodeFile.RelativePath))); + environmentVariables.Add("Sonarr_EpisodeFile_Paths", string.Join("|", renamedFiles.Select(e => e.EpisodeFile.Path))); + environmentVariables.Add("Sonarr_EpisodeFile_PreviousRelativePaths", string.Join("|", renamedFiles.Select(e => e.PreviousRelativePath))); + environmentVariables.Add("Sonarr_EpisodeFile_PreviousPaths", string.Join("|", renamedFiles.Select(e => e.PreviousPath))); ExecuteScript(environmentVariables); } diff --git a/src/NzbDrone.Core/Notifications/Discord/Discord.cs b/src/NzbDrone.Core/Notifications/Discord/Discord.cs index 062103288..40eec4698 100644 --- a/src/NzbDrone.Core/Notifications/Discord/Discord.cs +++ b/src/NzbDrone.Core/Notifications/Discord/Discord.cs @@ -4,6 +4,7 @@ using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; using NzbDrone.Core.MediaCover; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles.MediaInfo; using NzbDrone.Core.Notifications.Discord.Payloads; using NzbDrone.Core.Tv; @@ -220,7 +221,7 @@ namespace NzbDrone.Core.Notifications.Discord _proxy.SendPayload(payload, Settings); } - public override void OnRename(Series series) + public override void OnRename(Series series, List renamedFiles) { var attachments = new List { diff --git a/src/NzbDrone.Core/Notifications/INotification.cs b/src/NzbDrone.Core/Notifications/INotification.cs index bb982dcc6..f9639d897 100644 --- a/src/NzbDrone.Core/Notifications/INotification.cs +++ b/src/NzbDrone.Core/Notifications/INotification.cs @@ -1,4 +1,6 @@ -using NzbDrone.Core.ThingiProvider; +using System.Collections.Generic; +using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Notifications @@ -9,7 +11,7 @@ namespace NzbDrone.Core.Notifications void OnGrab(GrabMessage grabMessage); void OnDownload(DownloadMessage message); - void OnRename(Series series); + void OnRename(Series series, List renamedFiles); void OnEpisodeFileDelete(EpisodeDeleteMessage deleteMessage); void OnSeriesDelete(SeriesDeleteMessage deleteMessage); void OnHealthIssue(HealthCheck.HealthCheck healthCheck); diff --git a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs index 63fbe8d96..132d75262 100644 --- a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs +++ b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using FluentValidation.Results; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Notifications.Emby @@ -39,7 +40,7 @@ namespace NzbDrone.Core.Notifications.Emby } } - public override void OnRename(Series series) + public override void OnRename(Series series, List renamedFiles) { if (Settings.UpdateLibrary) { diff --git a/src/NzbDrone.Core/Notifications/NotificationBase.cs b/src/NzbDrone.Core/Notifications/NotificationBase.cs index 34ec5111b..81a5ac767 100644 --- a/src/NzbDrone.Core/Notifications/NotificationBase.cs +++ b/src/NzbDrone.Core/Notifications/NotificationBase.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using FluentValidation.Results; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Tv; @@ -44,7 +45,7 @@ namespace NzbDrone.Core.Notifications } - public virtual void OnRename(Series series) + public virtual void OnRename(Series series, List renamedFiles) { } diff --git a/src/NzbDrone.Core/Notifications/NotificationService.cs b/src/NzbDrone.Core/Notifications/NotificationService.cs index a013181b1..df520c1b8 100644 --- a/src/NzbDrone.Core/Notifications/NotificationService.cs +++ b/src/NzbDrone.Core/Notifications/NotificationService.cs @@ -182,7 +182,7 @@ namespace NzbDrone.Core.Notifications { if (ShouldHandleSeries(notification.Definition, message.Series)) { - notification.OnRename(message.Series); + notification.OnRename(message.Series, message.RenamedFiles); } } diff --git a/src/NzbDrone.Core/Notifications/Plex/Server/PlexServer.cs b/src/NzbDrone.Core/Notifications/Plex/Server/PlexServer.cs index db1029534..dbda0a22a 100644 --- a/src/NzbDrone.Core/Notifications/Plex/Server/PlexServer.cs +++ b/src/NzbDrone.Core/Notifications/Plex/Server/PlexServer.cs @@ -6,6 +6,7 @@ using NLog; using NzbDrone.Common.Cache; using NzbDrone.Common.Extensions; using NzbDrone.Core.Exceptions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Notifications.Plex.PlexTv; using NzbDrone.Core.Tv; using NzbDrone.Core.Validation; @@ -43,7 +44,7 @@ namespace NzbDrone.Core.Notifications.Plex.Server UpdateIfEnabled(message.Series); } - public override void OnRename(Series series) + public override void OnRename(Series series, List renamedFiles) { UpdateIfEnabled(series); } diff --git a/src/NzbDrone.Core/Notifications/Slack/Slack.cs b/src/NzbDrone.Core/Notifications/Slack/Slack.cs index de35793fb..49efa3f55 100644 --- a/src/NzbDrone.Core/Notifications/Slack/Slack.cs +++ b/src/NzbDrone.Core/Notifications/Slack/Slack.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Notifications.Slack.Payloads; using NzbDrone.Core.Tv; using NzbDrone.Core.Validation; @@ -56,7 +57,7 @@ namespace NzbDrone.Core.Notifications.Slack _proxy.SendPayload(payload, Settings); } - public override void OnRename(Series series) + public override void OnRename(Series series, List renamedFiles) { var attachments = new List { diff --git a/src/NzbDrone.Core/Notifications/Synology/SynologyIndexer.cs b/src/NzbDrone.Core/Notifications/Synology/SynologyIndexer.cs index a04f77726..538e77581 100644 --- a/src/NzbDrone.Core/Notifications/Synology/SynologyIndexer.cs +++ b/src/NzbDrone.Core/Notifications/Synology/SynologyIndexer.cs @@ -3,6 +3,7 @@ using System.IO; using FluentValidation.Results; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Notifications.Synology @@ -39,7 +40,7 @@ namespace NzbDrone.Core.Notifications.Synology } } - public override void OnRename(Series series) + public override void OnRename(Series series, List renamedFiles) { if (Settings.UpdateLibrary) { diff --git a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs index 2bf98c26d..ce59b07a2 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs @@ -4,6 +4,7 @@ using System.Linq; using FluentValidation.Results; using NzbDrone.Core.Tv; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Notifications.Webhook @@ -65,12 +66,13 @@ namespace NzbDrone.Core.Notifications.Webhook _proxy.SendWebhook(payload, Settings); } - public override void OnRename(Series series) + public override void OnRename(Series series, List renamedFiles) { var payload = new WebhookRenamePayload { EventType = WebhookEventType.Rename, - Series = new WebhookSeries(series) + Series = new WebhookSeries(series), + RenamedEpisodeFiles = renamedFiles.ConvertAll(x => new WebhookRenamedEpisodeFile(x)) }; _proxy.SendWebhook(payload, Settings); diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs index 04dc6be5f..6ebb92b49 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs @@ -1,7 +1,10 @@ -namespace NzbDrone.Core.Notifications.Webhook +using System.Collections.Generic; + +namespace NzbDrone.Core.Notifications.Webhook { public class WebhookRenamePayload : WebhookPayload { public WebhookSeries Series { get; set; } + public List RenamedEpisodeFiles { get; set; } } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamedEpisodeFile.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamedEpisodeFile.cs new file mode 100644 index 000000000..a1da2ed1a --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamedEpisodeFile.cs @@ -0,0 +1,16 @@ +using NzbDrone.Core.MediaFiles; + +namespace NzbDrone.Core.Notifications.Webhook +{ + public class WebhookRenamedEpisodeFile : WebhookEpisodeFile + { + public WebhookRenamedEpisodeFile(RenamedEpisodeFile renamedEpisode) : base(renamedEpisode.EpisodeFile) + { + PreviousRelativePath = renamedEpisode.PreviousRelativePath; + PreviousPath = renamedEpisode.PreviousPath; + } + + public string PreviousRelativePath { get; set; } + public string PreviousPath { get; set; } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs b/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs index 51ae68627..762ad6e1c 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs @@ -4,6 +4,7 @@ using System.Net.Sockets; using FluentValidation.Results; using NLog; using NzbDrone.Common.Extensions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Notifications.Xbmc @@ -36,10 +37,11 @@ namespace NzbDrone.Core.Notifications.Xbmc UpdateAndClean(message.Series, message.OldFiles.Any()); } - public override void OnRename(Series series) + public override void OnRename(Series series, List renamedFiles) { UpdateAndClean(series); } + public override void OnEpisodeFileDelete(EpisodeDeleteMessage deleteMessage) { const string header = "Sonarr - Deleted";