diff --git a/src/NzbDrone.Core/Indexers/Definitions/HDTorrents.cs b/src/NzbDrone.Core/Indexers/Definitions/HDTorrents.cs index dfb0b71ae..958a03d74 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/HDTorrents.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/HDTorrents.cs @@ -33,7 +33,6 @@ namespace NzbDrone.Core.Indexers.Definitions public override DownloadProtocol Protocol => DownloadProtocol.Torrent; public override IndexerPrivacy Privacy => IndexerPrivacy.Private; public override IndexerCapabilities Capabilities => SetCapabilities(); - private string LoginUrl => Settings.BaseUrl + "login.php"; public HDTorrents(IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IConfigService configService, Logger logger) : base(httpClient, eventAggregator, indexerStatusService, configService, logger) @@ -42,7 +41,7 @@ namespace NzbDrone.Core.Indexers.Definitions public override IIndexerRequestGenerator GetRequestGenerator() { - return new HDTorrentsRequestGenerator { Settings = Settings, Capabilities = Capabilities }; + return new HDTorrentsRequestGenerator(Settings, Capabilities); } public override IParseIndexerResponse GetParser() @@ -52,28 +51,28 @@ namespace NzbDrone.Core.Indexers.Definitions protected override async Task DoLogin() { - var requestBuilder = new HttpRequestBuilder(LoginUrl) + Cookies = null; + + var loginUrl = Settings.BaseUrl + "login.php"; + + var requestBuilder = new HttpRequestBuilder(loginUrl) { LogResponseContent = true, Method = HttpMethod.Post }; - var cookies = Cookies; - Cookies = null; - var authLoginRequest = requestBuilder .AddFormParameter("uid", Settings.Username) .AddFormParameter("pwd", Settings.Password) .SetHeader("Content-Type", "application/x-www-form-urlencoded") - .SetHeader("Referer", LoginUrl) + .SetHeader("Referer", loginUrl) .Build(); var response = await ExecuteAuth(authLoginRequest); - cookies = response.GetCookies(); - UpdateCookies(cookies, DateTime.Now.AddDays(30)); + UpdateCookies(response.GetCookies(), DateTime.Now.AddDays(30)); - _logger.Debug("HDTorrents authentication succeeded."); + _logger.Debug("Authentication succeeded"); } protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) @@ -142,12 +141,18 @@ namespace NzbDrone.Core.Indexers.Definitions public class HDTorrentsRequestGenerator : IIndexerRequestGenerator { - public UserPassTorrentBaseSettings Settings { get; set; } - public IndexerCapabilities Capabilities { get; set; } + private readonly UserPassTorrentBaseSettings _settings; + private readonly IndexerCapabilities _capabilities; + + public HDTorrentsRequestGenerator(UserPassTorrentBaseSettings settings, IndexerCapabilities capabilities) + { + _settings = settings; + _capabilities = capabilities; + } private IEnumerable GetPagedRequests(string term, int[] categories, string imdbId = null) { - var searchUrl = Settings.BaseUrl + "torrents.php?" + string.Join(string.Empty, Capabilities.Categories.MapTorznabCapsToTrackers(categories).Select(cat => $"category[]={cat}&")); + var searchUrl = _settings.BaseUrl + "torrents.php?" + string.Join(string.Empty, _capabilities.Categories.MapTorznabCapsToTrackers(categories).Select(cat => $"category[]={cat}&")); var search = new[] { imdbId, term }; @@ -161,16 +166,14 @@ namespace NzbDrone.Core.Indexers.Definitions // manually url encode parenthesis to prevent "hacking" detection searchUrl += queryCollection.GetQueryString().Replace("(", "%28").Replace(")", "%29").Replace(".", " "); - var request = new IndexerRequest(searchUrl, HttpAccept.Rss); - - yield return request; + yield return new IndexerRequest(searchUrl, HttpAccept.Html); } public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria) { var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.Add(GetPagedRequests(string.Format("{0}", searchCriteria.SearchTerm), searchCriteria.Categories, searchCriteria.FullImdbId)); + pageableRequests.Add(GetPagedRequests(searchCriteria.SearchTerm, searchCriteria.Categories, searchCriteria.FullImdbId)); return pageableRequests; } @@ -179,7 +182,7 @@ namespace NzbDrone.Core.Indexers.Definitions { var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.Add(GetPagedRequests(string.Format("{0}", searchCriteria.SanitizedSearchTerm), searchCriteria.Categories)); + pageableRequests.Add(GetPagedRequests(searchCriteria.SanitizedSearchTerm, searchCriteria.Categories)); return pageableRequests; } @@ -188,7 +191,7 @@ namespace NzbDrone.Core.Indexers.Definitions { 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; } @@ -197,7 +200,7 @@ namespace NzbDrone.Core.Indexers.Definitions { var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.Add(GetPagedRequests(string.Format("{0}", searchCriteria.SanitizedSearchTerm), searchCriteria.Categories)); + pageableRequests.Add(GetPagedRequests(searchCriteria.SanitizedSearchTerm, searchCriteria.Categories)); return pageableRequests; } @@ -206,7 +209,7 @@ namespace NzbDrone.Core.Indexers.Definitions { var pageableRequests = new IndexerPageableRequestChain(); - pageableRequests.Add(GetPagedRequests(string.Format("{0}", searchCriteria.SanitizedSearchTerm), searchCriteria.Categories)); + pageableRequests.Add(GetPagedRequests(searchCriteria.SanitizedSearchTerm, searchCriteria.Categories)); return pageableRequests; } @@ -239,7 +242,7 @@ namespace NzbDrone.Core.Indexers.Definitions public IList ParseResponse(IndexerResponse indexerResponse) { - var torrentInfos = new List(); + var releaseInfos = new List(); var parser = new HtmlParser(); var dom = parser.ParseDocument(indexerResponse.Content); @@ -356,10 +359,10 @@ namespace NzbDrone.Core.Indexers.Definitions MinimumSeedTime = 172800 // 48 hours }; - torrentInfos.Add(release); + releaseInfos.Add(release); } - return torrentInfos.ToArray(); + return releaseInfos.ToArray(); } public Action, DateTime?> CookiesUpdater { get; set; }