-
-
Notifications
You must be signed in to change notification settings - Fork 242
/
RedownloadFailedDownloadService.cs
79 lines (65 loc) · 2.69 KB
/
RedownloadFailedDownloadService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using NLog;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Messaging;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Music;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Download
{
public class RedownloadFailedDownloadService : IHandle<DownloadFailedEvent>
{
private readonly IConfigService _configService;
private readonly IAlbumService _albumService;
private readonly IManageCommandQueue _commandQueueManager;
private readonly Logger _logger;
public RedownloadFailedDownloadService(IConfigService configService,
IAlbumService albumService,
IManageCommandQueue commandQueueManager,
Logger logger)
{
_configService = configService;
_albumService = albumService;
_commandQueueManager = commandQueueManager;
_logger = logger;
}
[EventHandleOrder(EventHandleOrder.Last)]
public void Handle(DownloadFailedEvent message)
{
if (message.SkipRedownload)
{
_logger.Debug("Skip redownloading requested by user");
return;
}
if (!_configService.AutoRedownloadFailed)
{
_logger.Debug("Auto redownloading failed albums is disabled");
return;
}
if (message.ReleaseSource == ReleaseSourceType.InteractiveSearch && !_configService.AutoRedownloadFailedFromInteractiveSearch)
{
_logger.Debug("Auto redownloading failed albums from interactive search is disabled");
return;
}
if (message.AlbumIds.Count == 1)
{
_logger.Debug("Failed download only contains one album, searching again");
_commandQueueManager.Push(new AlbumSearchCommand(message.AlbumIds));
return;
}
var albumsInArtist = _albumService.GetAlbumsByArtist(message.ArtistId);
if (message.AlbumIds.Count == albumsInArtist.Count)
{
_logger.Debug("Failed download was entire artist, searching again");
_commandQueueManager.Push(new ArtistSearchCommand
{
ArtistId = message.ArtistId
});
return;
}
_logger.Debug("Failed download contains multiple albums, searching again");
_commandQueueManager.Push(new AlbumSearchCommand(message.AlbumIds));
}
}
}