Skip to content

Commit

Permalink
core: refactor http webclient part 10 #8529 (#7729)
Browse files Browse the repository at this point in the history
Move WebResult String and Byte properties to base class
  • Loading branch information
cadatoiva authored and ngosang committed Sep 21, 2020
1 parent ab74421 commit 1252984
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/Abnormal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ private async Task<string> queryCache(string request)
/// <returns>Results from query</returns>
private async Task<string> queryTracker(string request)
{
WebClientStringResult results = null;
BaseWebResult results = null;

// Cache mode not enabled or cached file didn't exist for our query
output("\nQuerying tracker for results....");
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/AniDUB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ private static string GetDateFromDocument(IElement content)
return domDate.NodeValue.Trim();
}

private bool IsAuthorized(WebClientStringResult result) =>
private bool IsAuthorized(BaseWebResult result) =>
result.ContentString.Contains("index.php?action=logout");

private IEnumerable<int> ParseCategories(Uri showUri)
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/BJShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private string FixAbsoluteNumbering(string title)
return title;
}

private bool IsSessionIsClosed(WebClientStringResult result)
private bool IsSessionIsClosed(BaseWebResult result)
{
return result.IsRedirect && result.RedirectingTo.Contains("login.php");
}
Expand Down
16 changes: 8 additions & 8 deletions src/Jackett.Common/Indexers/BaseIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ protected async Task<byte[]> Download(Uri link, RequestType method, string refer
return response.ContentBytes;
}

