Cardigann: support errors on search

This commit is contained in:
kaso17
2017-03-07 12:27:34 +01:00
parent 8e9f463bb5
commit 6c5433e7ba

View File

@@ -192,6 +192,7 @@ namespace Jackett.Indexers
public List<searchPathBlock> Paths { get; set; } public List<searchPathBlock> Paths { get; set; }
public List<filterBlock> Keywordsfilters { get; set; } public List<filterBlock> Keywordsfilters { get; set; }
public Dictionary<string, string> Inputs { get; set; } public Dictionary<string, string> Inputs { get; set; }
public List<errorBlock> Error { get; set; }
public rowsBlock Rows { get; set; } public rowsBlock Rows { get; set; }
public KeyValuePairList Fields { get; set; } public KeyValuePairList Fields { get; set; }
} }
@@ -494,26 +495,24 @@ namespace Jackett.Indexers
return template; return template;
} }
protected bool checkForLoginError(WebClientStringResult loginResult) protected bool checkForError(WebClientStringResult loginResult, IList<errorBlock> errorBlocks)
{ {
var ErrorBlocks = Definition.Login.Error; if (errorBlocks == null)
if (ErrorBlocks == null)
return true; // no error return true; // no error
var loginResultParser = new HtmlParser(); var ResultParser = new HtmlParser();
var loginResultDocument = loginResultParser.Parse(loginResult.Content); var ResultDocument = ResultParser.Parse(loginResult.Content);
foreach (errorBlock error in ErrorBlocks) foreach (errorBlock error in errorBlocks)
{ {
var selection = loginResultDocument.QuerySelector(error.Selector); var selection = ResultDocument.QuerySelector(error.Selector);
if (selection != null) if (selection != null)
{ {
string errorMessage = selection.TextContent; string errorMessage = selection.TextContent;
if (error.Message != null) if (error.Message != null)
{ {
errorMessage = handleSelector(error.Message, loginResultDocument.FirstElementChild); errorMessage = handleSelector(error.Message, ResultDocument.FirstElementChild);
} }
throw new ExceptionWithConfigData(string.Format("Login failed: {0}", errorMessage.Trim()), configData); throw new ExceptionWithConfigData(string.Format("Error: {0}", errorMessage.Trim()), configData);
} }
} }
return true; // no error return true; // no error
@@ -540,7 +539,7 @@ namespace Jackett.Indexers
var loginResult = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink, true); var loginResult = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink, true);
configData.CookieHeader.Value = loginResult.Cookies; configData.CookieHeader.Value = loginResult.Cookies;
checkForLoginError(loginResult); checkForError(loginResult, Definition.Login.Error);
} }
else if (Login.Method == "form") else if (Login.Method == "form")
{ {
@@ -750,7 +749,7 @@ namespace Jackett.Indexers
configData.CookieHeader.Value = loginResult.Cookies; configData.CookieHeader.Value = loginResult.Cookies;
checkForLoginError(loginResult); checkForError(loginResult, Definition.Login.Error);
} }
else if (Login.Method == "cookie") else if (Login.Method == "cookie")
{ {
@@ -770,7 +769,7 @@ namespace Jackett.Indexers
var loginResult = await RequestStringWithCookies(LoginUrl, null, SiteLink); var loginResult = await RequestStringWithCookies(LoginUrl, null, SiteLink);
configData.CookieHeader.Value = loginResult.Cookies; configData.CookieHeader.Value = loginResult.Cookies;
checkForLoginError(loginResult); checkForError(loginResult, Definition.Login.Error);
} }
else else
{ {
@@ -1205,10 +1204,12 @@ namespace Jackett.Indexers
throw new Exception(string.Format("Relogin failed")); throw new Exception(string.Format("Relogin failed"));
await TestLogin(); await TestLogin();
response = await RequestStringWithCookies(searchUrl); response = await RequestStringWithCookies(searchUrl);
results = results = response.Content; results = response.Content;
SearchResultDocument = SearchResultParser.Parse(results); SearchResultDocument = SearchResultParser.Parse(results);
} }
checkForError(response, Definition.Search.Error);
var RowsDom = SearchResultDocument.QuerySelectorAll(Search.Rows.Selector); var RowsDom = SearchResultDocument.QuerySelectorAll(Search.Rows.Selector);
List<IElement> Rows = new List<IElement>(); List<IElement> Rows = new List<IElement>();
foreach (var RowDom in RowsDom) foreach (var RowDom in RowsDom)