|
|
@ -1,4 +1,4 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
@ -21,7 +21,6 @@ namespace NzbDrone.Core.History
|
|
|
|
QualityModel GetBestQualityInHistory(Profile profile, int episodeId);
|
|
|
|
QualityModel GetBestQualityInHistory(Profile profile, int episodeId);
|
|
|
|
PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
|
|
|
|
PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
|
|
|
|
History MostRecentForMovie(int movieId);
|
|
|
|
History MostRecentForMovie(int movieId);
|
|
|
|
History MostRecentForEpisode(int episodeId);
|
|
|
|
|
|
|
|
History MostRecentForDownloadId(string downloadId);
|
|
|
|
History MostRecentForDownloadId(string downloadId);
|
|
|
|
History Get(int historyId);
|
|
|
|
History Get(int historyId);
|
|
|
|
List<History> Find(string downloadId, HistoryEventType eventType);
|
|
|
|
List<History> Find(string downloadId, HistoryEventType eventType);
|
|
|
@ -29,14 +28,11 @@ namespace NzbDrone.Core.History
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class HistoryService : IHistoryService,
|
|
|
|
public class HistoryService : IHistoryService,
|
|
|
|
IHandle<EpisodeGrabbedEvent>,
|
|
|
|
|
|
|
|
IHandle<MovieGrabbedEvent>,
|
|
|
|
IHandle<MovieGrabbedEvent>,
|
|
|
|
IHandle<MovieImportedEvent>,
|
|
|
|
IHandle<MovieImportedEvent>,
|
|
|
|
IHandle<EpisodeImportedEvent>,
|
|
|
|
|
|
|
|
IHandle<DownloadFailedEvent>,
|
|
|
|
IHandle<DownloadFailedEvent>,
|
|
|
|
IHandle<EpisodeFileDeletedEvent>,
|
|
|
|
|
|
|
|
IHandle<MovieFileDeletedEvent>,
|
|
|
|
IHandle<MovieFileDeletedEvent>,
|
|
|
|
IHandle<SeriesDeletedEvent>
|
|
|
|
IHandle<MovieDeletedEvent>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IHistoryRepository _historyRepository;
|
|
|
|
private readonly IHistoryRepository _historyRepository;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly Logger _logger;
|
|
|
@ -52,11 +48,6 @@ namespace NzbDrone.Core.History
|
|
|
|
return _historyRepository.GetPaged(pagingSpec);
|
|
|
|
return _historyRepository.GetPaged(pagingSpec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public History MostRecentForEpisode(int episodeId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _historyRepository.MostRecentForEpisode(episodeId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public History MostRecentForMovie(int movieId)
|
|
|
|
public History MostRecentForMovie(int movieId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return _historyRepository.MostRecentForMovie(movieId);
|
|
|
|
return _historyRepository.MostRecentForMovie(movieId);
|
|
|
@ -205,10 +196,7 @@ namespace NzbDrone.Core.History
|
|
|
|
|
|
|
|
|
|
|
|
var movieId = trackedDownload.MovieInfo.Movie.Id;
|
|
|
|
var movieId = trackedDownload.MovieInfo.Movie.Id;
|
|
|
|
|
|
|
|
|
|
|
|
var allHistory = _historyRepository.FindDownloadHistory(movieId, trackedDownload.ImportedMovie.Quality);
|
|
|
|
var movieHistory = _historyRepository.FindDownloadHistory(movieId, trackedDownload.ImportedMovie.Quality);
|
|
|
|
|
|
|
|
|
|
|
|
//Find download related items for this movie
|
|
|
|
|
|
|
|
var movieHistory = allHistory.Where(h => movieId == h.MovieId).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var processedDownloadId = movieHistory
|
|
|
|
var processedDownloadId = movieHistory
|
|
|
|
.Where(c => c.EventType != HistoryEventType.Grabbed && c.DownloadId != null)
|
|
|
|
.Where(c => c.EventType != HistoryEventType.Grabbed && c.DownloadId != null)
|
|
|
@ -244,136 +232,6 @@ namespace NzbDrone.Core.History
|
|
|
|
return downloadId;
|
|
|
|
return downloadId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string FindDownloadId(EpisodeImportedEvent trackedDownload)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedEpisode.Path);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var episodeIds = trackedDownload.EpisodeInfo.Episodes.Select(c => c.Id).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var allHistory = _historyRepository.FindDownloadHistory(trackedDownload.EpisodeInfo.Series.Id, trackedDownload.ImportedEpisode.Quality);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Find download related items for these episdoes
|
|
|
|
|
|
|
|
var episodesHistory = allHistory.Where(h => episodeIds.Contains(h.EpisodeId)).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var processedDownloadId = episodesHistory
|
|
|
|
|
|
|
|
.Where(c => c.EventType != HistoryEventType.Grabbed && c.DownloadId != null)
|
|
|
|
|
|
|
|
.Select(c => c.DownloadId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var stillDownloading = episodesHistory.Where(c => c.EventType == HistoryEventType.Grabbed && !processedDownloadId.Contains(c.DownloadId)).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string downloadId = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stillDownloading.Any())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var matchingHistory in trackedDownload.EpisodeInfo.Episodes.Select(e => stillDownloading.Where(c => c.EpisodeId == e.Id).ToList()))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (matchingHistory.Count != 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newDownloadId = matchingHistory.Single().DownloadId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (downloadId == null || downloadId == newDownloadId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
downloadId = newDownloadId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return downloadId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Handle(EpisodeGrabbedEvent message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var episode in message.Episode.Episodes)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var history = new History
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
EventType = HistoryEventType.Grabbed,
|
|
|
|
|
|
|
|
Date = DateTime.UtcNow,
|
|
|
|
|
|
|
|
Quality = message.Episode.ParsedEpisodeInfo.Quality,
|
|
|
|
|
|
|
|
SourceTitle = message.Episode.Release.Title,
|
|
|
|
|
|
|
|
SeriesId = episode.SeriesId,
|
|
|
|
|
|
|
|
EpisodeId = episode.Id,
|
|
|
|
|
|
|
|
DownloadId = message.DownloadId,
|
|
|
|
|
|
|
|
MovieId = 0
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
history.Data.Add("Indexer", message.Episode.Release.Indexer);
|
|
|
|
|
|
|
|
history.Data.Add("NzbInfoUrl", message.Episode.Release.InfoUrl);
|
|
|
|
|
|
|
|
history.Data.Add("ReleaseGroup", message.Episode.ParsedEpisodeInfo.ReleaseGroup);
|
|
|
|
|
|
|
|
history.Data.Add("Age", message.Episode.Release.Age.ToString());
|
|
|
|
|
|
|
|
history.Data.Add("AgeHours", message.Episode.Release.AgeHours.ToString());
|
|
|
|
|
|
|
|
history.Data.Add("AgeMinutes", message.Episode.Release.AgeMinutes.ToString());
|
|
|
|
|
|
|
|
history.Data.Add("PublishedDate", message.Episode.Release.PublishDate.ToString("s") + "Z");
|
|
|
|
|
|
|
|
history.Data.Add("DownloadClient", message.DownloadClient);
|
|
|
|
|
|
|
|
history.Data.Add("Size", message.Episode.Release.Size.ToString());
|
|
|
|
|
|
|
|
history.Data.Add("DownloadUrl", message.Episode.Release.DownloadUrl);
|
|
|
|
|
|
|
|
history.Data.Add("Guid", message.Episode.Release.Guid);
|
|
|
|
|
|
|
|
history.Data.Add("TvdbId", message.Episode.Release.TvdbId.ToString());
|
|
|
|
|
|
|
|
history.Data.Add("TvRageId", message.Episode.Release.TvRageId.ToString());
|
|
|
|
|
|
|
|
history.Data.Add("Protocol", ((int)message.Episode.Release.DownloadProtocol).ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!message.Episode.ParsedEpisodeInfo.ReleaseHash.IsNullOrWhiteSpace())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
history.Data.Add("ReleaseHash", message.Episode.ParsedEpisodeInfo.ReleaseHash);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var torrentRelease = message.Episode.Release as TorrentInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (torrentRelease != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
history.Data.Add("TorrentInfoHash", torrentRelease.InfoHash);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Handle(EpisodeImportedEvent message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!message.NewDownload)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var downloadId = message.DownloadId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (downloadId.IsNullOrWhiteSpace())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
downloadId = FindDownloadId(message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var episode in message.EpisodeInfo.Episodes)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var history = new History
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
EventType = HistoryEventType.DownloadFolderImported,
|
|
|
|
|
|
|
|
Date = DateTime.UtcNow,
|
|
|
|
|
|
|
|
Quality = message.EpisodeInfo.Quality,
|
|
|
|
|
|
|
|
SourceTitle = message.ImportedEpisode.SceneName ?? Path.GetFileNameWithoutExtension(message.EpisodeInfo.Path),
|
|
|
|
|
|
|
|
SeriesId = message.ImportedEpisode.SeriesId,
|
|
|
|
|
|
|
|
EpisodeId = episode.Id,
|
|
|
|
|
|
|
|
DownloadId = downloadId,
|
|
|
|
|
|
|
|
MovieId = 0,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Won't have a value since we publish this event before saving to DB.
|
|
|
|
|
|
|
|
//history.Data.Add("FileId", message.ImportedEpisode.Id.ToString());
|
|
|
|
|
|
|
|
history.Data.Add("DroppedPath", message.EpisodeInfo.Path);
|
|
|
|
|
|
|
|
history.Data.Add("ImportedPath", Path.Combine(message.EpisodeInfo.Series.Path, message.ImportedEpisode.RelativePath));
|
|
|
|
|
|
|
|
history.Data.Add("DownloadClient", message.DownloadClient);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Handle(DownloadFailedEvent message)
|
|
|
|
public void Handle(DownloadFailedEvent message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var history = new History
|
|
|
|
var history = new History
|
|
|
@ -393,37 +251,5 @@ namespace NzbDrone.Core.History
|
|
|
|
|
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Handle(EpisodeFileDeletedEvent message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (message.Reason == DeleteMediaFileReason.NoLinkedEpisodes)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Debug("Removing episode file from DB as part of cleanup routine, not creating history event.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var episode in message.EpisodeFile.Episodes.Value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var history = new History
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
EventType = HistoryEventType.EpisodeFileDeleted,
|
|
|
|
|
|
|
|
Date = DateTime.UtcNow,
|
|
|
|
|
|
|
|
Quality = message.EpisodeFile.Quality,
|
|
|
|
|
|
|
|
SourceTitle = message.EpisodeFile.Path,
|
|
|
|
|
|
|
|
SeriesId = message.EpisodeFile.SeriesId,
|
|
|
|
|
|
|
|
EpisodeId = episode.Id,
|
|
|
|
|
|
|
|
MovieId = 0
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
history.Data.Add("Reason", message.Reason.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Handle(SeriesDeletedEvent message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_historyRepository.DeleteForSeries(message.Series.Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|