Skip to content

Commit

Permalink
Minor cleanup for BTN
Browse files Browse the repository at this point in the history
  • Loading branch information
mynameisbogdan committed Nov 28, 2023
1 parent fdaca64 commit 9dc1171
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 42 deletions.
Expand Up @@ -27,18 +27,7 @@ public BroadcastheNet(IIndexerHttpClient httpClient, IEventAggregator eventAggre

public override IIndexerRequestGenerator GetRequestGenerator()
{
var requestGenerator = new BroadcastheNetRequestGenerator { Settings = Settings, PageSize = PageSize, Capabilities = Capabilities };

var releaseInfo = _indexerStatusService.GetLastRssSyncReleaseInfo(Definition.Id);
if (releaseInfo != null)
{
if (int.TryParse(releaseInfo.Guid.Replace("BTN-", string.Empty), out var torrentId))
{
requestGenerator.LastRecentTorrentID = torrentId;
}
}

return requestGenerator;
return new BroadcastheNetRequestGenerator { Settings = Settings, Capabilities = Capabilities, PageSize = PageSize };
}

public override IParseIndexerResponse GetParser()
Expand All @@ -62,7 +51,7 @@ private IndexerCapabilities SetCapabilities()
caps.Categories.AddCategoryMapping("720p", NewznabStandardCategory.TVHD, "720p");
caps.Categories.AddCategoryMapping("1080p", NewznabStandardCategory.TVHD, "1080p");
caps.Categories.AddCategoryMapping("1080i", NewznabStandardCategory.TVHD, "1080i");
caps.Categories.AddCategoryMapping("2160p", NewznabStandardCategory.TVHD, "2160p");
caps.Categories.AddCategoryMapping("2160p", NewznabStandardCategory.TVUHD, "2160p");
caps.Categories.AddCategoryMapping("Portable Device", NewznabStandardCategory.TVSD, "Portable Device");

return caps;
Expand Down
Expand Up @@ -138,9 +138,7 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)

private string CleanReleaseName(string releaseName)
{
releaseName = releaseName.Replace("\\", "");

return releaseName;
return releaseName.Replace("\\", "");
}
}
}
Expand Up @@ -9,31 +9,13 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet
{
public class BroadcastheNetRequestGenerator : IIndexerRequestGenerator
{
public int MaxPages { get; set; }
public int PageSize { get; set; }
public BroadcastheNetSettings Settings { get; set; }
public IndexerCapabilities Capabilities { get; set; }

public int? LastRecentTorrentID { get; set; }
public int PageSize { get; set; }

public Func<IDictionary<string, string>> GetCookies { get; set; }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }

public BroadcastheNetRequestGenerator()
{
MaxPages = 10;
PageSize = 100;
}

private IEnumerable<IndexerRequest> GetPagedRequests(BroadcastheNetTorrentQuery parameters, int results, int offset)
{
var builder = new JsonRpcRequestBuilder(Settings.BaseUrl)
.Call("getTorrents", Settings.ApiKey, parameters, results, offset);
builder.SuppressHttpError = true;

yield return new IndexerRequest(builder.Build());
}

public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria)
{
return new IndexerPageableRequestChain();
Expand Down Expand Up @@ -132,11 +114,24 @@ public IndexerPageableRequestChain GetSearchRequests(BasicSearchCriteria searchC

var btnOffset = searchCriteria.Offset.GetValueOrDefault(0);

parameters.Search = searchString.Replace(" ", "%");
if (searchString.IsNotNullOrWhiteSpace())
{
parameters.Search = searchString.Replace(" ", "%");
}

pageableRequests.Add(GetPagedRequests(parameters, btnResults, btnOffset));

return pageableRequests;
}

private IEnumerable<IndexerRequest> GetPagedRequests(BroadcastheNetTorrentQuery parameters, int results, int offset)
{
var builder = new JsonRpcRequestBuilder(Settings.BaseUrl)
.Call("getTorrents", Settings.ApiKey, parameters, results, offset);

builder.SuppressHttpError = true;

yield return new IndexerRequest(builder.Build());
}
}
}
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace NzbDrone.Core.Indexers.BroadcastheNet
{
Expand All @@ -13,15 +14,15 @@ public class BroadcastheNetTorrentQuery
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Search { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Codec { get; set; }
public IEnumerable<string> Codec { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Container { get; set; }
public IEnumerable<string> Container { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Source { get; set; }
public IEnumerable<string> Source { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Resolution { get; set; }
public IEnumerable<string> Resolution { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Origin { get; set; }
public IEnumerable<string> Origin { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Hash { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
Expand Down

0 comments on commit 9dc1171

Please sign in to comment.