Refactor ReDownload Failed Service (#52)

Refactor ReDownload Failed Service
This commit is contained in:
Qstick 2017-08-17 21:28:35 -04:00 committed by GitHub
parent 025534cf71
commit fcffd5461e
3 changed files with 19 additions and 22 deletions

View File

@ -12,11 +12,7 @@ namespace NzbDrone.Core.Download
Data = new Dictionary<string, string>();
}
[System.Obsolete("Used for sonarr, not lidarr")]
public int SeriesId { 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 QualityModel Quality { get; set; }
public string SourceTitle { get; set; }

View File

@ -4,24 +4,24 @@ using NzbDrone.Core.Configuration;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Music;
namespace NzbDrone.Core.Download
{
public class RedownloadFailedDownloadService : IHandleAsync<DownloadFailedEvent>
{
private readonly IConfigService _configService;
private readonly IEpisodeService _episodeService;
private readonly IAlbumService _albumService;
private readonly IManageCommandQueue _commandQueueManager;
private readonly Logger _logger;
public RedownloadFailedDownloadService(IConfigService configService,
IEpisodeService episodeService,
IAlbumService albumService,
IManageCommandQueue commandQueueManager,
Logger logger)
{
_configService = configService;
_episodeService = episodeService;
_albumService = albumService;
_commandQueueManager = commandQueueManager;
_logger = logger;
}
@ -30,38 +30,36 @@ namespace NzbDrone.Core.Download
{
if (!_configService.AutoRedownloadFailed)
{
_logger.Debug("Auto redownloading failed episodes is disabled");
_logger.Debug("Auto redownloading failed albums is disabled");
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;
}
var seasonNumber = _episodeService.GetEpisode(message.EpisodeIds.First()).SeasonNumber;
var episodesInSeason = _episodeService.GetEpisodesBySeason(message.SeriesId, seasonNumber);
var albumsInArtist = _albumService.GetAlbumsByArtist(message.ArtistId);
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,
SeasonNumber = seasonNumber
ArtistId = message.ArtistId
});
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));
}
}
}

View File

@ -81,6 +81,7 @@ namespace NzbDrone.Core.History
.FirstOrDefault();
}
[Obsolete("Used for Sonarr, not Lidarr")]
private string FindDownloadId(EpisodeImportedEvent trackedDownload)
{
_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)
{
if (!message.NewDownload)
@ -217,7 +219,7 @@ namespace NzbDrone.Core.History
Date = DateTime.UtcNow,
Quality = message.Quality,
SourceTitle = message.SourceTitle,
ArtistId = message.SeriesId,
ArtistId = message.ArtistId,
AlbumId = albumId,
DownloadId = message.DownloadId
};
@ -229,6 +231,7 @@ namespace NzbDrone.Core.History
}
}
[Obsolete("Used for Sonarr, not Lidarr")]
public void Handle(EpisodeFileDeletedEvent message)
{
if (message.Reason == DeleteMediaFileReason.NoLinkedEpisodes)