mirror of
https://github.com/Radarr/Radarr
synced 2026-05-09 07:23:21 +02:00
New: Resolve download client by name using 'downloadClient' for pushed releases
(cherry picked from commit 0496e728dc1e21b16b9ee2fee010de9707bdff85)
This commit is contained in:
parent
437e2f4597
commit
2f2004faa2
2 changed files with 31 additions and 2 deletions
|
|
@ -21,6 +21,7 @@ public class ReleasePushController : ReleaseControllerBase
|
||||||
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
||||||
private readonly IProcessDownloadDecisions _downloadDecisionProcessor;
|
private readonly IProcessDownloadDecisions _downloadDecisionProcessor;
|
||||||
private readonly IIndexerFactory _indexerFactory;
|
private readonly IIndexerFactory _indexerFactory;
|
||||||
|
private readonly IDownloadClientFactory _downloadClientFactory;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
private static readonly object PushLock = new object();
|
private static readonly object PushLock = new object();
|
||||||
|
|
@ -28,6 +29,7 @@ public class ReleasePushController : ReleaseControllerBase
|
||||||
public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker,
|
public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker,
|
||||||
IProcessDownloadDecisions downloadDecisionProcessor,
|
IProcessDownloadDecisions downloadDecisionProcessor,
|
||||||
IIndexerFactory indexerFactory,
|
IIndexerFactory indexerFactory,
|
||||||
|
IDownloadClientFactory downloadClientFactory,
|
||||||
IQualityProfileService qualityProfileService,
|
IQualityProfileService qualityProfileService,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
: base(qualityProfileService)
|
: base(qualityProfileService)
|
||||||
|
|
@ -35,6 +37,7 @@ public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker,
|
||||||
_downloadDecisionMaker = downloadDecisionMaker;
|
_downloadDecisionMaker = downloadDecisionMaker;
|
||||||
_downloadDecisionProcessor = downloadDecisionProcessor;
|
_downloadDecisionProcessor = downloadDecisionProcessor;
|
||||||
_indexerFactory = indexerFactory;
|
_indexerFactory = indexerFactory;
|
||||||
|
_downloadClientFactory = downloadClientFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
PostValidator.RuleFor(s => s.Title).NotEmpty();
|
PostValidator.RuleFor(s => s.Title).NotEmpty();
|
||||||
|
|
@ -57,6 +60,8 @@ public ActionResult<List<ReleaseResource>> Create(ReleaseResource release)
|
||||||
|
|
||||||
ResolveIndexer(info);
|
ResolveIndexer(info);
|
||||||
|
|
||||||
|
var downloadClientId = ResolveDownloadClientId(release);
|
||||||
|
|
||||||
DownloadDecision decision;
|
DownloadDecision decision;
|
||||||
|
|
||||||
lock (PushLock)
|
lock (PushLock)
|
||||||
|
|
@ -65,12 +70,12 @@ public ActionResult<List<ReleaseResource>> Create(ReleaseResource release)
|
||||||
|
|
||||||
decision = decisions.FirstOrDefault();
|
decision = decisions.FirstOrDefault();
|
||||||
|
|
||||||
_downloadDecisionProcessor.ProcessDecision(decision, release.DownloadClientId).GetAwaiter().GetResult();
|
_downloadDecisionProcessor.ProcessDecision(decision, downloadClientId).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decision?.RemoteMovie.ParsedMovieInfo == null)
|
if (decision?.RemoteMovie.ParsedMovieInfo == null)
|
||||||
{
|
{
|
||||||
throw new ValidationException(new List<ValidationFailure> { new ValidationFailure("Title", "Unable to parse", release.Title) });
|
throw new ValidationException(new List<ValidationFailure> { new ("Title", "Unable to parse", release.Title) });
|
||||||
}
|
}
|
||||||
|
|
||||||
return MapDecisions(new[] { decision });
|
return MapDecisions(new[] { decision });
|
||||||
|
|
@ -110,5 +115,26 @@ private void ResolveIndexer(ReleaseInfo release)
|
||||||
_logger.Debug("Push Release {0} not associated with an indexer.", release.Title);
|
_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,9 @@ public class ReleaseResource : RestResource
|
||||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||||
public int? DownloadClientId { get; set; }
|
public int? DownloadClientId { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||||
|
public string DownloadClient { get; set; }
|
||||||
|
|
||||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||||
public bool? ShouldOverride { get; set; }
|
public bool? ShouldOverride { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue