New: Include renamed file information for Webhook and Custom Scripts
Closes #3927
This commit is contained in:
parent
b815d27a10
commit
3c45349404
|
@ -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<RenamedEpisodeFile> renamedFiles)
|
||||
{
|
||||
TestLogger.Info("OnRename was called");
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace NzbDrone.Core.Test.NotificationTests
|
|||
{
|
||||
(Subject.Definition.Settings as SynologyIndexerSettings).UpdateLibrary = false;
|
||||
|
||||
Subject.OnRename(_series);
|
||||
Subject.OnRename(_series, new List<RenamedEpisodeFile>());
|
||||
|
||||
Mocker.GetMock<ISynologyIndexerProxy>()
|
||||
.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<RenamedEpisodeFile>());
|
||||
|
||||
Mocker.GetMock<ISynologyIndexerProxy>()
|
||||
.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.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<RenamedEpisodeFile> RenamedFiles { get; private set; }
|
||||
|
||||
public SeriesRenamedEvent(Series series)
|
||||
public SeriesRenamedEvent(Series series, List<RenamedEpisodeFile> renamedFiles)
|
||||
{
|
||||
Series = series;
|
||||
RenamedFiles = renamedFiles;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -107,13 +107,14 @@ namespace NzbDrone.Core.MediaFiles
|
|||
}
|
||||
}
|
||||
|
||||
private void RenameFiles(List<EpisodeFile> episodeFiles, Series series)
|
||||
private List<RenamedEpisodeFile> RenameFiles(List<EpisodeFile> episodeFiles, Series series)
|
||||
{
|
||||
var renamed = new List<EpisodeFile>();
|
||||
var renamed = new List<RenamedEpisodeFile>();
|
||||
|
||||
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)
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -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<RenamedEpisodeFile> 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);
|
||||
}
|
||||
|
|
|
@ -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<RenamedEpisodeFile> renamedFiles)
|
||||
{
|
||||
var attachments = new List<Embed>
|
||||
{
|
||||
|
|
|
@ -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<RenamedEpisodeFile> renamedFiles);
|
||||
void OnEpisodeFileDelete(EpisodeDeleteMessage deleteMessage);
|
||||
void OnSeriesDelete(SeriesDeleteMessage deleteMessage);
|
||||
void OnHealthIssue(HealthCheck.HealthCheck healthCheck);
|
||||
|
|
|
@ -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<RenamedEpisodeFile> renamedFiles)
|
||||
{
|
||||
if (Settings.UpdateLibrary)
|
||||
{
|
||||
|
|
|
@ -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<RenamedEpisodeFile> renamedFiles)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ namespace NzbDrone.Core.Notifications
|
|||
{
|
||||
if (ShouldHandleSeries(notification.Definition, message.Series))
|
||||
{
|
||||
notification.OnRename(message.Series);
|
||||
notification.OnRename(message.Series, message.RenamedFiles);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<RenamedEpisodeFile> renamedFiles)
|
||||
{
|
||||
UpdateIfEnabled(series);
|
||||
}
|
||||
|
|
|
@ -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<RenamedEpisodeFile> renamedFiles)
|
||||
{
|
||||
var attachments = new List<Attachment>
|
||||
{
|
||||
|
|
|
@ -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<RenamedEpisodeFile> renamedFiles)
|
||||
{
|
||||
if (Settings.UpdateLibrary)
|
||||
{
|
||||
|
|
|
@ -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<RenamedEpisodeFile> 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);
|
||||
|
|
|
@ -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<WebhookRenamedEpisodeFile> RenamedEpisodeFiles { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -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<RenamedEpisodeFile> renamedFiles)
|
||||
{
|
||||
UpdateAndClean(series);
|
||||
}
|
||||
|
||||
public override void OnEpisodeFileDelete(EpisodeDeleteMessage deleteMessage)
|
||||
{
|
||||
const string header = "Sonarr - Deleted";
|
||||
|
|
Loading…
Reference in New Issue