mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-26 22:46:37 -04:00
Failed downloads are added to history
This commit is contained in:
@@ -17,12 +17,9 @@ namespace NzbDrone.Core.History
|
||||
public string SourceTitle { get; set; }
|
||||
public QualityModel Quality { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public Episode Episode { get; set; }
|
||||
public Series Series { get; set; }
|
||||
|
||||
public HistoryEventType EventType { get; set; }
|
||||
|
||||
public Dictionary<string, string> Data { get; set; }
|
||||
}
|
||||
|
||||
@@ -32,7 +29,8 @@ namespace NzbDrone.Core.History
|
||||
Unknown = 0,
|
||||
Grabbed = 1,
|
||||
SeriesFolderImported = 2,
|
||||
DownloadFolderImported = 3
|
||||
DownloadFolderImported = 3,
|
||||
DownloadFailed = 4
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,8 @@ namespace NzbDrone.Core.History
|
||||
{
|
||||
void Trim();
|
||||
List<QualityModel> GetBestQualityInHistory(int episodeId);
|
||||
List<History> BetweenDates(DateTime startDate, DateTime endDate, HistoryEventType eventType);
|
||||
List<History> Failed();
|
||||
}
|
||||
|
||||
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
|
||||
@@ -38,6 +40,20 @@ namespace NzbDrone.Core.History
|
||||
return history.Select(h => h.Quality).ToList();
|
||||
}
|
||||
|
||||
public List<History> BetweenDates(DateTime startDate, DateTime endDate, HistoryEventType eventType)
|
||||
{
|
||||
return Query.Join<History, Series>(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id)
|
||||
.Join<History, Episode>(JoinType.Inner, h => h.Episode, (h, e) => h.EpisodeId == e.Id)
|
||||
.Where(h => h.Date >= startDate)
|
||||
.AndWhere(h => h.Date <= endDate)
|
||||
.AndWhere(h => h.EventType == eventType);
|
||||
}
|
||||
|
||||
public List<History> Failed()
|
||||
{
|
||||
return Query.Where(h => h.EventType == HistoryEventType.DownloadFailed);
|
||||
}
|
||||
|
||||
public override PagingSpec<History> GetPaged(PagingSpec<History> pagingSpec)
|
||||
{
|
||||
pagingSpec.Records = GetPagedQuery(pagingSpec).ToList();
|
||||
|
||||
@@ -18,9 +18,11 @@ namespace NzbDrone.Core.History
|
||||
void Trim();
|
||||
QualityModel GetBestQualityInHistory(int episodeId);
|
||||
PagingSpec<History> Paged(PagingSpec<History> pagingSpec);
|
||||
List<History> BetweenDates(DateTime startDate, DateTime endDate, HistoryEventType eventType);
|
||||
List<History> Failed();
|
||||
}
|
||||
|
||||
public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>, IHandle<EpisodeImportedEvent>
|
||||
public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>, IHandle<EpisodeImportedEvent>, IHandle<DownloadFailedEvent>
|
||||
{
|
||||
private readonly IHistoryRepository _historyRepository;
|
||||
private readonly Logger _logger;
|
||||
@@ -41,6 +43,16 @@ namespace NzbDrone.Core.History
|
||||
return _historyRepository.GetPaged(pagingSpec);
|
||||
}
|
||||
|
||||
public List<History> BetweenDates(DateTime startDate, DateTime endDate, HistoryEventType eventType)
|
||||
{
|
||||
return _historyRepository.BetweenDates(startDate, endDate, eventType);
|
||||
}
|
||||
|
||||
public List<History> Failed()
|
||||
{
|
||||
return _historyRepository.Failed();
|
||||
}
|
||||
|
||||
public void Purge()
|
||||
{
|
||||
_historyRepository.Purge();
|
||||
@@ -51,7 +63,7 @@ namespace NzbDrone.Core.History
|
||||
_historyRepository.Trim();
|
||||
}
|
||||
|
||||
public virtual QualityModel GetBestQualityInHistory(int episodeId)
|
||||
public QualityModel GetBestQualityInHistory(int episodeId)
|
||||
{
|
||||
return _historyRepository.GetBestQualityInHistory(episodeId).OrderByDescending(q => q).FirstOrDefault();
|
||||
}
|
||||
@@ -107,5 +119,23 @@ namespace NzbDrone.Core.History
|
||||
_historyRepository.Insert(history);
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(DownloadFailedEvent message)
|
||||
{
|
||||
var history = new History
|
||||
{
|
||||
EventType = HistoryEventType.DownloadFailed,
|
||||
Date = DateTime.UtcNow,
|
||||
Quality = message.Quality,
|
||||
SourceTitle = message.SourceTitle,
|
||||
SeriesId = message.Series.Id,
|
||||
EpisodeId = message.Episode.Id,
|
||||
};
|
||||
|
||||
history.Data.Add("DownloadClient", message.DownloadClient);
|
||||
history.Data.Add("DownloadClientId", message.DownloadClientId);
|
||||
|
||||
_historyRepository.Insert(history);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user