From 64788e23f61f308aff77e393fe40104f5eb20a48 Mon Sep 17 00:00:00 2001 From: ngosang Date: Thu, 1 Oct 2020 20:27:01 +0200 Subject: [PATCH] core: code cleanup --- src/Jackett.Common/Indexers/HDBitsApi.cs | 29 +++++++------------ ...tsApi.cs => ConfigurationDataHDBitsApi.cs} | 8 ++--- 2 files changed, 14 insertions(+), 23 deletions(-) rename src/Jackett.Common/Models/IndexerConfig/Bespoke/{ConfigurationHDBitsApi.cs => ConfigurationDataHDBitsApi.cs} (80%) diff --git a/src/Jackett.Common/Indexers/HDBitsApi.cs b/src/Jackett.Common/Indexers/HDBitsApi.cs index ea5138cbf..b036a1e7d 100644 --- a/src/Jackett.Common/Indexers/HDBitsApi.cs +++ b/src/Jackett.Common/Indexers/HDBitsApi.cs @@ -84,29 +84,25 @@ namespace Jackett.Common.Indexers var imdbId = ParseUtil.GetImdbID(query.ImdbID); if (imdbId != null) - { - requestData["imdb"] = new JObject(); - requestData["imdb"]["id"] = imdbId; - } + requestData["imdb"] = new JObject + { + ["id"] = imdbId + }; else if (query.TvdbID != null) { - requestData["tvdb"] = new JObject(); - requestData["tvdb"]["id"] = query.TvdbID; + requestData["tvdb"] = new JObject + { + ["id"] = query.TvdbID + }; if (query.Season != 0) - { requestData["tvdb"]["season"] = query.Season; - } if (!string.IsNullOrEmpty(query.Episode)) - { requestData["tvdb"]["episode"] = query.Episode; - } } else if (!string.IsNullOrWhiteSpace(queryString)) - { requestData["search"] = queryString; - } var categories = MapTorznabCapsToTrackers(query); @@ -152,14 +148,10 @@ namespace Jackett.Common.Indexers }; if (r.ContainsKey("imdb")) - { release.Imdb = ParseUtil.GetImdbID((string)r["imdb"]["id"]); - } if (r.ContainsKey("tvdb")) - { release.TVDBId = (long)r["tvdb"]["id"]; - } releases.Add(release); } @@ -191,7 +183,7 @@ namespace Jackett.Common.Indexers { requestData["username"] = configData.Username.Value; requestData["passkey"] = configData.Passkey.Value; - JObject json = null; + var response = await RequestWithCookiesAndRetryAsync( APIUrl + url, null, RequestType.POST, null, null, new Dictionary @@ -201,6 +193,7 @@ namespace Jackett.Common.Indexers }, requestData.ToString(), false); CheckSiteDown(response); + JObject json; try { json = JObject.Parse(response.ContentString); @@ -211,9 +204,7 @@ namespace Jackett.Common.Indexers } if ((int)json["status"] != 0) - { throw new Exception("HDBits returned an error with status code " + (int)json["status"] + ": " + (string)json["message"]); - } return json; } diff --git a/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationHDBitsApi.cs b/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataHDBitsApi.cs similarity index 80% rename from src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationHDBitsApi.cs rename to src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataHDBitsApi.cs index b7e4663b8..410e1d000 100644 --- a/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationHDBitsApi.cs +++ b/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataHDBitsApi.cs @@ -8,7 +8,7 @@ namespace Jackett.Common.Models.IndexerConfig.Bespoke public CheckboxItem Mediums { get; private set; } public CheckboxItem Origins { get; private set; } - public ConfigurationDataHDBitsApi() : base() + public ConfigurationDataHDBitsApi() { Codecs = new CheckboxItem(new Dictionary() { @@ -20,7 +20,7 @@ namespace Jackett.Common.Models.IndexerConfig.Bespoke {"6", "VP9"}, {"4", "XviD"} }) - { Name = "Codec", Values = new string[] { "0", "1", "5", "2", "3", "6", "4" } }; + { Name = "Codec", Values = new [] { "0", "1", "5", "2", "3", "6", "4" } }; Mediums = new CheckboxItem(new Dictionary() { @@ -31,14 +31,14 @@ namespace Jackett.Common.Models.IndexerConfig.Bespoke {"5", "Remux"}, {"6", "WEB-DL"} }) - { Name = "Medium", Values = new string[] { "0", "1", "4", "3", "5", "6" } }; + { Name = "Medium", Values = new [] { "0", "1", "4", "3", "5", "6" } }; Origins = new CheckboxItem(new Dictionary() { {"0", "Undefined"}, {"1", "Internal"} }) - { Name = "Origin", Values = new string[] { "0", "1" } }; + { Name = "Origin", Values = new [] { "0", "1" } }; } } }