2017-09-04 02:20:56 +00:00
|
|
|
using System;
|
2013-02-24 19:18:48 +00:00
|
|
|
using System.Collections.Generic;
|
2014-07-23 23:43:54 +00:00
|
|
|
using System.IO;
|
2013-02-23 21:29:22 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
2014-12-02 06:26:25 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Common.Serializer;
|
2013-05-10 22:33:04 +00:00
|
|
|
using NzbDrone.Core.Datastore;
|
2013-02-24 19:18:48 +00:00
|
|
|
using NzbDrone.Core.Download;
|
2014-08-21 06:29:34 +00:00
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-06-09 06:20:38 +00:00
|
|
|
using NzbDrone.Core.MediaFiles.Events;
|
2013-09-14 06:36:07 +00:00
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2017-08-14 02:58:42 +00:00
|
|
|
using NzbDrone.Core.Music.Events;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2019-02-16 14:49:24 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
2013-02-23 21:29:22 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.History
|
|
|
|
{
|
2013-02-24 19:18:48 +00:00
|
|
|
public interface IHistoryService
|
|
|
|
{
|
2013-05-10 22:33:04 +00:00
|
|
|
PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
|
2019-03-10 02:34:25 +00:00
|
|
|
History MostRecentForAlbum(int albumId);
|
2014-12-19 00:26:42 +00:00
|
|
|
History MostRecentForDownloadId(string downloadId);
|
|
|
|
History Get(int historyId);
|
2017-12-14 03:38:27 +00:00
|
|
|
List<History> GetByArtist(int artistId, HistoryEventType? eventType);
|
2019-03-21 02:14:27 +00:00
|
|
|
List<History> GetByAlbum(int albumId, HistoryEventType? eventType);
|
2014-12-19 00:26:42 +00:00
|
|
|
List<History> Find(string downloadId, HistoryEventType eventType);
|
2015-01-19 23:53:31 +00:00
|
|
|
List<History> FindByDownloadId(string downloadId);
|
2017-11-16 02:24:33 +00:00
|
|
|
List<History> Since(DateTime date, HistoryEventType? eventType);
|
2019-07-09 20:14:05 +00:00
|
|
|
void UpdateMany(IList<History> items);
|
2013-02-24 19:18:48 +00:00
|
|
|
}
|
2013-02-23 21:29:22 +00:00
|
|
|
|
2014-08-21 06:29:34 +00:00
|
|
|
public class HistoryService : IHistoryService,
|
2017-08-14 02:58:42 +00:00
|
|
|
IHandle<AlbumGrabbedEvent>,
|
2019-02-16 14:49:24 +00:00
|
|
|
IHandle<AlbumImportIncompleteEvent>,
|
2017-09-26 03:44:53 +00:00
|
|
|
IHandle<TrackImportedEvent>,
|
2014-08-21 06:29:34 +00:00
|
|
|
IHandle<DownloadFailedEvent>,
|
2019-02-16 14:49:24 +00:00
|
|
|
IHandle<DownloadCompletedEvent>,
|
2017-09-26 03:44:53 +00:00
|
|
|
IHandle<TrackFileDeletedEvent>,
|
2017-10-29 03:09:20 +00:00
|
|
|
IHandle<TrackFileRenamedEvent>,
|
2019-03-15 12:10:45 +00:00
|
|
|
IHandle<TrackFileRetaggedEvent>,
|
2021-01-24 19:41:48 +00:00
|
|
|
IHandle<ArtistsDeletedEvent>,
|
2020-07-26 20:27:31 +00:00
|
|
|
IHandle<DownloadIgnoredEvent>
|
2013-02-23 21:29:22 +00:00
|
|
|
{
|
|
|
|
private readonly IHistoryRepository _historyRepository;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
public HistoryService(IHistoryRepository historyRepository, Logger logger)
|
|
|
|
{
|
|
|
|
_historyRepository = historyRepository;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2013-05-10 22:33:04 +00:00
|
|
|
public PagingSpec<History> Paged(PagingSpec<History> pagingSpec)
|
|
|
|
{
|
2013-06-05 00:49:53 +00:00
|
|
|
return _historyRepository.GetPaged(pagingSpec);
|
2013-05-10 22:33:04 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
public History MostRecentForAlbum(int albumId)
|
2013-10-24 05:13:04 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
return _historyRepository.MostRecentForAlbum(albumId);
|
2013-10-24 05:13:04 +00:00
|
|
|
}
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
public History MostRecentForDownloadId(string downloadId)
|
2013-10-30 23:49:53 +00:00
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
return _historyRepository.MostRecentForDownloadId(downloadId);
|
2013-10-30 23:49:53 +00:00
|
|
|
}
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
public History Get(int historyId)
|
2014-04-01 20:07:41 +00:00
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
return _historyRepository.Get(historyId);
|
2014-04-01 20:07:41 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 03:38:27 +00:00
|
|
|
public List<History> GetByArtist(int artistId, HistoryEventType? eventType)
|
|
|
|
{
|
|
|
|
return _historyRepository.GetByArtist(artistId, eventType);
|
|
|
|
}
|
|
|
|
|
2019-03-21 02:14:27 +00:00
|
|
|
public List<History> GetByAlbum(int albumId, HistoryEventType? eventType)
|
2017-12-14 03:38:27 +00:00
|
|
|
{
|
2019-03-21 02:14:27 +00:00
|
|
|
return _historyRepository.GetByAlbum(albumId, eventType);
|
2017-12-14 03:38:27 +00:00
|
|
|
}
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
public List<History> Find(string downloadId, HistoryEventType eventType)
|
2013-02-23 21:29:22 +00:00
|
|
|
{
|
2014-12-19 00:26:42 +00:00
|
|
|
return _historyRepository.FindByDownloadId(downloadId).Where(c => c.EventType == eventType).ToList();
|
2013-02-23 21:29:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 23:53:31 +00:00
|
|
|
public List<History> FindByDownloadId(string downloadId)
|
|
|
|
{
|
|
|
|
return _historyRepository.FindByDownloadId(downloadId);
|
|
|
|
}
|
2013-02-23 21:29:22 +00:00
|
|
|
|
2017-09-26 03:44:53 +00:00
|
|
|
private string FindDownloadId(TrackImportedEvent trackedDownload)
|
2015-04-20 03:25:59 +00:00
|
|
|
{
|
2017-09-26 03:44:53 +00:00
|
|
|
_logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedTrack.Path);
|
2015-04-20 03:25:59 +00:00
|
|
|
|
2017-09-26 03:44:53 +00:00
|
|
|
var albumIds = trackedDownload.TrackInfo.Tracks.Select(c => c.AlbumId).ToList();
|
2015-04-20 03:25:59 +00:00
|
|
|
|
2017-09-26 03:44:53 +00:00
|
|
|
var allHistory = _historyRepository.FindDownloadHistory(trackedDownload.TrackInfo.Artist.Id, trackedDownload.ImportedTrack.Quality);
|
2015-04-20 03:25:59 +00:00
|
|
|
|
|
|
|
//Find download related items for these episdoes
|
2017-08-14 02:58:42 +00:00
|
|
|
var albumsHistory = allHistory.Where(h => albumIds.Contains(h.AlbumId)).ToList();
|
2015-04-20 03:25:59 +00:00
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
var processedDownloadId = albumsHistory
|
2015-04-20 03:25:59 +00:00
|
|
|
.Where(c => c.EventType != HistoryEventType.Grabbed && c.DownloadId != null)
|
|
|
|
.Select(c => c.DownloadId);
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
var stillDownloading = albumsHistory.Where(c => c.EventType == HistoryEventType.Grabbed && !processedDownloadId.Contains(c.DownloadId)).ToList();
|
2015-04-20 03:25:59 +00:00
|
|
|
|
|
|
|
string downloadId = null;
|
|
|
|
|
|
|
|
if (stillDownloading.Any())
|
|
|
|
{
|
2017-09-26 03:44:53 +00:00
|
|
|
foreach (var matchingHistory in trackedDownload.TrackInfo.Tracks.Select(e => stillDownloading.Where(c => c.AlbumId == e.AlbumId).ToList()))
|
2015-04-20 03:25:59 +00:00
|
|
|
{
|
|
|
|
if (matchingHistory.Count != 1)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var newDownloadId = matchingHistory.Single().DownloadId;
|
|
|
|
|
|
|
|
if (downloadId == null || downloadId == newDownloadId)
|
|
|
|
{
|
|
|
|
downloadId = newDownloadId;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return downloadId;
|
|
|
|
}
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
public void Handle(AlbumGrabbedEvent message)
|
2013-02-24 19:18:48 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
foreach (var album in message.Album.Albums)
|
2013-02-24 19:18:48 +00:00
|
|
|
{
|
|
|
|
var history = new History
|
|
|
|
{
|
2013-08-30 06:38:55 +00:00
|
|
|
EventType = HistoryEventType.Grabbed,
|
2013-06-09 20:50:57 +00:00
|
|
|
Date = DateTime.UtcNow,
|
2017-08-14 02:58:42 +00:00
|
|
|
Quality = message.Album.ParsedAlbumInfo.Quality,
|
|
|
|
SourceTitle = message.Album.Release.Title,
|
|
|
|
ArtistId = album.ArtistId,
|
|
|
|
AlbumId = album.Id,
|
2019-08-02 11:50:09 +00:00
|
|
|
DownloadId = message.DownloadId
|
2013-02-24 19:18:48 +00:00
|
|
|
};
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
history.Data.Add("Indexer", message.Album.Release.Indexer);
|
|
|
|
history.Data.Add("NzbInfoUrl", message.Album.Release.InfoUrl);
|
|
|
|
history.Data.Add("ReleaseGroup", message.Album.ParsedAlbumInfo.ReleaseGroup);
|
|
|
|
history.Data.Add("Age", message.Album.Release.Age.ToString());
|
|
|
|
history.Data.Add("AgeHours", message.Album.Release.AgeHours.ToString());
|
|
|
|
history.Data.Add("AgeMinutes", message.Album.Release.AgeMinutes.ToString());
|
|
|
|
history.Data.Add("PublishedDate", message.Album.Release.PublishDate.ToString("s") + "Z");
|
2014-01-05 19:49:04 +00:00
|
|
|
history.Data.Add("DownloadClient", message.DownloadClient);
|
2017-08-14 02:58:42 +00:00
|
|
|
history.Data.Add("Size", message.Album.Release.Size.ToString());
|
|
|
|
history.Data.Add("DownloadUrl", message.Album.Release.DownloadUrl);
|
|
|
|
history.Data.Add("Guid", message.Album.Release.Guid);
|
|
|
|
history.Data.Add("Protocol", ((int)message.Album.Release.DownloadProtocol).ToString());
|
2018-11-11 05:38:38 +00:00
|
|
|
history.Data.Add("DownloadForced", (!message.Album.DownloadAllowed).ToString());
|
2017-08-14 02:58:42 +00:00
|
|
|
|
|
|
|
if (!message.Album.ParsedAlbumInfo.ReleaseHash.IsNullOrWhiteSpace())
|
2014-05-19 19:14:41 +00:00
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
history.Data.Add("ReleaseHash", message.Album.ParsedAlbumInfo.ReleaseHash);
|
2014-05-19 19:14:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
var torrentRelease = message.Album.Release as TorrentInfo;
|
2015-04-20 03:25:59 +00:00
|
|
|
|
|
|
|
if (torrentRelease != null)
|
|
|
|
{
|
|
|
|
history.Data.Add("TorrentInfoHash", torrentRelease.InfoHash);
|
|
|
|
}
|
|
|
|
|
2013-06-09 06:20:38 +00:00
|
|
|
_historyRepository.Insert(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-16 14:49:24 +00:00
|
|
|
public void Handle(AlbumImportIncompleteEvent message)
|
|
|
|
{
|
|
|
|
foreach (var album in message.TrackedDownload.RemoteAlbum.Albums)
|
|
|
|
{
|
|
|
|
var history = new History
|
|
|
|
{
|
|
|
|
EventType = HistoryEventType.AlbumImportIncomplete,
|
|
|
|
Date = DateTime.UtcNow,
|
|
|
|
Quality = message.TrackedDownload.RemoteAlbum.ParsedAlbumInfo?.Quality ?? new QualityModel(),
|
|
|
|
SourceTitle = message.TrackedDownload.DownloadItem.Title,
|
|
|
|
ArtistId = album.ArtistId,
|
|
|
|
AlbumId = album.Id,
|
2019-08-02 11:50:09 +00:00
|
|
|
DownloadId = message.TrackedDownload.DownloadItem.DownloadId
|
2019-02-16 14:49:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
history.Data.Add("StatusMessages", message.TrackedDownload.StatusMessages.ToJson());
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 03:44:53 +00:00
|
|
|
public void Handle(TrackImportedEvent message)
|
2013-06-09 06:20:38 +00:00
|
|
|
{
|
2014-01-26 07:14:55 +00:00
|
|
|
if (!message.NewDownload)
|
2014-01-22 05:22:09 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-19 00:26:42 +00:00
|
|
|
var downloadId = message.DownloadId;
|
|
|
|
|
|
|
|
if (downloadId.IsNullOrWhiteSpace())
|
|
|
|
{
|
|
|
|
downloadId = FindDownloadId(message);
|
|
|
|
}
|
|
|
|
|
2017-09-26 03:44:53 +00:00
|
|
|
foreach (var track in message.TrackInfo.Tracks)
|
2013-06-09 06:20:38 +00:00
|
|
|
{
|
|
|
|
var history = new History
|
2020-01-03 12:49:24 +00:00
|
|
|
{
|
|
|
|
EventType = HistoryEventType.TrackFileImported,
|
|
|
|
Date = DateTime.UtcNow,
|
|
|
|
Quality = message.TrackInfo.Quality,
|
|
|
|
SourceTitle = message.ImportedTrack.SceneName ?? Path.GetFileNameWithoutExtension(message.TrackInfo.Path),
|
|
|
|
ArtistId = message.TrackInfo.Artist.Id,
|
|
|
|
AlbumId = message.TrackInfo.Album.Id,
|
|
|
|
TrackId = track.Id,
|
|
|
|
DownloadId = downloadId
|
2017-09-04 02:20:56 +00:00
|
|
|
};
|
2013-06-09 06:20:38 +00:00
|
|
|
|
2013-08-30 06:39:41 +00:00
|
|
|
//Won't have a value since we publish this event before saving to DB.
|
|
|
|
//history.Data.Add("FileId", message.ImportedEpisode.Id.ToString());
|
2017-09-26 03:44:53 +00:00
|
|
|
history.Data.Add("DroppedPath", message.TrackInfo.Path);
|
2019-06-08 19:13:58 +00:00
|
|
|
history.Data.Add("ImportedPath", message.ImportedTrack.Path);
|
2014-04-19 15:09:22 +00:00
|
|
|
history.Data.Add("DownloadClient", message.DownloadClient);
|
2013-08-26 05:31:58 +00:00
|
|
|
|
2013-02-24 19:18:48 +00:00
|
|
|
_historyRepository.Insert(history);
|
|
|
|
}
|
|
|
|
}
|
2013-10-22 07:31:36 +00:00
|
|
|
|
|
|
|
public void Handle(DownloadFailedEvent message)
|
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
foreach (var albumId in message.AlbumIds)
|
2013-10-22 07:31:36 +00:00
|
|
|
{
|
2013-10-24 05:13:04 +00:00
|
|
|
var history = new History
|
|
|
|
{
|
|
|
|
EventType = HistoryEventType.DownloadFailed,
|
|
|
|
Date = DateTime.UtcNow,
|
|
|
|
Quality = message.Quality,
|
|
|
|
SourceTitle = message.SourceTitle,
|
2017-08-18 01:28:35 +00:00
|
|
|
ArtistId = message.ArtistId,
|
2017-08-14 02:58:42 +00:00
|
|
|
AlbumId = albumId,
|
2019-08-02 11:50:09 +00:00
|
|
|
DownloadId = message.DownloadId
|
2013-10-24 05:13:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
history.Data.Add("DownloadClient", message.DownloadClient);
|
2013-10-25 01:25:04 +00:00
|
|
|
history.Data.Add("Message", message.Message);
|
2013-10-24 05:13:04 +00:00
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
}
|
2013-10-22 07:31:36 +00:00
|
|
|
}
|
2014-08-21 06:29:34 +00:00
|
|
|
|
2019-02-16 14:49:24 +00:00
|
|
|
public void Handle(DownloadCompletedEvent message)
|
|
|
|
{
|
|
|
|
foreach (var album in message.TrackedDownload.RemoteAlbum.Albums)
|
|
|
|
{
|
|
|
|
var history = new History
|
|
|
|
{
|
|
|
|
EventType = HistoryEventType.DownloadImported,
|
|
|
|
Date = DateTime.UtcNow,
|
|
|
|
Quality = message.TrackedDownload.RemoteAlbum.ParsedAlbumInfo?.Quality ?? new QualityModel(),
|
|
|
|
SourceTitle = message.TrackedDownload.DownloadItem.Title,
|
|
|
|
ArtistId = album.ArtistId,
|
|
|
|
AlbumId = album.Id,
|
2019-08-02 11:50:09 +00:00
|
|
|
DownloadId = message.TrackedDownload.DownloadItem.DownloadId
|
2019-02-16 14:49:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 03:44:53 +00:00
|
|
|
public void Handle(TrackFileDeletedEvent message)
|
2014-08-21 06:29:34 +00:00
|
|
|
{
|
|
|
|
if (message.Reason == DeleteMediaFileReason.NoLinkedEpisodes)
|
|
|
|
{
|
2017-09-26 03:44:53 +00:00
|
|
|
_logger.Debug("Removing track file from DB as part of cleanup routine, not creating history event.");
|
2014-08-21 06:29:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-26 03:01:53 +00:00
|
|
|
else if (message.Reason == DeleteMediaFileReason.ManualOverride)
|
|
|
|
{
|
|
|
|
_logger.Debug("Removing track file from DB as part of manual override of existing file, not creating history event.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-26 03:44:53 +00:00
|
|
|
foreach (var track in message.TrackFile.Tracks.Value)
|
2014-08-21 06:29:34 +00:00
|
|
|
{
|
|
|
|
var history = new History
|
|
|
|
{
|
2017-09-26 03:44:53 +00:00
|
|
|
EventType = HistoryEventType.TrackFileDeleted,
|
2014-08-21 06:29:34 +00:00
|
|
|
Date = DateTime.UtcNow,
|
2017-09-26 03:44:53 +00:00
|
|
|
Quality = message.TrackFile.Quality,
|
|
|
|
SourceTitle = message.TrackFile.Path,
|
2019-02-16 14:49:24 +00:00
|
|
|
ArtistId = message.TrackFile.Artist.Value.Id,
|
2017-09-26 03:44:53 +00:00
|
|
|
AlbumId = message.TrackFile.AlbumId,
|
|
|
|
TrackId = track.Id,
|
2014-08-21 06:29:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
history.Data.Add("Reason", message.Reason.ToString());
|
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
}
|
|
|
|
}
|
2016-07-20 22:53:49 +00:00
|
|
|
|
2017-10-29 03:09:20 +00:00
|
|
|
public void Handle(TrackFileRenamedEvent message)
|
|
|
|
{
|
|
|
|
var sourcePath = message.OriginalPath;
|
2019-06-08 19:13:58 +00:00
|
|
|
var path = message.TrackFile.Path;
|
2017-10-29 03:09:20 +00:00
|
|
|
|
|
|
|
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,
|
2019-02-16 14:49:24 +00:00
|
|
|
ArtistId = message.TrackFile.Artist.Value.Id,
|
2017-10-29 03:09:20 +00:00
|
|
|
AlbumId = message.TrackFile.AlbumId,
|
|
|
|
TrackId = track.Id,
|
|
|
|
};
|
|
|
|
|
|
|
|
history.Data.Add("SourcePath", sourcePath);
|
|
|
|
history.Data.Add("Path", path);
|
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 12:10:45 +00:00
|
|
|
public void Handle(TrackFileRetaggedEvent message)
|
|
|
|
{
|
2019-06-08 19:13:58 +00:00
|
|
|
var path = message.TrackFile.Path;
|
2019-03-15 12:10:45 +00:00
|
|
|
|
|
|
|
foreach (var track in message.TrackFile.Tracks.Value)
|
|
|
|
{
|
|
|
|
var history = new History
|
|
|
|
{
|
|
|
|
EventType = HistoryEventType.TrackFileRetagged,
|
|
|
|
Date = DateTime.UtcNow,
|
|
|
|
Quality = message.TrackFile.Quality,
|
|
|
|
SourceTitle = path,
|
|
|
|
ArtistId = message.TrackFile.Artist.Value.Id,
|
|
|
|
AlbumId = message.TrackFile.AlbumId,
|
|
|
|
TrackId = track.Id,
|
|
|
|
};
|
2020-01-03 12:49:24 +00:00
|
|
|
|
2019-03-15 12:10:45 +00:00
|
|
|
history.Data.Add("TagsScrubbed", message.Scrubbed.ToString());
|
2020-01-03 12:49:24 +00:00
|
|
|
history.Data.Add("Diff", message.Diff.Select(x => new
|
|
|
|
{
|
|
|
|
Field = x.Key,
|
|
|
|
OldValue = x.Value.Item1,
|
|
|
|
NewValue = x.Value.Item2
|
|
|
|
}).ToJson());
|
2019-03-15 12:10:45 +00:00
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-24 19:41:48 +00:00
|
|
|
public void Handle(ArtistsDeletedEvent message)
|
2016-07-20 22:53:49 +00:00
|
|
|
{
|
2021-01-24 19:41:48 +00:00
|
|
|
_historyRepository.DeleteForArtists(message.Artists.Select(x => x.Id).ToList());
|
2016-07-20 22:53:49 +00:00
|
|
|
}
|
2017-11-16 02:24:33 +00:00
|
|
|
|
2020-07-26 20:27:31 +00:00
|
|
|
public void Handle(DownloadIgnoredEvent message)
|
|
|
|
{
|
|
|
|
var historyToAdd = new List<History>();
|
|
|
|
foreach (var albumId in message.AlbumIds)
|
|
|
|
{
|
|
|
|
var history = new History
|
|
|
|
{
|
|
|
|
EventType = HistoryEventType.DownloadIgnored,
|
|
|
|
Date = DateTime.UtcNow,
|
|
|
|
Quality = message.Quality,
|
|
|
|
SourceTitle = message.SourceTitle,
|
|
|
|
ArtistId = message.ArtistId,
|
|
|
|
AlbumId = albumId,
|
|
|
|
DownloadId = message.DownloadId
|
|
|
|
};
|
|
|
|
|
2020-11-16 21:34:49 +00:00
|
|
|
history.Data.Add("DownloadClient", message.DownloadClientInfo.Name);
|
2020-07-26 20:27:31 +00:00
|
|
|
history.Data.Add("Message", message.Message);
|
|
|
|
|
|
|
|
historyToAdd.Add(history);
|
|
|
|
}
|
|
|
|
|
|
|
|
_historyRepository.InsertMany(historyToAdd);
|
|
|
|
}
|
|
|
|
|
2017-11-16 02:24:33 +00:00
|
|
|
public List<History> Since(DateTime date, HistoryEventType? eventType)
|
|
|
|
{
|
|
|
|
return _historyRepository.Since(date, eventType);
|
|
|
|
}
|
2019-07-09 20:14:05 +00:00
|
|
|
|
|
|
|
public void UpdateMany(IList<History> items)
|
|
|
|
{
|
|
|
|
_historyRepository.UpdateMany(items);
|
|
|
|
}
|
2013-02-23 21:29:22 +00:00
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|