mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-27 00:02:25 +00:00
New: Store track renames in History
This commit is contained in:
parent
257af8b914
commit
57aaf62a46
5 changed files with 54 additions and 1 deletions
|
@ -40,6 +40,7 @@ public enum HistoryEventType
|
|||
SeriesFolderImported = 2,
|
||||
DownloadFolderImported = 3,
|
||||
DownloadFailed = 4,
|
||||
TrackFileDeleted = 5
|
||||
TrackFileDeleted = 5,
|
||||
TrackFileRenamed = 6
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public class HistoryService : IHistoryService,
|
|||
IHandle<TrackImportedEvent>,
|
||||
IHandle<DownloadFailedEvent>,
|
||||
IHandle<TrackFileDeletedEvent>,
|
||||
IHandle<TrackFileRenamedEvent>,
|
||||
IHandle<ArtistDeletedEvent>
|
||||
{
|
||||
private readonly IHistoryRepository _historyRepository;
|
||||
|
@ -253,6 +254,35 @@ public void Handle(TrackFileDeletedEvent message)
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
19
src/NzbDrone.Core/MediaFiles/Events/TrackFileRenamedEvent.cs
Normal file
19
src/NzbDrone.Core/MediaFiles/Events/TrackFileRenamedEvent.cs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -129,6 +129,8 @@ private void RenameFiles(List<TrackFile> trackFiles, Artist artist)
|
|||
renamed.Add(trackFile);
|
||||
|
||||
_logger.Debug("Renamed track file: {0}", trackFile);
|
||||
|
||||
_eventAggregator.PublishEvent(new TrackFileRenamedEvent(artist, trackFile, trackFilePath));
|
||||
}
|
||||
catch (SameFilenameException ex)
|
||||
{
|
||||
|
|
|
@ -620,6 +620,7 @@
|
|||
<Compile Include="MediaFiles\Commands\CleanUpRecycleBinCommand.cs" />
|
||||
<Compile Include="MediaFiles\Commands\DownloadedAlbumsScanCommand.cs" />
|
||||
<Compile Include="MediaFiles\Commands\RenameArtistCommand.cs" />
|
||||
<Compile Include="MediaFiles\Events\TrackFileRenamedEvent.cs" />
|
||||
<Compile Include="MediaFiles\Events\TrackFolderCreatedEvent.cs" />
|
||||
<Compile Include="MediaFiles\MediaFileDeletionService.cs" />
|
||||
<Compile Include="MediaFiles\MediaInfo\MediaInfoFormatter.cs" />
|
||||
|
|
Loading…
Reference in a new issue