Skip to content

Commit

Permalink
Add flag to migrate bitwise indexer flags
Browse files Browse the repository at this point in the history
To be reverted in v6
  • Loading branch information
mynameisbogdan committed May 6, 2024
1 parent d5ffb7a commit 407eb54
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function MovieInteractiveSearchModalContent(props) {

<ModalBody scrollDirection={scrollDirections.BOTH}>
<InteractiveSearchConnector
searchPayload={{ movieId }}
searchPayload={{ movieId, bitwiseIndexerFlags: true }}
/>
</ModalBody>

Expand Down
18 changes: 9 additions & 9 deletions src/Radarr.Api.V3/Indexers/ReleaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,24 @@ public async Task<object> DownloadRelease([FromBody] ReleaseResource release)

[HttpGet]
[Produces("application/json")]
public async Task<List<ReleaseResource>> GetReleases(int? movieId)
public async Task<List<ReleaseResource>> GetReleases(int? movieId, bool bitwiseIndexerFlags = false)
{
if (movieId.HasValue)
{
return await GetMovieReleases(movieId.Value);
return await GetMovieReleases(movieId.Value, bitwiseIndexerFlags);
}

return await GetRss();
return await GetRss(bitwiseIndexerFlags);
}

private async Task<List<ReleaseResource>> GetMovieReleases(int movieId)
private async Task<List<ReleaseResource>> GetMovieReleases(int movieId, bool bitwiseIndexerFlags)
{
try
{
var decisions = await _releaseSearchService.MovieSearch(movieId, true, true);
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisionsForMovies(decisions);

return MapDecisions(prioritizedDecisions);
return MapDecisions(prioritizedDecisions, bitwiseIndexerFlags);
}
catch (SearchFailedException ex)
{
Expand All @@ -155,18 +155,18 @@ private async Task<List<ReleaseResource>> GetMovieReleases(int movieId)
}
}

private async Task<List<ReleaseResource>> GetRss()
private async Task<List<ReleaseResource>> GetRss(bool bitwiseIndexerFlags)
{
var reports = await _rssFetcherAndParser.Fetch();
var decisions = _downloadDecisionMaker.GetRssDecision(reports);
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisionsForMovies(decisions);

return MapDecisions(prioritizedDecisions);
return MapDecisions(prioritizedDecisions, bitwiseIndexerFlags);
}

protected override ReleaseResource MapDecision(DownloadDecision decision, int initialWeight)
protected override ReleaseResource MapDecision(DownloadDecision decision, int initialWeight, bool bitwiseIndexerFlags)
{
var resource = base.MapDecision(decision, initialWeight);
var resource = base.MapDecision(decision, initialWeight, bitwiseIndexerFlags);
_remoteMovieCache.Set(GetCacheKey(resource), decision.RemoteMovie, TimeSpan.FromMinutes(30));

return resource;
Expand Down
8 changes: 4 additions & 4 deletions src/Radarr.Api.V3/Indexers/ReleaseControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ protected override ReleaseResource GetResourceById(int id)
throw new NotImplementedException();
}

protected virtual List<ReleaseResource> MapDecisions(IEnumerable<DownloadDecision> decisions)
protected virtual List<ReleaseResource> MapDecisions(IEnumerable<DownloadDecision> decisions, bool bitwiseIndexerFlags)
{
var result = new List<ReleaseResource>();

foreach (var downloadDecision in decisions)
{
var release = MapDecision(downloadDecision, result.Count);
var release = MapDecision(downloadDecision, result.Count, bitwiseIndexerFlags);

result.Add(release);
}

return result;
}

protected virtual ReleaseResource MapDecision(DownloadDecision decision, int initialWeight)
protected virtual ReleaseResource MapDecision(DownloadDecision decision, int initialWeight, bool bitwiseIndexerFlags)
{
var release = decision.ToResource();
var release = decision.ToResource(bitwiseIndexerFlags);

release.ReleaseWeight = initialWeight;

Expand Down
4 changes: 2 additions & 2 deletions src/Radarr.Api.V3/Indexers/ReleasePushController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class ReleasePushController : ReleaseControllerBase

[HttpPost]
[Consumes("application/json")]
public ActionResult<List<ReleaseResource>> Create([FromBody] ReleaseResource release)
public ActionResult<List<ReleaseResource>> Create([FromBody] ReleaseResource release, [FromQuery] bool bitwiseIndexerFlags = false)
{
_logger.Info("Release pushed: {0} - {1}", release.Title, release.DownloadUrl ?? release.MagnetUrl);

Expand Down Expand Up @@ -79,7 +79,7 @@ public ActionResult<List<ReleaseResource>> Create([FromBody] ReleaseResource rel
throw new ValidationException(new List<ValidationFailure> { new ("Title", "Unable to parse", release.Title) });
}

return MapDecisions(new[] { decision });
return MapDecisions(new[] { decision }, bitwiseIndexerFlags);
}

private void ResolveIndexer(ReleaseInfo release)
Expand Down
10 changes: 6 additions & 4 deletions src/Radarr.Api.V3/Indexers/ReleaseResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ReleaseResource : RestResource
public int? Seeders { get; set; }
public int? Leechers { get; set; }
public DownloadProtocol Protocol { get; set; }
public int IndexerFlags { get; set; }
public dynamic IndexerFlags { get; set; }

// Sent when queuing an unknown release
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
Expand All @@ -70,13 +70,15 @@ public class ReleaseResource : RestResource

public static class ReleaseResourceMapper
{
public static ReleaseResource ToResource(this DownloadDecision model)
public static ReleaseResource ToResource(this DownloadDecision model, bool bitwiseIndexerFlags = false)
{
var releaseInfo = model.RemoteMovie.Release;
var parsedMovieInfo = model.RemoteMovie.ParsedMovieInfo;
var remoteMovie = model.RemoteMovie;
var torrentInfo = (model.RemoteMovie.Release as TorrentInfo) ?? new TorrentInfo();
var indexerFlags = torrentInfo.IndexerFlags;

// TODO: REMOVE IN v6
dynamic indexerFlags = bitwiseIndexerFlags ? (int)torrentInfo.IndexerFlags : torrentInfo.IndexerFlags.ToString().Split(new[] { ", " }, StringSplitOptions.None).Where(x => x != "0");

// TODO: Clean this mess up. don't mix data from multiple classes, use sub-resources instead? (Got a huge Deja Vu, didn't we talk about this already once?)
return new ReleaseResource
Expand Down Expand Up @@ -118,7 +120,7 @@ public static ReleaseResource ToResource(this DownloadDecision model)
Seeders = torrentInfo.Seeders,
Leechers = (torrentInfo.Peers.HasValue && torrentInfo.Seeders.HasValue) ? (torrentInfo.Peers.Value - torrentInfo.Seeders.Value) : (int?)null,
Protocol = releaseInfo.DownloadProtocol,
IndexerFlags = (int)indexerFlags
IndexerFlags = indexerFlags
};
}

Expand Down

0 comments on commit 407eb54

Please sign in to comment.