Add ContentSummary to BeyondHD requests

pull/1754/head
Bogdan 2 years ago
parent aed3f9f887
commit 34cd68fa07

@ -25,8 +25,7 @@ namespace NzbDrone.Core.Indexers.Definitions
public class BeyondHD : TorrentIndexerBase<BeyondHDSettings> public class BeyondHD : TorrentIndexerBase<BeyondHDSettings>
{ {
public override string Name => "BeyondHD"; public override string Name => "BeyondHD";
public override string[] IndexerUrls => new[] { "https://beyond-hd.me/" };
public override string[] IndexerUrls => new string[] { "https://beyond-hd.me/" };
public override string Description => "BeyondHD (BHD) is a Private Torrent Tracker for HD MOVIES / TV"; public override string Description => "BeyondHD (BHD) is a Private Torrent Tracker for HD MOVIES / TV";
public override IndexerPrivacy Privacy => IndexerPrivacy.Private; public override IndexerPrivacy Privacy => IndexerPrivacy.Private;
public override IndexerCapabilities Capabilities => SetCapabilities(); public override IndexerCapabilities Capabilities => SetCapabilities();
@ -38,12 +37,12 @@ namespace NzbDrone.Core.Indexers.Definitions
public override IIndexerRequestGenerator GetRequestGenerator() public override IIndexerRequestGenerator GetRequestGenerator()
{ {
return new BeyondHDRequestGenerator() { Settings = Settings, Capabilities = Capabilities }; return new BeyondHDRequestGenerator(Settings, Capabilities);
} }
public override IParseIndexerResponse GetParser() public override IParseIndexerResponse GetParser()
{ {
return new BeyondHDParser(Settings, Capabilities.Categories); return new BeyondHDParser(Capabilities.Categories);
} }
private IndexerCapabilities SetCapabilities() private IndexerCapabilities SetCapabilities()
@ -69,15 +68,21 @@ namespace NzbDrone.Core.Indexers.Definitions
public class BeyondHDRequestGenerator : IIndexerRequestGenerator public class BeyondHDRequestGenerator : IIndexerRequestGenerator
{ {
public BeyondHDSettings Settings { get; set; } private readonly BeyondHDSettings _settings;
public IndexerCapabilities Capabilities { get; set; } private readonly IndexerCapabilities _capabilities;
public BeyondHDRequestGenerator(BeyondHDSettings settings, IndexerCapabilities capabilities)
{
_settings = settings;
_capabilities = capabilities;
}
private IEnumerable<IndexerRequest> GetPagedRequests(string term, int[] categories, string imdbId = null, int tmdbId = 0) private IEnumerable<IndexerRequest> GetPagedRequests(string term, int[] categories, string imdbId = null, int tmdbId = 0)
{ {
var body = new Dictionary<string, object> var body = new Dictionary<string, object>
{ {
{ "action", "search" }, { "action", "search" },
{ "rsskey", Settings.RssKey } { "rsskey", _settings.RssKey }
}; };
if (imdbId.IsNotNullOrWhiteSpace()) if (imdbId.IsNotNullOrWhiteSpace())
@ -95,31 +100,34 @@ namespace NzbDrone.Core.Indexers.Definitions
body.Add("search", term); body.Add("search", term);
} }
var cats = Capabilities.Categories.MapTorznabCapsToTrackers(categories); var cats = _capabilities.Categories.MapTorznabCapsToTrackers(categories);
if (cats.Count > 0) if (cats.Count > 0)
{ {
body.Add("categories", string.Join(",", cats)); body.Add("categories", string.Join(",", cats));
} }
var searchUrl = Settings.BaseUrl + "api/torrents/" + Settings.ApiKey; var searchUrl = $"{_settings.BaseUrl}api/torrents/{_settings.ApiKey}";
var request = new HttpRequest(searchUrl, HttpAccept.Json); var request = new HttpRequest(searchUrl, HttpAccept.Json)
{
request.Headers.ContentType = "application/json"; Headers =
request.Method = HttpMethod.Post; {
ContentType = "application/json"
},
Method = HttpMethod.Post
};
request.SetContent(body.ToJson()); request.SetContent(body.ToJson());
request.ContentSummary = body.ToJson(Formatting.None);
var indexerRequest = new IndexerRequest(request); yield return new IndexerRequest(request);
yield return indexerRequest;
} }
public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria) public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria)
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(string.Format("{0}", searchCriteria.SanitizedSearchTerm), searchCriteria.Categories, searchCriteria.FullImdbId, searchCriteria.TmdbId.GetValueOrDefault())); pageableRequests.Add(GetPagedRequests(searchCriteria.SanitizedSearchTerm, searchCriteria.Categories, searchCriteria.FullImdbId, searchCriteria.TmdbId.GetValueOrDefault()));
return pageableRequests; return pageableRequests;
} }
@ -128,7 +136,7 @@ namespace NzbDrone.Core.Indexers.Definitions
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(string.Format("{0}", searchCriteria.SanitizedSearchTerm), searchCriteria.Categories)); pageableRequests.Add(GetPagedRequests(searchCriteria.SanitizedSearchTerm, searchCriteria.Categories));
return pageableRequests; return pageableRequests;
} }
@ -137,7 +145,7 @@ namespace NzbDrone.Core.Indexers.Definitions
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(string.Format("{0}", searchCriteria.SanitizedTvSearchString), searchCriteria.Categories, searchCriteria.FullImdbId)); pageableRequests.Add(GetPagedRequests(searchCriteria.SanitizedTvSearchString, searchCriteria.Categories, searchCriteria.FullImdbId));
return pageableRequests; return pageableRequests;
} }
@ -146,7 +154,7 @@ namespace NzbDrone.Core.Indexers.Definitions
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(string.Format("{0}", searchCriteria.SanitizedSearchTerm), searchCriteria.Categories)); pageableRequests.Add(GetPagedRequests(searchCriteria.SanitizedSearchTerm, searchCriteria.Categories));
return pageableRequests; return pageableRequests;
} }
@ -155,7 +163,7 @@ namespace NzbDrone.Core.Indexers.Definitions
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(string.Format("{0}", searchCriteria.SanitizedSearchTerm), searchCriteria.Categories)); pageableRequests.Add(GetPagedRequests(searchCriteria.SanitizedSearchTerm, searchCriteria.Categories));
return pageableRequests; return pageableRequests;
} }
@ -166,19 +174,17 @@ namespace NzbDrone.Core.Indexers.Definitions
public class BeyondHDParser : IParseIndexerResponse public class BeyondHDParser : IParseIndexerResponse
{ {
private readonly BeyondHDSettings _settings;
private readonly IndexerCapabilitiesCategories _categories; private readonly IndexerCapabilitiesCategories _categories;
public BeyondHDParser(BeyondHDSettings settings, IndexerCapabilitiesCategories categories) public BeyondHDParser(IndexerCapabilitiesCategories categories)
{ {
_settings = settings;
_categories = categories; _categories = categories;
} }
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse) public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
{ {
var torrentInfos = new List<TorrentInfo>();
var indexerHttpResponse = indexerResponse.HttpResponse; var indexerHttpResponse = indexerResponse.HttpResponse;
if (indexerHttpResponse.StatusCode != HttpStatusCode.OK) if (indexerHttpResponse.StatusCode != HttpStatusCode.OK)
{ {
throw new IndexerException(indexerResponse, $"Unexpected response status {indexerHttpResponse.StatusCode} code from indexer request"); throw new IndexerException(indexerResponse, $"Unexpected response status {indexerHttpResponse.StatusCode} code from indexer request");
@ -201,6 +207,8 @@ namespace NzbDrone.Core.Indexers.Definitions
throw new IndexerException(indexerResponse, $"Indexer Error: {jsonResponse.Resource.StatusMessage}"); throw new IndexerException(indexerResponse, $"Indexer Error: {jsonResponse.Resource.StatusMessage}");
} }
var releaseInfos = new List<ReleaseInfo>();
foreach (var row in jsonResponse.Resource.Results) foreach (var row in jsonResponse.Resource.Results)
{ {
var details = row.InfoUrl; var details = row.InfoUrl;
@ -231,11 +239,13 @@ namespace NzbDrone.Core.Indexers.Definitions
MinimumSeedTime = 172800, // 120 hours MinimumSeedTime = 172800, // 120 hours
}; };
torrentInfos.Add(release); releaseInfos.Add(release);
} }
// order by date // order by date
return torrentInfos.OrderByDescending(o => o.PublishDate).ToArray(); return releaseInfos
.OrderByDescending(o => o.PublishDate)
.ToArray();
} }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; } public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }

Loading…
Cancel
Save