Fixed: (HDTorrents) Use Accept Html for indexer requests

pull/1667/head
Bogdan 2 years ago
parent 541b8b4f7f
commit 2bcdae44c7

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

Loading…
Cancel
Save