mirror of https://github.com/lidarr/Lidarr
Refactor ReDownload Failed Service (#52)
Refactor ReDownload Failed Service
This commit is contained in:
parent
025534cf71
commit
fcffd5461e
|
@ -12,11 +12,7 @@ namespace NzbDrone.Core.Download
|
||||||
Data = new Dictionary<string, string>();
|
Data = new Dictionary<string, string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Obsolete("Used for sonarr, not lidarr")]
|
|
||||||
public int SeriesId { get; set; }
|
|
||||||
public int ArtistId { get; set; }
|
public int ArtistId { get; set; }
|
||||||
[System.Obsolete("Used for sonarr, not lidarr")]
|
|
||||||
public List<int> EpisodeIds { get; set; }
|
|
||||||
public List<int> AlbumIds { get; set; }
|
public List<int> AlbumIds { get; set; }
|
||||||
public QualityModel Quality { get; set; }
|
public QualityModel Quality { get; set; }
|
||||||
public string SourceTitle { get; set; }
|
public string SourceTitle { get; set; }
|
||||||
|
|
|
@ -4,24 +4,24 @@ using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.IndexerSearch;
|
using NzbDrone.Core.IndexerSearch;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
using NzbDrone.Core.Messaging.Commands;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Music;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download
|
namespace NzbDrone.Core.Download
|
||||||
{
|
{
|
||||||
public class RedownloadFailedDownloadService : IHandleAsync<DownloadFailedEvent>
|
public class RedownloadFailedDownloadService : IHandleAsync<DownloadFailedEvent>
|
||||||
{
|
{
|
||||||
private readonly IConfigService _configService;
|
private readonly IConfigService _configService;
|
||||||
private readonly IEpisodeService _episodeService;
|
private readonly IAlbumService _albumService;
|
||||||
private readonly IManageCommandQueue _commandQueueManager;
|
private readonly IManageCommandQueue _commandQueueManager;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public RedownloadFailedDownloadService(IConfigService configService,
|
public RedownloadFailedDownloadService(IConfigService configService,
|
||||||
IEpisodeService episodeService,
|
IAlbumService albumService,
|
||||||
IManageCommandQueue commandQueueManager,
|
IManageCommandQueue commandQueueManager,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
_episodeService = episodeService;
|
_albumService = albumService;
|
||||||
_commandQueueManager = commandQueueManager;
|
_commandQueueManager = commandQueueManager;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
@ -30,38 +30,36 @@ namespace NzbDrone.Core.Download
|
||||||
{
|
{
|
||||||
if (!_configService.AutoRedownloadFailed)
|
if (!_configService.AutoRedownloadFailed)
|
||||||
{
|
{
|
||||||
_logger.Debug("Auto redownloading failed episodes is disabled");
|
_logger.Debug("Auto redownloading failed albums is disabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.EpisodeIds.Count == 1)
|
if (message.AlbumIds.Count == 1)
|
||||||
{
|
{
|
||||||
_logger.Debug("Failed download only contains one episode, searching again");
|
_logger.Debug("Failed download only contains one album, searching again");
|
||||||
|
|
||||||
_commandQueueManager.Push(new EpisodeSearchCommand(message.EpisodeIds));
|
_commandQueueManager.Push(new AlbumSearchCommand(message.AlbumIds));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var seasonNumber = _episodeService.GetEpisode(message.EpisodeIds.First()).SeasonNumber;
|
var albumsInArtist = _albumService.GetAlbumsByArtist(message.ArtistId);
|
||||||
var episodesInSeason = _episodeService.GetEpisodesBySeason(message.SeriesId, seasonNumber);
|
|
||||||
|
|
||||||
if (message.EpisodeIds.Count == episodesInSeason.Count)
|
if (message.AlbumIds.Count == albumsInArtist.Count)
|
||||||
{
|
{
|
||||||
_logger.Debug("Failed download was entire season, searching again");
|
_logger.Debug("Failed download was entire artist, searching again");
|
||||||
|
|
||||||
_commandQueueManager.Push(new SeasonSearchCommand
|
_commandQueueManager.Push(new ArtistSearchCommand
|
||||||
{
|
{
|
||||||
SeriesId = message.SeriesId,
|
ArtistId = message.ArtistId
|
||||||
SeasonNumber = seasonNumber
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Debug("Failed download contains multiple episodes, probably a double episode, searching again");
|
_logger.Debug("Failed download contains multiple albums, searching again");
|
||||||
|
|
||||||
_commandQueueManager.Push(new EpisodeSearchCommand(message.EpisodeIds));
|
_commandQueueManager.Push(new AlbumSearchCommand(message.AlbumIds));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,7 @@ namespace NzbDrone.Core.History
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete("Used for Sonarr, not Lidarr")]
|
||||||
private string FindDownloadId(EpisodeImportedEvent trackedDownload)
|
private string FindDownloadId(EpisodeImportedEvent trackedDownload)
|
||||||
{
|
{
|
||||||
_logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedEpisode.Path);
|
_logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedEpisode.Path);
|
||||||
|
@ -170,6 +171,7 @@ namespace NzbDrone.Core.History
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete("Used for Sonarr, not Lidarr")]
|
||||||
public void Handle(EpisodeImportedEvent message)
|
public void Handle(EpisodeImportedEvent message)
|
||||||
{
|
{
|
||||||
if (!message.NewDownload)
|
if (!message.NewDownload)
|
||||||
|
@ -217,7 +219,7 @@ namespace NzbDrone.Core.History
|
||||||
Date = DateTime.UtcNow,
|
Date = DateTime.UtcNow,
|
||||||
Quality = message.Quality,
|
Quality = message.Quality,
|
||||||
SourceTitle = message.SourceTitle,
|
SourceTitle = message.SourceTitle,
|
||||||
ArtistId = message.SeriesId,
|
ArtistId = message.ArtistId,
|
||||||
AlbumId = albumId,
|
AlbumId = albumId,
|
||||||
DownloadId = message.DownloadId
|
DownloadId = message.DownloadId
|
||||||
};
|
};
|
||||||
|
@ -229,6 +231,7 @@ namespace NzbDrone.Core.History
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete("Used for Sonarr, not Lidarr")]
|
||||||
public void Handle(EpisodeFileDeletedEvent message)
|
public void Handle(EpisodeFileDeletedEvent message)
|
||||||
{
|
{
|
||||||
if (message.Reason == DeleteMediaFileReason.NoLinkedEpisodes)
|
if (message.Reason == DeleteMediaFileReason.NoLinkedEpisodes)
|
||||||
|
|
Loading…
Reference in New Issue