mirror of
https://github.com/Jackett/Jackett
synced 2025-03-09 13:52:03 +00:00
xspeeds: category filtering if single, prevent possible error in login, add sorting (#13966)
This commit is contained in:
parent
22af3a09a2
commit
e8875d38fc
1 changed files with 59 additions and 28 deletions
|
@ -142,8 +142,35 @@ namespace Jackett.Common.Indexers
|
|||
AddCategoryMapping("Wii Games", TorznabCatType.ConsoleWii);
|
||||
AddCategoryMapping("Wrestling", TorznabCatType.TVSport);
|
||||
AddCategoryMapping("Xbox Games", TorznabCatType.ConsoleXBox);
|
||||
|
||||
// Configure the sort selects
|
||||
var sortBySelect = new SingleSelectConfigurationItem(
|
||||
"Sort by",
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
{ "added", "created" },
|
||||
{ "seeders", "seeders" },
|
||||
{ "size", "size" },
|
||||
{ "name", "title" }
|
||||
})
|
||||
{ Value = "added" };
|
||||
configData.AddDynamic("sortrequestedfromsite", sortBySelect);
|
||||
|
||||
var orderSelect = new SingleSelectConfigurationItem(
|
||||
"Order",
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
{ "desc", "descending" },
|
||||
{ "asc", "ascending" }
|
||||
})
|
||||
{ Value = "desc" };
|
||||
configData.AddDynamic("orderrequestedfromsite", orderSelect);
|
||||
}
|
||||
|
||||
private string GetSortBy => ((SingleSelectConfigurationItem)configData.GetDynamic("sortrequestedfromsite")).Value;
|
||||
|
||||
private string GetOrder => ((SingleSelectConfigurationItem)configData.GetDynamic("orderrequestedfromsite")).Value;
|
||||
|
||||
public override async Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
var loginPage = await RequestWithCookiesAsync(LandingUrl);
|
||||
|
@ -170,12 +197,11 @@ namespace Jackett.Common.Indexers
|
|||
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
||||
{
|
||||
LoadValuesFromJson(configJson);
|
||||
|
||||
var pairs = new Dictionary<string, string>
|
||||
{
|
||||
{"username", configData.Username.Value},
|
||||
{"password", configData.Password.Value}
|
||||
};
|
||||
{
|
||||
{ "username", configData.Username.Value },
|
||||
{ "password", configData.Password.Value }
|
||||
};
|
||||
|
||||
var captchaText = (StringConfigurationItem)configData.GetDynamic("CaptchaText");
|
||||
if (captchaText != null)
|
||||
|
@ -183,26 +209,26 @@ namespace Jackett.Common.Indexers
|
|||
|
||||
//var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink, true);
|
||||
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, SearchUrl, LandingUrl, true);
|
||||
await ConfigureIfOK(result.Cookies, result.ContentString?.Contains("logout.php") == true,
|
||||
() =>
|
||||
{
|
||||
var parser = new HtmlParser();
|
||||
var dom = parser.ParseDocument(result.ContentString);
|
||||
var errorMessage = dom.QuerySelector(".left_side table:nth-of-type(1) tr:nth-of-type(2)")?.TextContent.Trim().Replace("\n\t", " ");
|
||||
if (string.IsNullOrWhiteSpace(errorMessage))
|
||||
errorMessage = dom.QuerySelector("div.notification-body").TextContent.Trim().Replace("\n\t", " ");
|
||||
throw new ExceptionWithConfigData(errorMessage, configData);
|
||||
});
|
||||
await ConfigureIfOK(result.Cookies, result.ContentString?.Contains("logout.php") == true, () =>
|
||||
{
|
||||
var parser = new HtmlParser();
|
||||
var dom = parser.ParseDocument(result.ContentString);
|
||||
var errorMessage = dom.QuerySelector(".left_side table:nth-of-type(1) tr:nth-of-type(2)")?.TextContent.Trim().Replace("\n\t", " ");
|
||||
if (string.IsNullOrWhiteSpace(errorMessage))
|
||||
errorMessage = dom.QuerySelector("div.notification-body")?.TextContent.Trim().Replace("\n\t", " ");
|
||||
|
||||
throw new ExceptionWithConfigData(errorMessage ?? "Login failed.", configData);
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
// Get RSS key
|
||||
var rssParams = new Dictionary<string, string>
|
||||
{
|
||||
{"feedtype", "download"},
|
||||
{"timezone", "0"},
|
||||
{"showrows", "50"}
|
||||
};
|
||||
{
|
||||
{ "feedtype", "download" },
|
||||
{ "timezone", "0" },
|
||||
{ "showrows", "50" }
|
||||
};
|
||||
var rssPage = await RequestWithCookiesAsync(
|
||||
GetRSSKeyUrl, result.Cookies, RequestType.POST, data: rssParams);
|
||||
var match = Regex.Match(rssPage.ContentString, "(?<=secret_key\\=)([a-zA-z0-9]*)");
|
||||
|
@ -216,19 +242,24 @@ namespace Jackett.Common.Indexers
|
|||
IsConfigured = false;
|
||||
throw;
|
||||
}
|
||||
|
||||
return IndexerConfigurationStatus.RequiresTesting;
|
||||
}
|
||||
|
||||
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
var releases = new List<ReleaseInfo>();
|
||||
var searchString = query.GetQueryString();
|
||||
var prevCook = CookieHeader + "";
|
||||
|
||||
var searchParams = new Dictionary<string, string> {
|
||||
var categoryMapping = MapTorznabCapsToTrackers(query);
|
||||
|
||||
var searchParams = new Dictionary<string, string>
|
||||
{
|
||||
{ "do", "search" },
|
||||
{ "category", "0" },
|
||||
{ "include_dead_torrents", "no" }
|
||||
{ "category", categoryMapping.FirstIfSingleOrDefault("0") }, // multi category search not supported
|
||||
{ "include_dead_torrents", "yes" },
|
||||
{ "sort", GetSortBy },
|
||||
{ "order", GetOrder }
|
||||
};
|
||||
|
||||
if (query.IsImdbQuery)
|
||||
|
@ -242,16 +273,16 @@ namespace Jackett.Common.Indexers
|
|||
searchParams.Add("search_type", "t_name");
|
||||
}
|
||||
|
||||
var searchPage = await RequestWithCookiesAndRetryAsync(
|
||||
SearchUrl, CookieHeader, RequestType.POST, null, searchParams);
|
||||
var searchPage = await RequestWithCookiesAndRetryAsync(SearchUrl, CookieHeader, RequestType.POST, null, searchParams);
|
||||
// Occasionally the cookies become invalid, login again if that happens
|
||||
if (searchPage.IsRedirect)
|
||||
{
|
||||
await ApplyConfiguration(null);
|
||||
searchPage = await RequestWithCookiesAndRetryAsync(
|
||||
SearchUrl, CookieHeader, RequestType.POST, null, searchParams);
|
||||
searchPage = await RequestWithCookiesAndRetryAsync(SearchUrl, CookieHeader, RequestType.POST, null, searchParams);
|
||||
}
|
||||
|
||||
var releases = new List<ReleaseInfo>();
|
||||
|
||||
try
|
||||
{
|
||||
var parser = new HtmlParser();
|
||||
|
|
Loading…
Add table
Reference in a new issue