diff --git a/src/NzbDrone.Core/History/History.cs b/src/NzbDrone.Core/History/History.cs index a3e9a62d7..ffc274db0 100644 --- a/src/NzbDrone.Core/History/History.cs +++ b/src/NzbDrone.Core/History/History.cs @@ -40,6 +40,7 @@ namespace NzbDrone.Core.History SeriesFolderImported = 2, DownloadFolderImported = 3, DownloadFailed = 4, - TrackFileDeleted = 5 + TrackFileDeleted = 5, + TrackFileRenamed = 6 } } diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index 696eca938..c9dba532a 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -33,6 +33,7 @@ namespace NzbDrone.Core.History IHandle, IHandle, IHandle, + IHandle, IHandle { private readonly IHistoryRepository _historyRepository; @@ -253,6 +254,35 @@ namespace NzbDrone.Core.History } } + public void Handle(TrackFileRenamedEvent message) + { + var sourcePath = message.OriginalPath; + var sourceRelativePath = message.Artist.Path.GetRelativePath(message.OriginalPath); + var path = Path.Combine(message.Artist.Path, message.TrackFile.RelativePath); + var relativePath = message.TrackFile.RelativePath; + + foreach (var track in message.TrackFile.Tracks.Value) + { + var history = new History + { + EventType = HistoryEventType.TrackFileRenamed, + Date = DateTime.UtcNow, + Quality = message.TrackFile.Quality, + SourceTitle = message.OriginalPath, + ArtistId = message.TrackFile.ArtistId, + AlbumId = message.TrackFile.AlbumId, + TrackId = track.Id, + }; + + history.Data.Add("SourcePath", sourcePath); + history.Data.Add("SourceRelativePath", sourceRelativePath); + history.Data.Add("Path", path); + history.Data.Add("RelativePath", relativePath); + + _historyRepository.Insert(history); + } + } + public void Handle(ArtistDeletedEvent message) { _historyRepository.DeleteForArtist(message.Artist.Id); diff --git a/src/NzbDrone.Core/MediaFiles/Events/TrackFileRenamedEvent.cs b/src/NzbDrone.Core/MediaFiles/Events/TrackFileRenamedEvent.cs new file mode 100644 index 000000000..a4c1847fc --- /dev/null +++ b/src/NzbDrone.Core/MediaFiles/Events/TrackFileRenamedEvent.cs @@ -0,0 +1,19 @@ +using NzbDrone.Common.Messaging; +using NzbDrone.Core.Music; + +namespace NzbDrone.Core.MediaFiles.Events +{ + public class TrackFileRenamedEvent : IEvent + { + public Artist Artist { get; private set; } + public TrackFile TrackFile { get; private set; } + public string OriginalPath { get; private set; } + + public TrackFileRenamedEvent(Artist artist, TrackFile trackFile, string originalPath) + { + Artist = artist; + TrackFile = trackFile; + OriginalPath = originalPath; + } + } +} diff --git a/src/NzbDrone.Core/MediaFiles/RenameTrackFileService.cs b/src/NzbDrone.Core/MediaFiles/RenameTrackFileService.cs index 8b1352d0d..0a59441e2 100644 --- a/src/NzbDrone.Core/MediaFiles/RenameTrackFileService.cs +++ b/src/NzbDrone.Core/MediaFiles/RenameTrackFileService.cs @@ -129,6 +129,8 @@ namespace NzbDrone.Core.MediaFiles renamed.Add(trackFile); _logger.Debug("Renamed track file: {0}", trackFile); + + _eventAggregator.PublishEvent(new TrackFileRenamedEvent(artist, trackFile, trackFilePath)); } catch (SameFilenameException ex) { diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index af5bc22b8..c0b454e1e 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -620,6 +620,7 @@ +