New: (HDBits) Add pagination support

pull/1920/head
Bogdan 1 year ago
parent ccdad3a44c
commit bd0609639e

@ -12,9 +12,10 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
public override string[] LegacyUrls => new[] { "https://hdbits.org" };
public override string Description => "Best HD Tracker";
public override IndexerPrivacy Privacy => IndexerPrivacy.Private;
public override IndexerCapabilities Capabilities => SetCapabilities();
public override bool SupportsRedirect => true;
public override int PageSize => 30;
public override bool SupportsPagination => true;
public override int PageSize => 100;
public override IndexerCapabilities Capabilities => SetCapabilities();
public HDBits(IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IConfigService configService, Logger logger)
: base(httpClient, eventAggregator, indexerStatusService, configService, logger)
@ -45,14 +46,14 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
}
};
caps.Categories.AddCategoryMapping(6, NewznabStandardCategory.Audio, "Audio Track");
caps.Categories.AddCategoryMapping(3, NewznabStandardCategory.TVDocumentary, "Documentary");
caps.Categories.AddCategoryMapping(8, NewznabStandardCategory.Other, "Misc/Demo");
caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.Movies, "Movie");
caps.Categories.AddCategoryMapping(2, NewznabStandardCategory.TV, "TV");
caps.Categories.AddCategoryMapping(3, NewznabStandardCategory.TVDocumentary, "Documentary");
caps.Categories.AddCategoryMapping(4, NewznabStandardCategory.Audio, "Music");
caps.Categories.AddCategoryMapping(5, NewznabStandardCategory.TVSport, "Sport");
caps.Categories.AddCategoryMapping(2, NewznabStandardCategory.TV, "TV");
caps.Categories.AddCategoryMapping(6, NewznabStandardCategory.Audio, "Audio Track");
caps.Categories.AddCategoryMapping(7, NewznabStandardCategory.XXX, "XXX");
caps.Categories.AddCategoryMapping(8, NewznabStandardCategory.Other, "Misc/Demo");
return caps;
}

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace NzbDrone.Core.Indexers.Definitions.HDBits
@ -7,19 +8,15 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
{
[JsonProperty(Required = Required.Always)]
public string Username { get; set; }
[JsonProperty(Required = Required.Always)]
public string Passkey { get; set; }
public string Hash { get; set; }
public string Search { get; set; }
public int[] Category { get; set; }
public int[] Codec { get; set; }
public int[] Medium { get; set; }
public IEnumerable<int> Category { get; set; }
public IEnumerable<int> Codec { get; set; }
public IEnumerable<int> Medium { get; set; }
public int? Origin { get; set; }
[JsonProperty(PropertyName = "imdb")]
@ -33,13 +30,9 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
[JsonProperty(PropertyName = "snatched_only")]
public bool? SnatchedOnly { get; set; }
public int? Limit { get; set; }
public int? Page { get; set; }
public TorrentQuery Clone()
{
return MemberwiseClone() as TorrentQuery;
}
}
public class HDBitsResponse

