Skip to content

Commit

Permalink
New: Resolve download client by name using 'downloadClient' for pushe…
Browse files Browse the repository at this point in the history
…d releases

Closes #4279
  • Loading branch information
mynameisbogdan committed Jan 12, 2024
1 parent a82a1d4 commit bee2b44
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Lidarr.Api.V1/Indexers/ReleasePushController.cs
Expand Up @@ -21,20 +21,23 @@ 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();

public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker,
IProcessDownloadDecisions downloadDecisionProcessor,
IIndexerFactory indexerFactory,
IDownloadClientFactory downloadClientFactory,
IQualityProfileService qualityProfileService,
Logger logger)
: base(qualityProfileService)
{
_downloadDecisionMaker = downloadDecisionMaker;
_downloadDecisionProcessor = downloadDecisionProcessor;
_indexerFactory = indexerFactory;
_downloadClientFactory = downloadClientFactory;
_logger = logger;

PostValidator.RuleFor(s => s.Title).NotEmpty();
Expand All @@ -56,6 +59,8 @@ public ActionResult<ReleaseResource> Create(ReleaseResource release)

ResolveIndexer(info);

var downloadClientId = ResolveDownloadClientId(release);

DownloadDecision decision;

lock (PushLock)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
}
}
3 changes: 3 additions & 0 deletions src/Lidarr.Api.V1/Indexers/ReleaseResource.cs
Expand Up @@ -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
Expand Down

0 comments on commit bee2b44

Please sign in to comment.