mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
xspeeds: category filtering if single, prevent possible error in login, add sorting (#13966)
This commit is contained in:
@@ -142,8 +142,35 @@ namespace Jackett.Common.Indexers
|
|||||||
AddCategoryMapping("Wii Games", TorznabCatType.ConsoleWii);
|
AddCategoryMapping("Wii Games", TorznabCatType.ConsoleWii);
|
||||||
AddCategoryMapping("Wrestling", TorznabCatType.TVSport);
|
AddCategoryMapping("Wrestling", TorznabCatType.TVSport);
|
||||||
AddCategoryMapping("Xbox Games", TorznabCatType.ConsoleXBox);
|
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()
|
public override async Task<ConfigurationData> GetConfigurationForSetup()
|
||||||
{
|
{
|
||||||
var loginPage = await RequestWithCookiesAsync(LandingUrl);
|
var loginPage = await RequestWithCookiesAsync(LandingUrl);
|
||||||
@@ -170,7 +197,6 @@ namespace Jackett.Common.Indexers
|
|||||||
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
||||||
{
|
{
|
||||||
LoadValuesFromJson(configJson);
|
LoadValuesFromJson(configJson);
|
||||||
|
|
||||||
var pairs = new Dictionary<string, string>
|
var pairs = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "username", configData.Username.Value },
|
{ "username", configData.Username.Value },
|
||||||
@@ -183,15 +209,15 @@ namespace Jackett.Common.Indexers
|
|||||||
|
|
||||||
//var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink, true);
|
//var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink, true);
|
||||||
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, SearchUrl, LandingUrl, true);
|
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, SearchUrl, LandingUrl, true);
|
||||||
await ConfigureIfOK(result.Cookies, result.ContentString?.Contains("logout.php") == true,
|
await ConfigureIfOK(result.Cookies, result.ContentString?.Contains("logout.php") == true, () =>
|
||||||
() =>
|
|
||||||
{
|
{
|
||||||
var parser = new HtmlParser();
|
var parser = new HtmlParser();
|
||||||
var dom = parser.ParseDocument(result.ContentString);
|
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", " ");
|
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))
|
if (string.IsNullOrWhiteSpace(errorMessage))
|
||||||
errorMessage = dom.QuerySelector("div.notification-body").TextContent.Trim().Replace("\n\t", " ");
|
errorMessage = dom.QuerySelector("div.notification-body")?.TextContent.Trim().Replace("\n\t", " ");
|
||||||
throw new ExceptionWithConfigData(errorMessage, configData);
|
|
||||||
|
throw new ExceptionWithConfigData(errorMessage ?? "Login failed.", configData);
|
||||||
});
|
});
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -216,19 +242,24 @@ namespace Jackett.Common.Indexers
|
|||||||
IsConfigured = false;
|
IsConfigured = false;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return IndexerConfigurationStatus.RequiresTesting;
|
return IndexerConfigurationStatus.RequiresTesting;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
||||||
{
|
{
|
||||||
var releases = new List<ReleaseInfo>();
|
|
||||||
var searchString = query.GetQueryString();
|
var searchString = query.GetQueryString();
|
||||||
var prevCook = CookieHeader + "";
|
var prevCook = CookieHeader + "";
|
||||||
|
|
||||||
var searchParams = new Dictionary<string, string> {
|
var categoryMapping = MapTorznabCapsToTrackers(query);
|
||||||
|
|
||||||
|
var searchParams = new Dictionary<string, string>
|
||||||
|
{
|
||||||
{ "do", "search" },
|
{ "do", "search" },
|
||||||
{ "category", "0" },
|
{ "category", categoryMapping.FirstIfSingleOrDefault("0") }, // multi category search not supported
|
||||||
{ "include_dead_torrents", "no" }
|
{ "include_dead_torrents", "yes" },
|
||||||
|
{ "sort", GetSortBy },
|
||||||
|
{ "order", GetOrder }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (query.IsImdbQuery)
|
if (query.IsImdbQuery)
|
||||||
@@ -242,16 +273,16 @@ namespace Jackett.Common.Indexers
|
|||||||
searchParams.Add("search_type", "t_name");
|
searchParams.Add("search_type", "t_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchPage = await RequestWithCookiesAndRetryAsync(
|
var searchPage = await RequestWithCookiesAndRetryAsync(SearchUrl, CookieHeader, RequestType.POST, null, searchParams);
|
||||||
SearchUrl, CookieHeader, RequestType.POST, null, searchParams);
|
|
||||||
// Occasionally the cookies become invalid, login again if that happens
|
// Occasionally the cookies become invalid, login again if that happens
|
||||||
if (searchPage.IsRedirect)
|
if (searchPage.IsRedirect)
|
||||||
{
|
{
|
||||||
await ApplyConfiguration(null);
|
await ApplyConfiguration(null);
|
||||||
searchPage = await RequestWithCookiesAndRetryAsync(
|
searchPage = await RequestWithCookiesAndRetryAsync(SearchUrl, CookieHeader, RequestType.POST, null, searchParams);
|
||||||
SearchUrl, CookieHeader, RequestType.POST, null, searchParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var releases = new List<ReleaseInfo>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var parser = new HtmlParser();
|
var parser = new HtmlParser();
|
||||||
|
Reference in New Issue
Block a user