mirror of
https://github.com/lidarr/Lidarr
synced 2025-01-03 13:34:54 +00:00
New: Resolve download client by name using 'downloadClient' for pushed releases
Closes #4279
This commit is contained in:
parent
a82a1d46ae
commit
bee2b44918
2 changed files with 30 additions and 1 deletions
|
@ -21,6 +21,7 @@ public class ReleasePushController : ReleaseControllerBase
|
|||
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
||||
private readonly IProcessDownloadDecisions _downloadDecisionProcessor;
|
||||
private readonly IIndexerFactory _indexerFactory;
|
||||
private readonly IDownloadClientFactory _downloadClientFactory;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private static readonly object PushLock = new object();
|
||||
|
@ -28,6 +29,7 @@ public class ReleasePushController : ReleaseControllerBase
|
|||
public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker,
|
||||
IProcessDownloadDecisions downloadDecisionProcessor,
|
||||
IIndexerFactory indexerFactory,
|
||||
IDownloadClientFactory downloadClientFactory,
|
||||
IQualityProfileService qualityProfileService,
|
||||
Logger logger)
|
||||
: base(qualityProfileService)
|
||||
|
@ -35,6 +37,7 @@ public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker,
|
|||
_downloadDecisionMaker = downloadDecisionMaker;
|
||||
_downloadDecisionProcessor = downloadDecisionProcessor;
|
||||
_indexerFactory = indexerFactory;
|
||||
_downloadClientFactory = downloadClientFactory;
|
||||
_logger = logger;
|
||||
|
||||
PostValidator.RuleFor(s => s.Title).NotEmpty();
|
||||
|
@ -56,6 +59,8 @@ public ActionResult<ReleaseResource> Create(ReleaseResource release)
|
|||
|
||||
ResolveIndexer(info);
|
||||
|
||||
var downloadClientId = ResolveDownloadClientId(release);
|
||||
|
||||
DownloadDecision decision;
|
||||
|
||||
lock (PushLock)
|
||||
|
@ -64,7 +69,7 @@ public ActionResult<ReleaseResource> Create(ReleaseResource release)
|
|||
|
||||
decision = decisions.FirstOrDefault();
|
||||
|
||||
_downloadDecisionProcessor.ProcessDecision(decision, release.DownloadClientId).GetAwaiter().GetResult();
|
||||
_downloadDecisionProcessor.ProcessDecision(decision, downloadClientId).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
if (decision?.RemoteAlbum.ParsedAlbumInfo == null)
|
||||
|
@ -109,5 +114,26 @@ private void ResolveIndexer(ReleaseInfo release)
|
|||
_logger.Debug("Push Release {0} not associated with an indexer.", release.Title);
|
||||
}
|
||||
}
|
||||
|
||||
private int? ResolveDownloadClientId(ReleaseResource release)
|
||||
{
|
||||
var downloadClientId = release.DownloadClientId.GetValueOrDefault();
|
||||
|
||||
if (downloadClientId == 0 && release.DownloadClient.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
var downloadClient = _downloadClientFactory.All().FirstOrDefault(v => v.Name.EqualsIgnoreCase(release.DownloadClient));
|
||||
|
||||
if (downloadClient != null)
|
||||
{
|
||||
_logger.Debug("Push Release {0} associated with download client {1} - {2}.", release.Title, downloadClientId, release.DownloadClient);
|
||||
|
||||
return downloadClient.Id;
|
||||
}
|
||||
|
||||
_logger.Debug("Push Release {0} not associated with known download client {1}.", release.Title, release.DownloadClient);
|
||||
}
|
||||
|
||||
return release.DownloadClientId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,9 @@ public class ReleaseResource : RestResource
|
|||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public int? DownloadClientId { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public string DownloadClient { get; set; }
|
||||
}
|
||||
|
||||
public static class ReleaseResourceMapper
|
||||
|
|
Loading…
Reference in a new issue