protected async Task<WebClientByteResult> RequestBytesWithCookiesAndRetry(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null, IEnumerable<KeyValuePair<string, string>> data = null)
protected async Task<BaseWebResult> RequestBytesWithCookiesAndRetry(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null, IEnumerable<KeyValuePair<string, string>> data = null)
{
Exception lastException = null;
for (var i = 0; i < 3; i++)
Expand All @@ -432,7 +432,7 @@ protected async Task<WebClientByteResult> RequestBytesWithCookiesAndRetry(string
throw lastException;
}

protected async Task<WebClientStringResult> RequestStringWithCookies(string url, string cookieOverride = null, string referer = null, Dictionary<string, string> headers = null)
protected async Task<BaseWebResult> RequestStringWithCookies(string url, string cookieOverride = null, string referer = null, Dictionary<string, string> headers = null)
{
var request = new Utils.Clients.WebRequest()
{
Expand All @@ -452,7 +452,7 @@ protected async Task<WebClientStringResult> RequestStringWithCookies(string url,
return result;
}

protected async Task<WebClientStringResult> RequestStringWithCookiesAndRetry(string url, string cookieOverride = null, string referer = null, Dictionary<string, string> headers = null)
protected async Task<BaseWebResult> RequestStringWithCookiesAndRetry(string url, string cookieOverride = null, string referer = null, Dictionary<string, string> headers = null)
{
Exception lastException = null;
for (var i = 0; i < 3; i++)
Expand All @@ -472,7 +472,7 @@ protected async Task<WebClientStringResult> RequestStringWithCookiesAndRetry(str
throw lastException;
}

protected virtual async Task<WebClientByteResult> RequestBytesWithCookies(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null, IEnumerable<KeyValuePair<string, string>> data = null, Dictionary<string, string> headers = null)
protected virtual async Task<BaseWebResult> RequestBytesWithCookies(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null, IEnumerable<KeyValuePair<string, string>> data = null, Dictionary<string, string> headers = null)
{
var request = new Utils.Clients.WebRequest()
{
Expand All @@ -492,7 +492,7 @@ protected virtual async Task<WebClientByteResult> RequestBytesWithCookies(string
return result;
}

protected async Task<WebClientStringResult> PostDataWithCookies(string url, IEnumerable<KeyValuePair<string, string>> data, string cookieOverride = null, string referer = null, Dictionary<string, string> headers = null, string rawbody = null, bool? emulateBrowser = null)
protected async Task<BaseWebResult> PostDataWithCookies(string url, IEnumerable<KeyValuePair<string, string>> data, string cookieOverride = null, string referer = null, Dictionary<string, string> headers = null, string rawbody = null, bool? emulateBrowser = null)
{
var request = new Utils.Clients.WebRequest()
{
Expand All @@ -514,7 +514,7 @@ protected async Task<WebClientStringResult> PostDataWithCookies(string url, IEnu
return result;
}

protected async Task<WebClientStringResult> PostDataWithCookiesAndRetry(string url, IEnumerable<KeyValuePair<string, string>> data, string cookieOverride = null, string referer = null, Dictionary<string, string> headers = null, string rawbody = null, bool? emulateBrowser = null)
protected async Task<BaseWebResult> PostDataWithCookiesAndRetry(string url, IEnumerable<KeyValuePair<string, string>> data, string cookieOverride = null, string referer = null, Dictionary<string, string> headers = null, string rawbody = null, bool? emulateBrowser = null)
{
Exception lastException = null;
for (var i = 0; i < 3; i++)
Expand All @@ -534,7 +534,7 @@ protected async Task<WebClientStringResult> PostDataWithCookiesAndRetry(string u
throw lastException;
}

protected async Task<WebClientStringResult> RequestLoginAndFollowRedirect(string url, IEnumerable<KeyValuePair<string, string>> data, string cookies, bool returnCookiesFromFirstCall, string redirectUrlOverride = null, string referer = null, bool accumulateCookies = false)
protected async Task<BaseWebResult> RequestLoginAndFollowRedirect(string url, IEnumerable<KeyValuePair<string, string>> data, string cookies, bool returnCookiesFromFirstCall, string redirectUrlOverride = null, string referer = null, bool accumulateCookies = false)
{
var request = new Utils.Clients.WebRequest()
{
Expand Down Expand Up @@ -566,7 +566,7 @@ protected async Task<WebClientStringResult> RequestLoginAndFollowRedirect(string
return response;
}

protected void CheckTrackerDown(WebClientStringResult response)
protected void CheckTrackerDown(BaseWebResult response)
{
if (response.Status == System.Net.HttpStatusCode.BadGateway
|| response.Status == System.Net.HttpStatusCode.GatewayTimeout
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/BitHDTV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
{
{"cat", MapTorznabCapsToTrackers(query, true).FirstIfSingleOrDefault("0")}
};
var results = new List<WebClientStringResult>();
var results = new List<BaseWebResult>();
var search = new UriBuilder(SearchUrl);
if (query.IsImdbQuery)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Jackett.Common/Indexers/CardigannIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Jackett.Common.Indexers
public class CardigannIndexer : BaseWebIndexer
{
protected IndexerDefinition Definition;
protected WebClientStringResult landingResult;
protected BaseWebResult landingResult;
protected IHtmlDocument landingResultDocument;

protected List<string> DefaultCategories = new List<string>();
Expand Down Expand Up @@ -455,7 +455,7 @@ protected string applyGoTemplateText(string template, Dictionary<string, object>
return template;
}

protected bool checkForError(WebClientStringResult loginResult, IList<errorBlock> errorBlocks)
protected bool checkForError(BaseWebResult loginResult, IList<errorBlock> errorBlocks)
{
if (loginResult.Status == HttpStatusCode.Unauthorized) // e.g. used by YGGtorrent
throw new ExceptionWithConfigData("401 Unauthorized, check your credentials", configData);
Expand Down Expand Up @@ -702,7 +702,7 @@ protected async Task<bool> DoLogin()
landingResult = null;
landingResultDocument = null;

WebClientStringResult loginResult = null;
BaseWebResult loginResult = null;
var enctype = form.GetAttribute("enctype");
if (enctype == "multipart/form-data")
{
Expand Down Expand Up @@ -1334,7 +1334,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
logger.Info($"Fetching: {searchUrl}");

// send HTTP request
WebClientStringResult response = null;
BaseWebResult response = null;
Dictionary<string, string> headers = null;
if (Search.Headers != null)
{
Expand Down Expand Up @@ -1721,7 +1721,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
return releases;
}

protected async Task<WebClientByteResult> handleRequest(requestBlock request, Dictionary<string, object> variables = null, string referer = null)
protected async Task<BaseWebResult> handleRequest(requestBlock request, Dictionary<string, object> variables = null, string referer = null)
{
var requestLinkStr = resolvePath(applyGoTemplateText(request.Path, variables)).ToString();
logger.Debug($"CardigannIndexer ({Id}): handleRequest() requestLinkStr= {requestLinkStr}");
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/Cinecalidad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public override async Task<byte[]> Download(Uri link)
return null;
}

private List<ReleaseInfo> ParseReleases(WebClientStringResult response, TorznabQuery query)
private List<ReleaseInfo> ParseReleases(BaseWebResult response, TorznabQuery query)
{
var releases = new List<ReleaseInfo>();

Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/CorsaroRed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken
return IndexerConfigurationStatus.Completed;
}

private dynamic CheckResponse(WebClientStringResult result)
private dynamic CheckResponse(BaseWebResult result)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/DanishBits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected override string GetSearchString(TorznabQuery query)
return searchString;
}

protected override async Task<WebClientByteResult> RequestBytesWithCookies(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null, IEnumerable<KeyValuePair<string, string>> data = null, Dictionary<string, string> headers = null)
protected override async Task<BaseWebResult> RequestBytesWithCookies(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null, IEnumerable<KeyValuePair<string, string>> data = null, Dictionary<string, string> headers = null)
{
CookieHeader = null; // Download fill fail with cookies set
return await base.RequestBytesWithCookies(url, cookieOverride, method, referer, data, headers);
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/InternetArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
return releases;
}

private JArray ParseResponse(WebClientStringResult result)
private JArray ParseResponse(BaseWebResult result)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/LostFilm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
}
}

private async Task<WebClientStringResult> RequestStringAndRelogin(string url)
private async Task<BaseWebResult> RequestStringAndRelogin(string url)
{
var results = await RequestStringWithCookies(url);
if (results.ContentString.Contains("503 Service"))
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/NCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private async Task<List<ReleaseInfo>> PerformQueryAsync(TorznabQuery query, stri
return releases;
}

private List<ReleaseInfo> ParseTorrents(WebClientStringResult results, string episodeString, TorznabQuery query,
private List<ReleaseInfo> ParseTorrents(BaseWebResult results, string episodeString, TorznabQuery query,
int alreadyFound, int limit, int previouslyParsedOnPage)
{
var releases = new List<ReleaseInfo>();
Expand Down
10 changes: 5 additions & 5 deletions src/Jackett.Common/Indexers/NorBits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ private string BuildQuery(string term, TorznabQuery query, string url, int page
/// </summary>
/// <param name="request">URL created by Query Builder</param>
/// <returns>Results from query</returns>
private async Task<WebClientStringResult> QueryExec(string request)
private async Task<BaseWebResult> QueryExec(string request)
{
WebClientStringResult results;
BaseWebResult results;

// Switch in we are in DEV mode with Hard Drive Cache or not
if (DevMode && CacheMode)
Expand All @@ -482,9 +482,9 @@ private async Task<WebClientStringResult> QueryExec(string request)
/// </summary>
/// <param name="request">URL created by Query Builder</param>
/// <returns>Results from query</returns>
private async Task<WebClientStringResult> QueryCache(string request)
private async Task<BaseWebResult> QueryCache(string request)
{
WebClientStringResult results;
BaseWebResult results;

// Create Directory if not exist
System.IO.Directory.CreateDirectory(Directory);
Expand Down Expand Up @@ -519,7 +519,7 @@ private async Task<WebClientStringResult> QueryCache(string request)
/// </summary>
/// <param name="request">URL created by Query Builder</param>
/// <returns>Results from query</returns>
private async Task<WebClientStringResult> QueryTracker(string request)
private async Task<BaseWebResult> QueryTracker(string request)
{
// Cache mode not enabled or cached file didn't exist for our query
Output("\nQuerying tracker for results....");
Expand Down
10 changes: 5 additions & 5 deletions src/Jackett.Common/Indexers/NordicBits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ private string BuildQuery(string searchTerm, TorznabQuery query, string url, int
/// </summary>
/// <param name="request">URL created by Query Builder</param>
/// <returns>Results from query</returns>
private async Task<WebClientStringResult> QueryExec(string request)
private async Task<BaseWebResult> QueryExec(string request)
{
WebClientStringResult results;
BaseWebResult results;

// Switch in we are in DEV mode with Hard Drive Cache or not
if (DevMode && CacheMode)
Expand All @@ -553,9 +553,9 @@ private async Task<WebClientStringResult> QueryExec(string request)
/// </summary>
/// <param name="request">URL created by Query Builder</param>
/// <returns>Results from query</returns>
private async Task<WebClientStringResult> QueryCache(string request)
private async Task<BaseWebResult> QueryCache(string request)
{
WebClientStringResult results;
BaseWebResult results;

// Create Directory if not exist
System.IO.Directory.CreateDirectory(Directory);
Expand Down Expand Up @@ -590,7 +590,7 @@ private async Task<WebClientStringResult> QueryCache(string request)
/// </summary>
/// <param name="request">URL created by Query Builder</param>
/// <returns>Results from query</returns>
private async Task<WebClientStringResult> QueryTracker(string request)
private async Task<BaseWebResult> QueryTracker(string request)
{
// Cache mode not enabled or cached file didn't exist for our query
Output("\nQuerying tracker for results....");
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/Partis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
var releases = new List<ReleaseInfo>(); //List of releases initialization
var searchString = query.GetQueryString(); //get search string from query

WebClientStringResult results = null;
BaseWebResult results = null;
var queryCollection = new NameValueCollection();
var catList = MapTorznabCapsToTrackers(query); // map categories from query to indexer specific
var categ = string.Join(",", catList);
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/SceneTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public SceneTime(IIndexerConfigurationService configService, WebClient w, Logger

public override async Task<ConfigurationData> GetConfigurationForSetup()
{
WebClientStringResult loginPage;
BaseWebResult loginPage;
try
{
loginPage = await RequestStringWithCookies(StartPageUrl, string.Empty);
Expand Down
4 changes: 2 additions & 2 deletions src/Jackett.Common/Indexers/Shazbat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
{
var releases = new List<ReleaseInfo>();
var queryString = query.GetQueryString();
WebClientStringResult results = null;
BaseWebResult results = null;
var searchUrls = new List<string>();
if (!string.IsNullOrWhiteSpace(query.SanitizedSearchTerm))
{
Expand Down Expand Up @@ -170,7 +170,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
return releases;
}

private async Task<WebClientStringResult> ReloginIfNecessary(WebClientStringResult response)
private async Task<BaseWebResult> ReloginIfNecessary(BaseWebResult response)
{
if (response.ContentString.Contains("onclick=\"document.location='logout'\""))
return response;
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/SolidTorrents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken
return IndexerConfigurationStatus.Completed;
}

private JArray CheckResponse(WebClientStringResult result)
private JArray CheckResponse(BaseWebResult result)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/TVStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static double UploadFactorCalculator(DateTime dateTime, bool isSeasonPac
/// <param name="alreadyFound">Number of the already found torrents.(used for limit)</param>
/// <param name="limit">The limit to the number of torrents to download </param>
/// <param name="previouslyParsedOnPage">Current position in parsed results</param>
private async Task<List<ReleaseInfo>> ParseTorrentsAsync(WebClientStringResult results, int alreadyFound, int limit,
private async Task<List<ReleaseInfo>> ParseTorrentsAsync(BaseWebResult results, int alreadyFound, int limit,
int previouslyParsedOnPage)
{
var releases = new List<ReleaseInfo>();
Expand Down
2 changes: 1 addition & 1 deletion src/Jackett.Common/Indexers/TorrenTech.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
var releases = new List<ReleaseInfo>();
var searchString = query.GetQueryString();

WebClientStringResult results = null;
BaseWebResult results = null;
var queryCollection = new NameValueCollection
{
{ "act", "search" },
Expand Down

0 comments on commit 1252984

Please sign in to comment.