From 5328fb4ab31b643449a38adb4abcd2ea57371df4 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Fri, 17 Nov 2023 17:25:38 +0200 Subject: [PATCH] New: Additional options for HDBits --- src/NzbDrone.Core/Indexers/HDBits/HDBits.cs | 4 +- .../Indexers/HDBits/HDBitsApi.cs | 16 +++--- .../Indexers/HDBits/HDBitsParser.cs | 7 +-- .../Indexers/HDBits/HDBitsRequestGenerator.cs | 13 ++++- .../Indexers/HDBits/HDBitsSettings.cs | 55 +++++++++++++++---- src/NzbDrone.Core/Localization/Core/en.json | 6 ++ 6 files changed, 72 insertions(+), 29 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/HDBits/HDBits.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBits.cs index e7a200bf9..2ac2cfb4b 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HDBits.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBits.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Core.Indexers.HDBits public override DownloadProtocol Protocol => DownloadProtocol.Torrent; public override bool SupportsRss => true; public override bool SupportsSearch => true; - public override int PageSize => 30; + public override int PageSize => 100; public HDBits(IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger, ILocalizationService localizationService) : base(httpClient, indexerStatusService, configService, parsingService, logger, localizationService) @@ -21,7 +21,7 @@ namespace NzbDrone.Core.Indexers.HDBits public override IIndexerRequestGenerator GetRequestGenerator() { - return new HDBitsRequestGenerator() { Settings = Settings }; + return new HDBitsRequestGenerator { Settings = Settings }; } public override IParseIndexerResponse GetParser() diff --git a/src/NzbDrone.Core/Indexers/HDBits/HDBitsApi.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBitsApi.cs index 9bb6d624b..75c360599 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HDBitsApi.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBitsApi.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Newtonsoft.Json; namespace NzbDrone.Core.Indexers.HDBits @@ -7,20 +8,16 @@ namespace NzbDrone.Core.Indexers.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 int[] Origin { get; set; } + public IEnumerable Category { get; set; } + public IEnumerable Codec { get; set; } + public IEnumerable Medium { get; set; } + public int? Origin { get; set; } [JsonProperty(PropertyName = "imdb")] public ImdbInfo ImdbInfo { get; set; } @@ -33,6 +30,7 @@ namespace NzbDrone.Core.Indexers.HDBits [JsonProperty(PropertyName = "snatched_only")] public bool? SnatchedOnly { get; set; } + public int? Limit { get; set; } public int? Page { get; set; } diff --git a/src/NzbDrone.Core/Indexers/HDBits/HDBitsParser.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBitsParser.cs index 06f986b60..4bff86c7c 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HDBitsParser.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBitsParser.cs @@ -38,8 +38,7 @@ namespace NzbDrone.Core.Indexers.HDBits jsonResponse.Message ?? string.Empty); } - var responseData = jsonResponse.Data as JArray; - if (responseData == null) + if (jsonResponse.Data is not JArray responseData) { throw new IndexerException(indexerResponse, "Indexer API call response missing result data"); @@ -50,9 +49,9 @@ namespace NzbDrone.Core.Indexers.HDBits foreach (var result in queryResults) { var id = result.Id; - torrentInfos.Add(new TorrentInfo() + torrentInfos.Add(new TorrentInfo { - Guid = string.Format("HDBits-{0}", id), + Guid = $"HDBits-{id}", Title = result.Name, Size = result.Size, InfoHash = result.Hash, diff --git a/src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs index 315376b72..413404d7a 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs @@ -72,7 +72,7 @@ namespace NzbDrone.Core.Indexers.HDBits if (TryAddSearchParameters(query, searchCriteria)) { - query.Search = string.Format("{0:yyyy}-{0:MM}-{0:dd}", searchCriteria.AirDate); + query.Search = searchCriteria.AirDate.ToString("yyyy-MM-dd"); pageableRequests.Add(GetRequest(query)); } @@ -87,7 +87,7 @@ namespace NzbDrone.Core.Indexers.HDBits if (TryAddSearchParameters(query, searchCriteria)) { - query.Search = string.Format("{0}-", searchCriteria.Year); + query.Search = $"{searchCriteria.Year}-"; pageableRequests.Add(GetRequest(query)); } @@ -140,8 +140,9 @@ namespace NzbDrone.Core.Indexers.HDBits { if (searchCriteria.Series.TvdbId != 0) { - query.TvdbInfo = query.TvdbInfo ?? new TvdbInfo(); + query.TvdbInfo ??= new TvdbInfo(); query.TvdbInfo.Id = searchCriteria.Series.TvdbId; + return true; } @@ -162,6 +163,12 @@ namespace NzbDrone.Core.Indexers.HDBits query.Username = Settings.Username; query.Passkey = Settings.ApiKey; + query.Category = Settings.Categories.ToArray(); + query.Codec = Settings.Codecs.ToArray(); + query.Medium = Settings.Mediums.ToArray(); + + query.Limit = 100; + request.SetContent(query.ToJson()); request.ContentSummary = query.ToJson(Formatting.None); diff --git a/src/NzbDrone.Core/Indexers/HDBits/HDBitsSettings.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBitsSettings.cs index 0b573850c..c6525771d 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HDBitsSettings.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBitsSettings.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using FluentValidation; using NzbDrone.Core.Annotations; using NzbDrone.Core.Validation; @@ -17,28 +19,41 @@ namespace NzbDrone.Core.Indexers.HDBits public class HDBitsSettings : ITorrentIndexerSettings { - private static readonly HDBitsSettingsValidator Validator = new HDBitsSettingsValidator(); + private static readonly HDBitsSettingsValidator Validator = new (); public HDBitsSettings() { BaseUrl = "https://hdbits.org"; MinimumSeeders = IndexerDefaults.MINIMUM_SEEDERS; + + Categories = new[] { (int)HdBitsCategory.Tv, (int)HdBitsCategory.Documentary }; + Codecs = Array.Empty(); + Mediums = Array.Empty(); } - [FieldDefinition(0, Label = "Username", Privacy = PrivacyLevel.UserName)] - public string Username { get; set; } - - [FieldDefinition(1, Label = "ApiKey", Privacy = PrivacyLevel.ApiKey)] - public string ApiKey { get; set; } - - [FieldDefinition(2, Label = "IndexerSettingsApiUrl", Advanced = true, HelpText = "IndexerSettingsApiUrlHelpText")] + [FieldDefinition(0, Label = "IndexerSettingsApiUrl", Advanced = true, HelpText = "IndexerSettingsApiUrlHelpText")] public string BaseUrl { get; set; } - [FieldDefinition(3, Type = FieldType.Number, Label = "IndexerSettingsMinimumSeeders", HelpText = "IndexerSettingsMinimumSeedersHelpText", Advanced = true)] + [FieldDefinition(1, Label = "Username", Privacy = PrivacyLevel.UserName)] + public string Username { get; set; } + + [FieldDefinition(2, Label = "ApiKey", Privacy = PrivacyLevel.ApiKey)] + public string ApiKey { get; set; } + + [FieldDefinition(3, Label = "IndexerHDBitsSettingsCategories", Type = FieldType.Select, SelectOptions = typeof(HdBitsCategory), HelpText = "IndexerHDBitsSettingsCategoriesHelpText")] + public IEnumerable Categories { get; set; } + + [FieldDefinition(4, Label = "IndexerHDBitsSettingsCodecs", Type = FieldType.Select, SelectOptions = typeof(HdBitsCodec), Advanced = true, HelpText = "IndexerHDBitsSettingsCodecsHelpText")] + public IEnumerable Codecs { get; set; } + + [FieldDefinition(5, Label = "IndexerHDBitsSettingsMediums", Type = FieldType.Select, SelectOptions = typeof(HdBitsMedium), Advanced = true, HelpText = "IndexerHDBitsSettingsMediumsHelpText")] + public IEnumerable Mediums { get; set; } + + [FieldDefinition(6, Type = FieldType.Number, Label = "IndexerSettingsMinimumSeeders", HelpText = "IndexerSettingsMinimumSeedersHelpText", Advanced = true)] public int MinimumSeeders { get; set; } - [FieldDefinition(4)] - public SeedCriteriaSettings SeedCriteria { get; set; } = new SeedCriteriaSettings(); + [FieldDefinition(7)] + public SeedCriteriaSettings SeedCriteria { get; set; } = new (); public NzbDroneValidationResult Validate() { @@ -48,31 +63,49 @@ namespace NzbDrone.Core.Indexers.HDBits public enum HdBitsCategory { + [FieldOption(label: "Movie")] Movie = 1, + [FieldOption(label: "TV")] Tv = 2, + [FieldOption(label: "Documentary")] Documentary = 3, + [FieldOption(label: "Music")] Music = 4, + [FieldOption(label: "Sport")] Sport = 5, + [FieldOption(label: "Audio Track")] Audio = 6, + [FieldOption(label: "XXX")] Xxx = 7, + [FieldOption(label: "Misc/Demo")] MiscDemo = 8 } public enum HdBitsCodec { + [FieldOption(label: "H.264")] H264 = 1, + [FieldOption(label: "MPEG-2")] Mpeg2 = 2, + [FieldOption(label: "VC-1")] Vc1 = 3, + [FieldOption(label: "XviD")] Xvid = 4, + [FieldOption(label: "HEVC")] Hevc = 5 } public enum HdBitsMedium { + [FieldOption(label: "Blu-ray/HD DVD")] Bluray = 1, + [FieldOption(label: "Encode")] Encode = 3, + [FieldOption(label: "Capture")] Capture = 4, + [FieldOption(label: "Remux")] Remux = 5, + [FieldOption(label: "WEB-DL")] WebDl = 6 } } diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index df12a7431..de3b64ce2 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -770,6 +770,12 @@ "Indexer": "Indexer", "IndexerDownloadClientHealthCheckMessage": "Indexers with invalid download clients: {indexerNames}.", "IndexerDownloadClientHelpText": "Specify which download client is used for grabs from this indexer", + "IndexerHDBitsSettingsCategories": "Categories", + "IndexerHDBitsSettingsCategoriesHelpText": "If unspecified, all options are used.", + "IndexerHDBitsSettingsCodecs": "Codecs", + "IndexerHDBitsSettingsCodecsHelpText": "If unspecified, all options are used.", + "IndexerHDBitsSettingsMediums": "Mediums", + "IndexerHDBitsSettingsMediumsHelpText": "If unspecified, all options are used.", "IndexerIPTorrentsSettingsFeedUrl": "Feed URL", "IndexerIPTorrentsSettingsFeedUrlHelpText": "The full RSS feed url generated by IPTorrents, using only the categories you selected (HD, SD, x264, etc ...)", "IndexerJackettAllHealthCheckMessage": "Indexers using the unsupported Jackett 'all' endpoint: {indexerNames}",