@ -53,7 +53,7 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
foreach (var result in queryResults)
{
var id = result.Id;
var internalRelease = result.TypeOrigin == 1 ? true : false;
var internalRelease = result.TypeOrigin == 1;
var flags = new HashSet<IndexerFlag>();
@ -62,9 +62,9 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
flags.Add(IndexerFlag.Internal);
}
torrentInfos.Add(new HDBitsInfo()
torrentInfos.Add(new HDBitsInfo
{
Guid = string.Format("HDBits-{0}", id),
Guid = $"HDBits-{id}",
Title = result.Name,
Size = result.Size,
Categories = _categories.MapTrackerCatToNewznab(result.TypeCategory.ToString()),
@ -77,6 +77,7 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
Peers = result.Leechers + result.Seeders,
PublishDate = result.Added.ToUniversalTime(),
Internal = internalRelease,
Year = result.ImdbInfo?.Year ?? 0,
ImdbId = result.ImdbInfo?.Id ?? 0,
TvdbId = result.TvdbInfo?.Id ?? 0,
DownloadVolumeFactor = result.FreeLeech == "yes" ? 0 : 1,

@ -21,12 +21,8 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
{
var pageableRequests = new IndexerPageableRequestChain();
var query = new TorrentQuery();
var imdbId = ParseUtil.GetImdbId(searchCriteria.ImdbId).GetValueOrDefault(0);
if (searchCriteria.Categories?.Length > 0)
{
query.Category = Capabilities.Categories.MapTorznabCapsToTrackers(searchCriteria.Categories).Select(int.Parse).ToArray();
}
var imdbId = ParseUtil.GetImdbId(searchCriteria.ImdbId).GetValueOrDefault(0);
if (imdbId == 0 && searchCriteria.SearchTerm.IsNotNullOrWhiteSpace())
{
@ -39,37 +35,11 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
query.ImdbInfo.Id = imdbId;
}
pageableRequests.Add(GetRequest(query));
pageableRequests.Add(GetRequest(query, searchCriteria));
return pageableRequests;
}
public Func<IDictionary<string, string>> GetCookies { get; set; }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
private IEnumerable<IndexerRequest> GetRequest(TorrentQuery query)
{
var request = new HttpRequestBuilder(Settings.BaseUrl)
.Resource("/api/torrents")
.Build();
request.Method = HttpMethod.Post;
const string appJson = "application/json";
request.Headers.Accept = appJson;
request.Headers.ContentType = appJson;
query.Username = Settings.Username;
query.Passkey = Settings.ApiKey;
query.Codec = Settings.Codecs.ToArray();
query.Medium = Settings.Mediums.ToArray();
request.SetContent(query.ToJson());
request.ContentSummary = query.ToJson(Formatting.None);
yield return new IndexerRequest(request);
}
public IndexerPageableRequestChain GetSearchRequests(MusicSearchCriteria searchCriteria)
{
return new IndexerPageableRequestChain();
@ -79,14 +49,10 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
{
var pageableRequests = new IndexerPageableRequestChain();
var query = new TorrentQuery();
var tvdbId = searchCriteria.TvdbId.GetValueOrDefault(0);
var imdbId = ParseUtil.GetImdbId(searchCriteria.ImdbId).GetValueOrDefault(0);
if (searchCriteria.Categories?.Length > 0)
{
query.Category = Capabilities.Categories.MapTorznabCapsToTrackers(searchCriteria.Categories).Select(int.Parse).ToArray();
}
if (tvdbId == 0 && imdbId == 0 && searchCriteria.SearchTerm.IsNotNullOrWhiteSpace())
{
query.Search = searchCriteria.SanitizedTvSearchString;
@ -114,7 +80,7 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
query.ImdbInfo.Id = imdbId;
}
pageableRequests.Add(GetRequest(query));
pageableRequests.Add(GetRequest(query, searchCriteria));
return pageableRequests;
}
@ -129,19 +95,56 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
var pageableRequests = new IndexerPageableRequestChain();
var query = new TorrentQuery();
if (searchCriteria.SearchTerm.IsNotNullOrWhiteSpace())
{
query.Search = searchCriteria.SanitizedSearchTerm;
}
pageableRequests.Add(GetRequest(query, searchCriteria));
return pageableRequests;
}
public Func<IDictionary<string, string>> GetCookies { get; set; }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
private IEnumerable<IndexerRequest> GetRequest(TorrentQuery query, SearchCriteriaBase searchCriteria)
{
var request = new HttpRequestBuilder(Settings.BaseUrl)
.Resource("/api/torrents")
.Build();
request.Method = HttpMethod.Post;
const string appJson = "application/json";
request.Headers.Accept = appJson;
request.Headers.ContentType = appJson;
query.Username = Settings.Username;
query.Passkey = Settings.ApiKey;
query.Codec = Settings.Codecs.ToArray();
query.Medium = Settings.Mediums.ToArray();
if (searchCriteria.Categories?.Length > 0)
{
query.Category = Capabilities.Categories.MapTorznabCapsToTrackers(searchCriteria.Categories).Select(int.Parse).ToArray();
query.Category = Capabilities.Categories
.MapTorznabCapsToTrackers(searchCriteria.Categories)
.Distinct()
.Select(int.Parse)
.ToArray();
}
if (searchCriteria.SearchTerm.IsNotNullOrWhiteSpace())
query.Limit = 100;
if (searchCriteria.Limit is > 0 && searchCriteria.Offset is > 0)
{
query.Search = searchCriteria.SanitizedSearchTerm;
query.Page = (int)(searchCriteria.Offset / searchCriteria.Limit);
}
pageableRequests.Add(GetRequest(query));
request.SetContent(query.ToJson());
request.ContentSummary = query.ToJson(Formatting.None);
return pageableRequests;
yield return new IndexerRequest(request);
}
}
}

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using FluentValidation;
using NzbDrone.Core.Annotations;
@ -10,6 +11,7 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
{
public HDBitsSettingsValidator()
{
RuleFor(c => c.Username).NotEmpty();
RuleFor(c => c.ApiKey).NotEmpty();
}
}
@ -20,8 +22,8 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
public HDBitsSettings()
{
Codecs = System.Array.Empty<int>();
Mediums = System.Array.Empty<int>();
Codecs = Array.Empty<int>();
Mediums = Array.Empty<int>();
}
[FieldDefinition(2, Label = "Username", HelpText = "Site Username", Privacy = PrivacyLevel.UserName)]
@ -42,18 +44,6 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
}
}
public enum HdBitsCategory
{
Movie = 1,
Tv = 2,
Documentary = 3,
Music = 4,
Sport = 5,
Audio = 6,
Xxx = 7,
MiscDemo = 8
}
public enum HdBitsCodec
{
H264 = 1,

Loading…
Cancel
Save