Improvements to download factor and show Freeleech only for HDB

This commit is contained in:
Bogdan
2023-11-13 16:23:10 +02:00
parent bd0609639e
commit 4b4589ed27
2 changed files with 47 additions and 7 deletions

View File

@@ -14,6 +14,8 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
private readonly HDBitsSettings _settings; private readonly HDBitsSettings _settings;
private readonly IndexerCapabilitiesCategories _categories; private readonly IndexerCapabilitiesCategories _categories;
private readonly List<int> _halfLeechMediums = new () { (int)HdBitsMedium.Bluray, (int)HdBitsMedium.Remux, (int)HdBitsMedium.Capture };
public HDBitsParser(HDBitsSettings settings, IndexerCapabilitiesCategories categories) public HDBitsParser(HDBitsSettings settings, IndexerCapabilitiesCategories categories)
{ {
_settings = settings; _settings = settings;
@@ -22,7 +24,6 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse) public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
{ {
var torrentInfos = new List<ReleaseInfo>();
var indexerHttpResponse = indexerResponse.HttpResponse; var indexerHttpResponse = indexerResponse.HttpResponse;
if (indexerHttpResponse.StatusCode == HttpStatusCode.Forbidden) if (indexerHttpResponse.StatusCode == HttpStatusCode.Forbidden)
@@ -42,16 +43,23 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
throw new IndexerException(indexerResponse, "HDBits API request returned status code {0}: {1}", jsonResponse.Status, jsonResponse.Message ?? string.Empty); throw new IndexerException(indexerResponse, "HDBits API request returned status code {0}: {1}", jsonResponse.Status, jsonResponse.Message ?? string.Empty);
} }
var responseData = jsonResponse.Data as JArray; if (jsonResponse.Data is not JArray responseData)
if (responseData == null)
{ {
throw new IndexerException(indexerResponse, "Indexer API call response missing result data"); throw new IndexerException(indexerResponse, "Indexer API call response missing result data");
} }
var releaseInfos = new List<ReleaseInfo>();
var queryResults = responseData.ToObject<TorrentQueryResponse[]>(); var queryResults = responseData.ToObject<TorrentQueryResponse[]>();
foreach (var result in queryResults) foreach (var result in queryResults)
{ {
// Skip non-freeleech results when freeleech only is set
if (_settings.FreeleechOnly && result.FreeLeech != "yes")
{
continue;
}
var id = result.Id; var id = result.Id;
var internalRelease = result.TypeOrigin == 1; var internalRelease = result.TypeOrigin == 1;
@@ -62,7 +70,7 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
flags.Add(IndexerFlag.Internal); flags.Add(IndexerFlag.Internal);
} }
torrentInfos.Add(new HDBitsInfo releaseInfos.Add(new HDBitsInfo
{ {
Guid = $"HDBits-{id}", Guid = $"HDBits-{id}",
Title = result.Name, Title = result.Name,
@@ -80,17 +88,45 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
Year = result.ImdbInfo?.Year ?? 0, Year = result.ImdbInfo?.Year ?? 0,
ImdbId = result.ImdbInfo?.Id ?? 0, ImdbId = result.ImdbInfo?.Id ?? 0,
TvdbId = result.TvdbInfo?.Id ?? 0, TvdbId = result.TvdbInfo?.Id ?? 0,
DownloadVolumeFactor = result.FreeLeech == "yes" ? 0 : 1, DownloadVolumeFactor = GetDownloadVolumeFactor(result),
UploadVolumeFactor = 1, UploadVolumeFactor = GetUploadVolumeFactor(result),
IndexerFlags = flags IndexerFlags = flags
}); });
} }
return torrentInfos.ToArray(); return releaseInfos.ToArray();
} }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; } public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
private double GetDownloadVolumeFactor(TorrentQueryResponse item)
{
if (item.FreeLeech == "yes")
{
return 0;
}
// 100% Neutral Leech: all XXX content.
if (item.TypeCategory == 7)
{
return 0;
}
// 50% Free Leech: all full discs, remuxes, captures and all internal encodes, also all TV and Documentary content.
if (_halfLeechMediums.Contains(item.TypeMedium) || item.TypeOrigin == 1 || item.TypeCategory is 2 or 3)
{
return 0.5;
}
return 1;
}
private static double GetUploadVolumeFactor(TorrentQueryResponse item)
{
// 100% Neutral Leech: all XXX content.
return item.TypeCategory == 7 ? 0 : 1;
}
private string GetDownloadUrl(string torrentId) private string GetDownloadUrl(string torrentId)
{ {
var url = new HttpUri(_settings.BaseUrl) var url = new HttpUri(_settings.BaseUrl)

View File

@@ -24,6 +24,7 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
{ {
Codecs = Array.Empty<int>(); Codecs = Array.Empty<int>();
Mediums = Array.Empty<int>(); Mediums = Array.Empty<int>();
FreeleechOnly = false;
} }
[FieldDefinition(2, Label = "Username", HelpText = "Site Username", Privacy = PrivacyLevel.UserName)] [FieldDefinition(2, Label = "Username", HelpText = "Site Username", Privacy = PrivacyLevel.UserName)]
@@ -38,6 +39,9 @@ namespace NzbDrone.Core.Indexers.Definitions.HDBits
[FieldDefinition(5, Label = "Mediums", Type = FieldType.TagSelect, SelectOptions = typeof(HdBitsMedium), Advanced = true, HelpText = "Options: BluRay, Encode, Capture, Remux, WebDL. If unspecified, all options are used.")] [FieldDefinition(5, Label = "Mediums", Type = FieldType.TagSelect, SelectOptions = typeof(HdBitsMedium), Advanced = true, HelpText = "Options: BluRay, Encode, Capture, Remux, WebDL. If unspecified, all options are used.")]
public IEnumerable<int> Mediums { get; set; } public IEnumerable<int> Mediums { get; set; }
[FieldDefinition(6, Label = "Freeleech Only", Type = FieldType.Checkbox, Advanced = true, HelpText = "Show freeleech releases only")]
public bool FreeleechOnly { get; set; }
public override NzbDroneValidationResult Validate() public override NzbDroneValidationResult Validate()
{ {
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));