From fcffd5461e434d5309926a46d8e66b420c9823f3 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 17 Aug 2017 21:28:35 -0400 Subject: [PATCH] Refactor ReDownload Failed Service (#52) Refactor ReDownload Failed Service --- .../Download/DownloadFailedEvent.cs | 4 --- .../RedownloadFailedDownloadService.cs | 32 +++++++++---------- src/NzbDrone.Core/History/HistoryService.cs | 5 ++- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/NzbDrone.Core/Download/DownloadFailedEvent.cs b/src/NzbDrone.Core/Download/DownloadFailedEvent.cs index 47e2d6349..680000d8f 100644 --- a/src/NzbDrone.Core/Download/DownloadFailedEvent.cs +++ b/src/NzbDrone.Core/Download/DownloadFailedEvent.cs @@ -12,11 +12,7 @@ namespace NzbDrone.Core.Download Data = new Dictionary(); } - [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 EpisodeIds { get; set; } public List AlbumIds { get; set; } public QualityModel Quality { get; set; } public string SourceTitle { get; set; } diff --git a/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs b/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs index d85729775..9519c1c96 100644 --- a/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs @@ -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 { 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)); } } } diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index eb4095f4c..2f5707346 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -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)