bjshare: use cookie login method. resolves #12756 (#12757)

should also resolve #12746
This commit is contained in:
Uilton Oliveira
2021-12-31 14:35:30 -03:00
committed by GitHub
parent 627864111f
commit 434d574867

View File

@@ -22,7 +22,6 @@ namespace Jackett.Common.Indexers
[ExcludeFromCodeCoverage] [ExcludeFromCodeCoverage]
public class BJShare : BaseWebIndexer public class BJShare : BaseWebIndexer
{ {
private string LoginUrl => SiteLink + "login.php";
private string BrowseUrl => SiteLink + "torrents.php"; private string BrowseUrl => SiteLink + "torrents.php";
private string TodayUrl => SiteLink + "torrents.php?action=today"; private string TodayUrl => SiteLink + "torrents.php?action=today";
private static readonly Regex _EpisodeRegex = new Regex(@"(?:[SsEe]\d{2,4}){1,2}"); private static readonly Regex _EpisodeRegex = new Regex(@"(?:[SsEe]\d{2,4}){1,2}");
@@ -32,7 +31,7 @@ namespace Jackett.Common.Indexers
"https://bj-share.me/" "https://bj-share.me/"
}; };
private ConfigurationDataBasicLoginWithRSSAndDisplay ConfigData => (ConfigurationDataBasicLoginWithRSSAndDisplay)configData; private new ConfigurationDataCookie configData => (ConfigurationDataCookie)base.configData;
@@ -90,7 +89,7 @@ namespace Jackett.Common.Indexers
logger: l, logger: l,
p: ps, p: ps,
cacheService: cs, cacheService: cs,
configData: new ConfigurationDataBasicLoginWithRSSAndDisplay()) configData: new ConfigurationDataCookie())
{ {
Encoding = Encoding.UTF8; Encoding = Encoding.UTF8;
Language = "pt-BR"; Language = "pt-BR";
@@ -123,20 +122,21 @@ 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> CookieHeader = configData.Cookie.Value;
try
{ {
{"username", ConfigData.Username.Value}, var results = await PerformQuery(new TorznabQuery());
{"password", ConfigData.Password.Value}, if (!results.Any())
{"keeplogged", "1"} throw new Exception("Found 0 results in the tracker");
}; IsConfigured = true;
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, LoginUrl, true); SaveConfig();
await ConfigureIfOK( return IndexerConfigurationStatus.Completed;
result.Cookies, result.ContentString?.Contains("logout.php") == true, () => }
{ catch (Exception e)
var errorMessage = result.ContentString; {
throw new ExceptionWithConfigData(errorMessage, ConfigData); IsConfigured = false;
}); throw new Exception("Your cookie did not work: " + e.Message);
return IndexerConfigurationStatus.RequiresTesting; }
} }
private static string InternationalTitle(string title) private static string InternationalTitle(string title)
@@ -222,17 +222,14 @@ namespace Jackett.Common.Indexers
// until they or the source from where they get that info fix it... // until they or the source from where they get that info fix it...
if (IsAbsoluteNumbering(title)) if (IsAbsoluteNumbering(title))
{ {
title = Regex.Replace(title, @"(Ep[\.]?[ ]?)|([S]\d\d[Ee])", ""); title = Regex.Replace(title, @"(Ep[\.]?[ ]?)|([S]\d\d[Ee])", "E");
return title; return title;
} }
return title; return title;
} }
private bool IsSessionIsClosed(WebResult result) private bool IsSessionIsClosed(WebResult result) => result.IsRedirect && result.RedirectingTo.Contains("login.php");
{
return result.IsRedirect && result.RedirectingTo.Contains("login.php");
}
private string FixSearchTerm(TorznabQuery query) private string FixSearchTerm(TorznabQuery query)
{ {
@@ -265,14 +262,16 @@ namespace Jackett.Common.Indexers
{"searchsubmit", "1"} {"searchsubmit", "1"}
}; };
foreach (var cat in MapTorznabCapsToTrackers(query)) foreach (var cat in MapTorznabCapsToTrackers(query))
{
queryCollection.Add("filter_cat[" + cat + "]", "1"); queryCollection.Add("filter_cat[" + cat + "]", "1");
}
searchUrl += "?" + queryCollection.GetQueryString(); searchUrl += "?" + queryCollection.GetQueryString();
var results = await RequestWithCookiesAsync(searchUrl); var results = await RequestWithCookiesAsync(searchUrl);
if (IsSessionIsClosed(results)) if (IsSessionIsClosed(results))
{ {
// re-login throw new Exception("The user is not logged in. It is possible that the cookie has expired or you " +
await ApplyConfiguration(null); "made a mistake when copying it. Please check the settings.");
results = await RequestWithCookiesAsync(searchUrl);
} }
try try
@@ -436,9 +435,8 @@ namespace Jackett.Common.Indexers
var results = await RequestWithCookiesAsync(TodayUrl); var results = await RequestWithCookiesAsync(TodayUrl);
if (IsSessionIsClosed(results)) if (IsSessionIsClosed(results))
{ {
// re-login throw new Exception("The user is not logged in. It is possible that the cookie has expired or you " +
await ApplyConfiguration(null); "made a mistake when copying it. Please check the settings.");
results = await RequestWithCookiesAsync(TodayUrl);
} }
try try