mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
norbits: cleaning, removed legacy dev tools. (#11677)
This commit is contained in:
@@ -3,9 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -18,7 +16,6 @@ using Jackett.Common.Models.IndexerConfig.Bespoke;
|
|||||||
using Jackett.Common.Services.Interfaces;
|
using Jackett.Common.Services.Interfaces;
|
||||||
using Jackett.Common.Utils;
|
using Jackett.Common.Utils;
|
||||||
using Jackett.Common.Utils.Clients;
|
using Jackett.Common.Utils.Clients;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
@@ -32,12 +29,6 @@ namespace Jackett.Common.Indexers
|
|||||||
private string SearchUrl => SiteLink + "browse.php";
|
private string SearchUrl => SiteLink + "browse.php";
|
||||||
private string TorrentDetailsUrl => SiteLink + "details.php?id={id}";
|
private string TorrentDetailsUrl => SiteLink + "details.php?id={id}";
|
||||||
private string TorrentDownloadUrl => SiteLink + "download.php?id={id}&passkey={passkey}";
|
private string TorrentDownloadUrl => SiteLink + "download.php?id={id}&passkey={passkey}";
|
||||||
private bool Latency => ConfigData.Latency.Value;
|
|
||||||
private bool DevMode => ConfigData.DevMode.Value;
|
|
||||||
private bool CacheMode => ConfigData.HardDriveCache.Value;
|
|
||||||
private static string Directory => Path.Combine(Path.GetTempPath(), "Jackett", MethodBase.GetCurrentMethod().DeclaringType?.Name);
|
|
||||||
|
|
||||||
private readonly Dictionary<string, string> _emulatedBrowserHeaders = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
private ConfigurationDataNorbits ConfigData => (ConfigurationDataNorbits)configData;
|
private ConfigurationDataNorbits ConfigData => (ConfigurationDataNorbits)configData;
|
||||||
|
|
||||||
@@ -113,26 +104,7 @@ namespace Jackett.Common.Indexers
|
|||||||
// Check & Validate Config
|
// Check & Validate Config
|
||||||
ValidateConfig();
|
ValidateConfig();
|
||||||
|
|
||||||
// Setting our data for a better emulated browser (maximum security)
|
await DoLoginAsync();
|
||||||
// TODO: Encoded Content not supported by Jackett at this time
|
|
||||||
// emulatedBrowserHeaders.Add("Accept-Encoding", "gzip, deflate");
|
|
||||||
|
|
||||||
// If we want to simulate a browser
|
|
||||||
if (ConfigData.Browser.Value)
|
|
||||||
{
|
|
||||||
// Clean headers
|
|
||||||
_emulatedBrowserHeaders.Clear();
|
|
||||||
|
|
||||||
// Inject headers
|
|
||||||
_emulatedBrowserHeaders.Add("Accept", ConfigData.HeaderAccept.Value);
|
|
||||||
_emulatedBrowserHeaders.Add("Accept-Language", ConfigData.HeaderAcceptLang.Value);
|
|
||||||
_emulatedBrowserHeaders.Add("DNT", Convert.ToInt32(ConfigData.HeaderDnt.Value).ToString());
|
|
||||||
_emulatedBrowserHeaders.Add("Upgrade-Insecure-Requests", Convert.ToInt32(ConfigData.HeaderUpgradeInsecure.Value).ToString());
|
|
||||||
_emulatedBrowserHeaders.Add("User-Agent", ConfigData.HeaderUserAgent.Value);
|
|
||||||
_emulatedBrowserHeaders.Add("Referer", LoginUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
await DoLogin();
|
|
||||||
|
|
||||||
return IndexerConfigurationStatus.RequiresTesting;
|
return IndexerConfigurationStatus.RequiresTesting;
|
||||||
}
|
}
|
||||||
@@ -141,19 +113,18 @@ namespace Jackett.Common.Indexers
|
|||||||
/// Perform login to racker
|
/// Perform login to racker
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task DoLogin()
|
private async Task DoLoginAsync()
|
||||||
{
|
{
|
||||||
// Build WebRequest for index
|
// Build WebRequest for index
|
||||||
var myIndexRequest = new WebRequest
|
var myIndexRequest = new WebRequest
|
||||||
{
|
{
|
||||||
Type = RequestType.GET,
|
Type = RequestType.GET,
|
||||||
Url = SiteLink,
|
Url = SiteLink,
|
||||||
Headers = _emulatedBrowserHeaders,
|
|
||||||
Encoding = Encoding
|
Encoding = Encoding
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get index page for cookies
|
// Get index page for cookies
|
||||||
Output("\nGetting index page (for cookies).. with " + SiteLink);
|
logger.Info("\nNorBits - Getting index page (for cookies).. with " + SiteLink);
|
||||||
var indexPage = await webclient.GetResultAsync(myIndexRequest);
|
var indexPage = await webclient.GetResultAsync(myIndexRequest);
|
||||||
|
|
||||||
// Building login form data
|
// Building login form data
|
||||||
@@ -167,15 +138,13 @@ namespace Jackett.Common.Indexers
|
|||||||
{
|
{
|
||||||
Type = RequestType.GET,
|
Type = RequestType.GET,
|
||||||
Url = LoginUrl,
|
Url = LoginUrl,
|
||||||
Headers = _emulatedBrowserHeaders,
|
|
||||||
Cookies = indexPage.Cookies,
|
Cookies = indexPage.Cookies,
|
||||||
Referer = SiteLink,
|
Referer = SiteLink,
|
||||||
Encoding = Encoding
|
Encoding = Encoding
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get login page -- (not used, but simulation needed by tracker security's checks)
|
// Get login page -- (not used, but simulation needed by tracker security's checks)
|
||||||
LatencyNow();
|
logger.Info("\nNorBits - Getting login page (user simulation).. with " + LoginUrl);
|
||||||
Output("\nGetting login page (user simulation).. with " + LoginUrl);
|
|
||||||
await webclient.GetResultAsync(myRequestLogin);
|
await webclient.GetResultAsync(myRequestLogin);
|
||||||
|
|
||||||
// Build WebRequest for submitting authentification
|
// Build WebRequest for submitting authentification
|
||||||
@@ -185,14 +154,12 @@ namespace Jackett.Common.Indexers
|
|||||||
Referer = LoginUrl,
|
Referer = LoginUrl,
|
||||||
Type = RequestType.POST,
|
Type = RequestType.POST,
|
||||||
Url = LoginCheckUrl,
|
Url = LoginCheckUrl,
|
||||||
Headers = _emulatedBrowserHeaders,
|
|
||||||
Cookies = indexPage.Cookies,
|
Cookies = indexPage.Cookies,
|
||||||
Encoding = Encoding
|
Encoding = Encoding
|
||||||
};
|
};
|
||||||
|
|
||||||
// Perform loggin
|
// Perform loggin
|
||||||
LatencyNow();
|
logger.Info("\nPerform loggin.. with " + LoginCheckUrl);
|
||||||
Output("\nPerform loggin.. with " + LoginCheckUrl);
|
|
||||||
var response = await webclient.GetResultAsync(request);
|
var response = await webclient.GetResultAsync(request);
|
||||||
|
|
||||||
// Test if we are logged in
|
// Test if we are logged in
|
||||||
@@ -204,36 +171,36 @@ namespace Jackett.Common.Indexers
|
|||||||
var redirectTo = response.RedirectingTo;
|
var redirectTo = response.RedirectingTo;
|
||||||
|
|
||||||
// Oops, unable to login
|
// Oops, unable to login
|
||||||
Output("-> Login failed: " + message, "error");
|
logger.Info("NorBits - Login failed: " + message, "error");
|
||||||
throw new ExceptionWithConfigData("Login failed: " + message, configData);
|
throw new ExceptionWithConfigData("Login failed: " + message, configData);
|
||||||
});
|
});
|
||||||
|
|
||||||
Output("\nCookies saved for future uses...");
|
logger.Info("\nNorBits - Cookies saved for future uses...");
|
||||||
ConfigData.CookieHeader.Value = indexPage.Cookies + " " + response.Cookies + " ts_username=" + ConfigData.Username.Value;
|
ConfigData.CookieHeader.Value = indexPage.Cookies + " " + response.Cookies + " ts_username=" + ConfigData.Username.Value;
|
||||||
|
|
||||||
Output("\n-> Login Success\n");
|
logger.Info("\nNorBits - Login Success\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check logged-in state for provider
|
/// Check logged-in state for provider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task CheckLogin()
|
private async Task CheckLoginAsync()
|
||||||
{
|
{
|
||||||
// Checking ...
|
// Checking ...
|
||||||
Output("\n-> Checking logged-in state....");
|
logger.Info("\nNorBits - Checking logged-in state....");
|
||||||
var loggedInCheck = await RequestWithCookiesAsync(SearchUrl);
|
var loggedInCheck = await RequestWithCookiesAsync(SearchUrl);
|
||||||
if (!loggedInCheck.ContentString.Contains("logout.php"))
|
if (!loggedInCheck.ContentString.Contains("logout.php"))
|
||||||
{
|
{
|
||||||
// Cookie expired, renew session on provider
|
// Cookie expired, renew session on provider
|
||||||
Output("-> Not logged, login now...\n");
|
logger.Info("NorBits - Not logged, login now...\n");
|
||||||
|
|
||||||
await DoLogin();
|
await DoLoginAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Already logged, session active
|
// Already logged, session active
|
||||||
Output("-> Already logged, continue...\n");
|
logger.Info("NorBits - Already logged, continue...\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,22 +216,7 @@ namespace Jackett.Common.Indexers
|
|||||||
var searchUrl = SearchUrl;
|
var searchUrl = SearchUrl;
|
||||||
|
|
||||||
// Check login before performing a query
|
// Check login before performing a query
|
||||||
await CheckLogin();
|
await CheckLoginAsync();
|
||||||
|
|
||||||
// Check cache first so we don't query the server (if search term used or not in dev mode)
|
|
||||||
if (!DevMode && !string.IsNullOrEmpty(exactSearchTerm))
|
|
||||||
{
|
|
||||||
lock (cache)
|
|
||||||
{
|
|
||||||
// Remove old cache items
|
|
||||||
CleanCache();
|
|
||||||
|
|
||||||
// Search in cache
|
|
||||||
var cachedResult = cache.FirstOrDefault(i => i.Query == exactSearchTerm);
|
|
||||||
if (cachedResult != null)
|
|
||||||
return cachedResult.Results.Select(s => (ReleaseInfo)s.Clone()).ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var SearchTerms = new List<string> { exactSearchTerm };
|
var SearchTerms = new List<string> { exactSearchTerm };
|
||||||
|
|
||||||
@@ -300,76 +252,41 @@ namespace Jackett.Common.Indexers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// No result found for this query
|
// No result found for this query
|
||||||
Output("\nNo result found for your query, please try another search term ...\n", "info");
|
logger.Info("\nNorBits - No result found for your query, please try another search term ...\n", "info");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Output("\nFound " + nbResults + " result(s) (+/- " + firstPageRows.Length + ") in " + pageLinkCount + " page(s) for this query !");
|
logger.Info("\nNorBits - Found " + nbResults + " result(s) (+/- " + firstPageRows.Length + ") in " + pageLinkCount + " page(s) for this query !");
|
||||||
Output("\nThere are " + firstPageRows.Length + " results on the first page !");
|
logger.Info("\nNorBits - There are " + firstPageRows.Length + " results on the first page !");
|
||||||
|
|
||||||
// Loop on results
|
// Loop on results
|
||||||
|
|
||||||
foreach (var row in firstPageRows)
|
foreach (var row in firstPageRows)
|
||||||
{
|
{
|
||||||
Output("Torrent #" + (releases.Count + 1));
|
var id = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(1)").GetAttribute("href").Split('=').Last(); // ID
|
||||||
|
var name = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(1)").GetAttribute("title"); // Release Name
|
||||||
// ID
|
var categoryName = row.QuerySelector("td:nth-of-type(1) > div > a:nth-of-type(1)").GetAttribute("title"); // Category
|
||||||
var id = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(1)").GetAttribute("href").Split('=').Last();
|
|
||||||
Output("ID: " + id);
|
|
||||||
|
|
||||||
// Release Name
|
|
||||||
var name = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(1)").GetAttribute("title");
|
|
||||||
|
|
||||||
// Category
|
|
||||||
var categoryName = row.QuerySelector("td:nth-of-type(1) > div > a:nth-of-type(1)").GetAttribute("title");
|
|
||||||
var mainCat = row.QuerySelector("td:nth-of-type(1) > div > a:nth-of-type(1)").GetAttribute("href").Split('?').Last();
|
var mainCat = row.QuerySelector("td:nth-of-type(1) > div > a:nth-of-type(1)").GetAttribute("href").Split('?').Last();
|
||||||
var qSubCat2 = row.QuerySelector("td:nth-of-type(1) > div > a[href^=\"/browse.php?sub2_cat[]=\"]");
|
var qSubCat2 = row.QuerySelector("td:nth-of-type(1) > div > a[href^=\"/browse.php?sub2_cat[]=\"]");
|
||||||
|
|
||||||
var cat = mainCat;
|
var cat = mainCat;
|
||||||
if (qSubCat2 != null)
|
if (qSubCat2 != null)
|
||||||
cat += '&' + qSubCat2.GetAttribute("href").Split('?').Last();
|
cat += '&' + qSubCat2.GetAttribute("href").Split('?').Last();
|
||||||
|
var seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(9)").TextContent); // Seeders
|
||||||
Output("Category: " + cat + " - " + categoryName);
|
var leechers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(10)").TextContent); // Leechers
|
||||||
|
var regexObj = new Regex(@"[^\d]"); // Completed
|
||||||
// Seeders
|
|
||||||
var seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(9)").TextContent);
|
|
||||||
Output("Seeders: " + seeders);
|
|
||||||
|
|
||||||
// Leechers
|
|
||||||
var leechers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(10)").TextContent);
|
|
||||||
Output("Leechers: " + leechers);
|
|
||||||
|
|
||||||
// Completed
|
|
||||||
var regexObj = new Regex(@"[^\d]");
|
|
||||||
var completed2 = row.QuerySelector("td:nth-of-type(8)").TextContent;
|
var completed2 = row.QuerySelector("td:nth-of-type(8)").TextContent;
|
||||||
var completed = ParseUtil.CoerceLong(regexObj.Replace(completed2, ""));
|
var completed = ParseUtil.CoerceLong(regexObj.Replace(completed2, ""));
|
||||||
Output("Completed: " + completed);
|
var qFiles = row.QuerySelector("td:nth-of-type(3) > a"); // Files
|
||||||
|
|
||||||
// Files
|
|
||||||
var qFiles = row.QuerySelector("td:nth-of-type(3) > a");
|
|
||||||
var files = qFiles != null ? ParseUtil.CoerceInt(Regex.Match(qFiles.TextContent, @"\d+").Value) : 1;
|
var files = qFiles != null ? ParseUtil.CoerceInt(Regex.Match(qFiles.TextContent, @"\d+").Value) : 1;
|
||||||
Output("Files: " + files);
|
var humanSize = row.QuerySelector("td:nth-of-type(7)").TextContent.ToLowerInvariant(); // Size
|
||||||
|
var size = ReleaseInfo.GetBytes(humanSize); // Date
|
||||||
// Size
|
|
||||||
var humanSize = row.QuerySelector("td:nth-of-type(7)").TextContent.ToLowerInvariant();
|
|
||||||
var size = ReleaseInfo.GetBytes(humanSize);
|
|
||||||
Output("Size: " + humanSize + " (" + size + " bytes)");
|
|
||||||
|
|
||||||
// --> Date
|
|
||||||
var dateTimeOrig = row.QuerySelector("td:nth-of-type(5)").TextContent;
|
var dateTimeOrig = row.QuerySelector("td:nth-of-type(5)").TextContent;
|
||||||
var dateTime = Regex.Replace(dateTimeOrig, @"<[^>]+>| ", "").Trim();
|
var dateTime = Regex.Replace(dateTimeOrig, @"<[^>]+>| ", "").Trim();
|
||||||
var date = DateTime.ParseExact(dateTime, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
|
var date = DateTime.ParseExact(dateTime, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
|
||||||
Output("Released on: " + date);
|
var details = new Uri(TorrentDetailsUrl.Replace("{id}", id.ToString())); // Description Link
|
||||||
|
var passkey = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(2)").GetAttribute("href"); // Download Link
|
||||||
// Torrent Details URL
|
|
||||||
var details = new Uri(TorrentDetailsUrl.Replace("{id}", id.ToString()));
|
|
||||||
Output("Details: " + details.AbsoluteUri);
|
|
||||||
|
|
||||||
// Torrent Download URL
|
|
||||||
var passkey = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(2)").GetAttribute("href");
|
|
||||||
var key = Regex.Match(passkey, "(?<=passkey\\=)([a-zA-z0-9]*)");
|
var key = Regex.Match(passkey, "(?<=passkey\\=)([a-zA-z0-9]*)");
|
||||||
var downloadLink = new Uri(TorrentDownloadUrl.Replace("{id}", id.ToString()).Replace("{passkey}", key.ToString()));
|
var downloadLink = new Uri(TorrentDownloadUrl.Replace("{id}", id.ToString()).Replace("{passkey}", key.ToString()));
|
||||||
Output("Download Link: " + downloadLink.AbsoluteUri);
|
|
||||||
|
|
||||||
// Building release infos
|
// Building release infos
|
||||||
var release = new ReleaseInfo
|
var release = new ReleaseInfo
|
||||||
@@ -462,7 +379,7 @@ namespace Jackett.Common.Indexers
|
|||||||
// Building our query
|
// Building our query
|
||||||
url += "?" + searchterm + "&" + parameters.GetQueryString() + "&" + CatQryStr;
|
url += "?" + searchterm + "&" + parameters.GetQueryString() + "&" + CatQryStr;
|
||||||
|
|
||||||
Output("\nBuilded query for \"" + term + "\"... " + url);
|
logger.Info("\nBuilded query for \"" + term + "\"... " + url);
|
||||||
|
|
||||||
// Return our search url
|
// Return our search url
|
||||||
return url;
|
return url;
|
||||||
@@ -473,58 +390,10 @@ namespace Jackett.Common.Indexers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request">URL created by Query Builder</param>
|
/// <param name="request">URL created by Query Builder</param>
|
||||||
/// <returns>Results from query</returns>
|
/// <returns>Results from query</returns>
|
||||||
private async Task<WebResult> QueryExec(string request)
|
private async Task<WebResult> QueryExecAsync(string request)
|
||||||
{
|
{
|
||||||
WebResult results;
|
WebResult results;
|
||||||
|
results = await QueryTrackerAsync(request);
|
||||||
// Switch in we are in DEV mode with Hard Drive Cache or not
|
|
||||||
if (DevMode && CacheMode)
|
|
||||||
{
|
|
||||||
// Check Cache before querying and load previous results if available
|
|
||||||
results = await QueryCache(request);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Querying tracker directly
|
|
||||||
results = await QueryTracker(request);
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get Torrents Page from Cache by Query Provided
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request">URL created by Query Builder</param>
|
|
||||||
/// <returns>Results from query</returns>
|
|
||||||
private async Task<WebResult> QueryCache(string request)
|
|
||||||
{
|
|
||||||
WebResult results;
|
|
||||||
|
|
||||||
// Create Directory if not exist
|
|
||||||
System.IO.Directory.CreateDirectory(Directory);
|
|
||||||
|
|
||||||
// Clean Storage Provider Directory from outdated cached queries
|
|
||||||
CleanCacheStorage();
|
|
||||||
|
|
||||||
// Create fingerprint for request
|
|
||||||
var file = Directory + request.GetHashCode() + ".json";
|
|
||||||
|
|
||||||
// Checking modes states
|
|
||||||
if (File.Exists(file))
|
|
||||||
{
|
|
||||||
// File exist... loading it right now !
|
|
||||||
Output("Loading results from hard drive cache ..." + request.GetHashCode() + ".json");
|
|
||||||
results = JsonConvert.DeserializeObject<WebResult>(File.ReadAllText(file));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// No cached file found, querying tracker directly
|
|
||||||
results = await QueryTracker(request);
|
|
||||||
|
|
||||||
// Cached file didn't exist for our query, writing it right now !
|
|
||||||
Output("Writing results to hard drive cache ..." + request.GetHashCode() + ".json");
|
|
||||||
File.WriteAllText(file, JsonConvert.SerializeObject(results));
|
|
||||||
}
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,91 +402,18 @@ namespace Jackett.Common.Indexers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request">URL created by Query Builder</param>
|
/// <param name="request">URL created by Query Builder</param>
|
||||||
/// <returns>Results from query</returns>
|
/// <returns>Results from query</returns>
|
||||||
private async Task<WebResult> QueryTracker(string request)
|
private async Task<WebResult> QueryTrackerAsync(string request)
|
||||||
{
|
{
|
||||||
// Cache mode not enabled or cached file didn't exist for our query
|
// Cache mode not enabled or cached file didn't exist for our query
|
||||||
Output("\nQuerying tracker for results....");
|
logger.Info("\nNorBits - Querying tracker for results....");
|
||||||
|
|
||||||
// Request our first page
|
// Request our first page
|
||||||
LatencyNow();
|
var results = await RequestWithCookiesAndRetryAsync(request, ConfigData.CookieHeader.Value, RequestType.GET, SearchUrl, null);
|
||||||
var results = await RequestWithCookiesAndRetryAsync(request, ConfigData.CookieHeader.Value, RequestType.GET, SearchUrl, null, _emulatedBrowserHeaders);
|
|
||||||
|
|
||||||
// Return results from tracker
|
// Return results from tracker
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean Hard Drive Cache Storage
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="force">Force Provider Folder deletion</param>
|
|
||||||
private void CleanCacheStorage(bool force = false)
|
|
||||||
{
|
|
||||||
// Check cleaning method
|
|
||||||
if (force)
|
|
||||||
{
|
|
||||||
// Deleting Provider Storage folder and all files recursively
|
|
||||||
Output("\nDeleting Provider Storage folder and all files recursively ...");
|
|
||||||
|
|
||||||
// Check if directory exist
|
|
||||||
if (System.IO.Directory.Exists(Directory))
|
|
||||||
{
|
|
||||||
// Delete storage directory of provider
|
|
||||||
System.IO.Directory.Delete(Directory, true);
|
|
||||||
Output("-> Storage folder deleted successfully.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// No directory, so nothing to do
|
|
||||||
Output("-> No Storage folder found for this provider !");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var i = 0;
|
|
||||||
// Check if there is file older than ... and delete them
|
|
||||||
Output("\nCleaning Provider Storage folder... in progress.");
|
|
||||||
System.IO.Directory.GetFiles(Directory)
|
|
||||||
.Select(f => new FileInfo(f))
|
|
||||||
.Where(f => f.LastAccessTime < DateTime.Now.AddMilliseconds(-Convert.ToInt32(ConfigData.HardDriveCacheKeepTime.Value)))
|
|
||||||
.ToList()
|
|
||||||
.ForEach(f =>
|
|
||||||
{
|
|
||||||
Output("Deleting cached file << " + f.Name + " >> ... done.");
|
|
||||||
f.Delete();
|
|
||||||
i++;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Inform on what was cleaned during process
|
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
Output("-> Deleted " + i + " cached files during cleaning.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Output("-> Nothing deleted during cleaning.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generate a random fake latency to avoid detection on tracker side
|
|
||||||
/// </summary>
|
|
||||||
private void LatencyNow()
|
|
||||||
{
|
|
||||||
// Need latency ?
|
|
||||||
if (Latency)
|
|
||||||
{
|
|
||||||
var random = new Random(DateTime.Now.Millisecond);
|
|
||||||
var waiting = random.Next(Convert.ToInt32(ConfigData.LatencyStart.Value),
|
|
||||||
Convert.ToInt32(ConfigData.LatencyEnd.Value));
|
|
||||||
Output("\nLatency Faker => Sleeping for " + waiting + " ms...");
|
|
||||||
|
|
||||||
// Sleep now...
|
|
||||||
System.Threading.Thread.Sleep(waiting);
|
|
||||||
}
|
|
||||||
// Generate a random value in our range
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Find torrent rows in search pages
|
/// Find torrent rows in search pages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -634,7 +430,7 @@ namespace Jackett.Common.Indexers
|
|||||||
{
|
{
|
||||||
// Retrieving ID from link provided
|
// Retrieving ID from link provided
|
||||||
var id = ParseUtil.CoerceInt(Regex.Match(link.AbsoluteUri, @"\d+").Value);
|
var id = ParseUtil.CoerceInt(Regex.Match(link.AbsoluteUri, @"\d+").Value);
|
||||||
Output("Torrent Requested ID: " + id);
|
logger.Info("NorBits - Torrent Requested ID: " + id);
|
||||||
|
|
||||||
// Building login form data
|
// Building login form data
|
||||||
var pairs = new Dictionary<string, string> {
|
var pairs = new Dictionary<string, string> {
|
||||||
@@ -642,67 +438,19 @@ namespace Jackett.Common.Indexers
|
|||||||
{ "_", string.Empty } // ~~ Strange, blank param...
|
{ "_", string.Empty } // ~~ Strange, blank param...
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add emulated XHR request
|
|
||||||
_emulatedBrowserHeaders.Add("X-Prototype-Version", "1.6.0.3");
|
|
||||||
_emulatedBrowserHeaders.Add("X-Requested-With", "XMLHttpRequest");
|
|
||||||
|
|
||||||
// Get torrent file now
|
// Get torrent file now
|
||||||
Output("Getting torrent file now....");
|
|
||||||
var response = await base.Download(link);
|
var response = await base.Download(link);
|
||||||
|
|
||||||
// Remove our XHR request header
|
|
||||||
_emulatedBrowserHeaders.Remove("X-Prototype-Version");
|
|
||||||
_emulatedBrowserHeaders.Remove("X-Requested-With");
|
|
||||||
|
|
||||||
// Return content
|
// Return content
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Output message for logging or developpment (console)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">Message to output</param>
|
|
||||||
/// <param name="level">Level for Logger</param>
|
|
||||||
private void Output(string message, string level = "debug")
|
|
||||||
{
|
|
||||||
// Check if we are in dev mode
|
|
||||||
if (DevMode)
|
|
||||||
{
|
|
||||||
// Output message to console
|
|
||||||
Console.WriteLine(message);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Send message to logger with level
|
|
||||||
switch (level)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
goto case "debug";
|
|
||||||
case "debug":
|
|
||||||
// Only if Debug Level Enabled on Jackett
|
|
||||||
if (logger.IsDebugEnabled)
|
|
||||||
{
|
|
||||||
logger.Debug(message);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "info":
|
|
||||||
logger.Info(message);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "error":
|
|
||||||
logger.Error(message);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Validate Config entered by user on Jackett
|
/// Validate Config entered by user on Jackett
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ValidateConfig()
|
private void ValidateConfig()
|
||||||
{
|
{
|
||||||
Output("\nValidating Settings ... \n");
|
logger.Info("\nNorBits - Validating Settings ... \n");
|
||||||
|
|
||||||
// Check Username Setting
|
// Check Username Setting
|
||||||
if (string.IsNullOrEmpty(ConfigData.Username.Value))
|
if (string.IsNullOrEmpty(ConfigData.Username.Value))
|
||||||
@@ -711,7 +459,7 @@ namespace Jackett.Common.Indexers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Output("Validated Setting -- Username (auth) => " + ConfigData.Username.Value);
|
logger.Info("NorBits - Validated Setting -- Username (auth) => " + ConfigData.Username.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Password Setting
|
// Check Password Setting
|
||||||
@@ -721,7 +469,7 @@ namespace Jackett.Common.Indexers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Output("Validated Setting -- Password (auth) => " + ConfigData.Password.Value);
|
logger.Info("NorBits - Validated Setting -- Password (auth) => " + ConfigData.Password.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Max Page Setting
|
// Check Max Page Setting
|
||||||
@@ -729,7 +477,7 @@ namespace Jackett.Common.Indexers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Output("Validated Setting -- Max Pages => " + Convert.ToInt32(ConfigData.Pages.Value));
|
logger.Info("NorBits - Validated Setting -- Max Pages => " + Convert.ToInt32(ConfigData.Pages.Value));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -740,121 +488,6 @@ namespace Jackett.Common.Indexers
|
|||||||
{
|
{
|
||||||
throw new ExceptionWithConfigData("Please enter a maximum number of pages to crawl !", ConfigData);
|
throw new ExceptionWithConfigData("Please enter a maximum number of pages to crawl !", ConfigData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Latency Setting
|
|
||||||
if (ConfigData.Latency.Value)
|
|
||||||
{
|
|
||||||
Output("\nValidated Setting -- Latency Simulation enabled");
|
|
||||||
|
|
||||||
// Check Latency Start Setting
|
|
||||||
if (!string.IsNullOrEmpty(ConfigData.LatencyStart.Value))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Output("Validated Setting -- Latency Start => " + Convert.ToInt32(ConfigData.LatencyStart.Value));
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
throw new ExceptionWithConfigData("Please enter a numeric latency start in ms !", ConfigData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ExceptionWithConfigData("Latency Simulation enabled, Please enter a start latency !", ConfigData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check Latency End Setting
|
|
||||||
if (!string.IsNullOrEmpty(ConfigData.LatencyEnd.Value))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Output("Validated Setting -- Latency End => " + Convert.ToInt32(ConfigData.LatencyEnd.Value));
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
throw new ExceptionWithConfigData("Please enter a numeric latency end in ms !", ConfigData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ExceptionWithConfigData("Latency Simulation enabled, Please enter a end latency !", ConfigData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check Browser Setting
|
|
||||||
if (ConfigData.Browser.Value)
|
|
||||||
{
|
|
||||||
Output("\nValidated Setting -- Browser Simulation enabled");
|
|
||||||
|
|
||||||
// Check ACCEPT header Setting
|
|
||||||
if (string.IsNullOrEmpty(ConfigData.HeaderAccept.Value))
|
|
||||||
{
|
|
||||||
throw new ExceptionWithConfigData("Browser Simulation enabled, Please enter an ACCEPT header !", ConfigData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Output("Validated Setting -- ACCEPT (header) => " + ConfigData.HeaderAccept.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check ACCEPT-LANG header Setting
|
|
||||||
if (string.IsNullOrEmpty(ConfigData.HeaderAcceptLang.Value))
|
|
||||||
{
|
|
||||||
throw new ExceptionWithConfigData("Browser Simulation enabled, Please enter an ACCEPT-LANG header !", ConfigData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Output("Validated Setting -- ACCEPT-LANG (header) => " + ConfigData.HeaderAcceptLang.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check USER-AGENT header Setting
|
|
||||||
if (string.IsNullOrEmpty(ConfigData.HeaderUserAgent.Value))
|
|
||||||
{
|
|
||||||
throw new ExceptionWithConfigData("Browser Simulation enabled, Please enter an USER-AGENT header !", ConfigData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Output("Validated Setting -- USER-AGENT (header) => " + ConfigData.HeaderUserAgent.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Browser simulation must be enabled (otherwhise, this provider will not work due to tracker's security)
|
|
||||||
throw new ExceptionWithConfigData("Browser Simulation must be enabled for this provider to work, please enable it !", ConfigData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check Dev Cache Settings
|
|
||||||
if (ConfigData.HardDriveCache.Value)
|
|
||||||
{
|
|
||||||
Output("\nValidated Setting -- DEV Hard Drive Cache enabled");
|
|
||||||
|
|
||||||
// Check if Dev Mode enabled !
|
|
||||||
if (!ConfigData.DevMode.Value)
|
|
||||||
{
|
|
||||||
throw new ExceptionWithConfigData("Hard Drive is enabled but not in DEV MODE, Please enable DEV MODE !", ConfigData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check Cache Keep Time Setting
|
|
||||||
if (!string.IsNullOrEmpty(ConfigData.HardDriveCacheKeepTime.Value))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Output("Validated Setting -- Cache Keep Time (ms) => " + Convert.ToInt32(ConfigData.HardDriveCacheKeepTime.Value));
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
throw new ExceptionWithConfigData("Please enter a numeric hard drive keep time in ms !", ConfigData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ExceptionWithConfigData("Hard Drive Cache enabled, Please enter a maximum keep time for cache !", ConfigData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Delete cache if previously existed
|
|
||||||
CleanCacheStorage(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,22 +11,6 @@ namespace Jackett.Common.Models.IndexerConfig.Bespoke
|
|||||||
public DisplayInfoConfigurationItem PagesWarning { get; private set; }
|
public DisplayInfoConfigurationItem PagesWarning { get; private set; }
|
||||||
public StringConfigurationItem Pages { get; private set; }
|
public StringConfigurationItem Pages { get; private set; }
|
||||||
public BoolConfigurationItem UseFullSearch { get; private set; }
|
public BoolConfigurationItem UseFullSearch { get; private set; }
|
||||||
public DisplayInfoConfigurationItem SecurityWarning { get; private set; }
|
|
||||||
public BoolConfigurationItem Latency { get; private set; }
|
|
||||||
public BoolConfigurationItem Browser { get; private set; }
|
|
||||||
public DisplayInfoConfigurationItem LatencyWarning { get; private set; }
|
|
||||||
public StringConfigurationItem LatencyStart { get; private set; }
|
|
||||||
public StringConfigurationItem LatencyEnd { get; private set; }
|
|
||||||
public DisplayInfoConfigurationItem HeadersWarning { get; private set; }
|
|
||||||
public StringConfigurationItem HeaderAccept { get; private set; }
|
|
||||||
public StringConfigurationItem HeaderAcceptLang { get; private set; }
|
|
||||||
public BoolConfigurationItem HeaderDnt { get; private set; }
|
|
||||||
public BoolConfigurationItem HeaderUpgradeInsecure { get; private set; }
|
|
||||||
public StringConfigurationItem HeaderUserAgent { get; private set; }
|
|
||||||
public DisplayInfoConfigurationItem DevWarning { get; private set; }
|
|
||||||
public BoolConfigurationItem DevMode { get; private set; }
|
|
||||||
public BoolConfigurationItem HardDriveCache { get; private set; }
|
|
||||||
public StringConfigurationItem HardDriveCacheKeepTime { get; private set; }
|
|
||||||
|
|
||||||
public ConfigurationDataNorbits()
|
public ConfigurationDataNorbits()
|
||||||
{
|
{
|
||||||
@@ -36,22 +20,6 @@ namespace Jackett.Common.Models.IndexerConfig.Bespoke
|
|||||||
PagesWarning = new DisplayInfoConfigurationItem("Preferences", "<b>Preferences Configuration</b> (<i>Tweak your search settings</i>),<br /><br /> <ul><li><b>Max Pages to Process</b> let you specify how many page (max) Jackett can process when doing a search. Setting a value <b>higher than 4 is dangerous</b> for you account ! (<b>Result of too many requests to tracker...that <u>will be suspect</u></b>).</li></ul>");
|
PagesWarning = new DisplayInfoConfigurationItem("Preferences", "<b>Preferences Configuration</b> (<i>Tweak your search settings</i>),<br /><br /> <ul><li><b>Max Pages to Process</b> let you specify how many page (max) Jackett can process when doing a search. Setting a value <b>higher than 4 is dangerous</b> for you account ! (<b>Result of too many requests to tracker...that <u>will be suspect</u></b>).</li></ul>");
|
||||||
Pages = new StringConfigurationItem("Max Pages to Process (Required)") { Value = "4" };
|
Pages = new StringConfigurationItem("Max Pages to Process (Required)") { Value = "4" };
|
||||||
UseFullSearch = new BoolConfigurationItem("Enable search in description.") { Value = false };
|
UseFullSearch = new BoolConfigurationItem("Enable search in description.") { Value = false };
|
||||||
SecurityWarning = new DisplayInfoConfigurationItem("Security", "<b>Security Configuration</b> (<i>Read this area carefully !</i>),<br /><br /> <ul><li><b>Latency Simulation</b> will simulate human browsing with Jacket by pausing Jacket for an random time between each request, to fake a real content browsing.</li><li><b>Browser Simulation</b> will simulate a real human browser by injecting additionals headers when doing requests to tracker.<b>You must enable it to use this provider!</b></li></ul>");
|
|
||||||
Latency = new BoolConfigurationItem("Latency Simulation (Optional)") { Value = false };
|
|
||||||
Browser = new BoolConfigurationItem("Browser Simulation (Forced)") { Value = true };
|
|
||||||
LatencyWarning = new DisplayInfoConfigurationItem("Simulate Latency", "<b>Latency Configuration</b> (<i>Required if latency simulation enabled</i>),<br /><br/> <ul><li>By filling this range, <b>Jackett will make a random timed pause</b> <u>between requests</u> to tracker <u>to simulate a real browser</u>.</li><li>MilliSeconds <b>only</b></li></ul>");
|
|
||||||
LatencyStart = new StringConfigurationItem("Minimum Latency (ms)") { Value = "1589" };
|
|
||||||
LatencyEnd = new StringConfigurationItem("Maximum Latency (ms)") { Value = "3674" };
|
|
||||||
HeadersWarning = new DisplayInfoConfigurationItem("Injecting headers", "<b>Browser Headers Configuration</b> (<i>Required if browser simulation enabled</i>),<br /><br /> <ul><li>By filling these fields, <b>Jackett will inject headers</b> with your values <u>to simulate a real browser</u>.</li><li>You can get <b>your browser values</b> here: <a href='https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending' target='blank'>www.whatismybrowser.com</a></li></ul><br /><i><b>Note that</b> some headers are not necessary because they are injected automatically by this provider such as Accept_Encoding, Connection, Host or X-Requested-With</i>");
|
|
||||||
HeaderAccept = new StringConfigurationItem("Accept") { Value = "" };
|
|
||||||
HeaderAcceptLang = new StringConfigurationItem("Accept-Language") { Value = "" };
|
|
||||||
HeaderDnt = new BoolConfigurationItem("DNT") { Value = false };
|
|
||||||
HeaderUpgradeInsecure = new BoolConfigurationItem("Upgrade-Insecure-Requests") { Value = false };
|
|
||||||
HeaderUserAgent = new StringConfigurationItem("User-Agent") { Value = "" };
|
|
||||||
DevWarning = new DisplayInfoConfigurationItem("Development", "<b>Development Facility</b> (<i>For Developers ONLY</i>),<br /><br /> <ul><li>By enabling development mode, <b>Jackett will bypass his cache</b> and will <u>output debug messages to console</u> instead of his log file.</li><li>By enabling Hard Drive Cache, <b>This provider</b> will <u>save each query answers from tracker</u> in temp directory, in fact this reduce drastically HTTP requests when building a provider at parsing step for example. So, <b> Jackett will search for a cached query answer on hard drive before executing query on tracker side !</b> <i>DEV MODE must be enabled to use it !</li></ul>");
|
|
||||||
DevMode = new BoolConfigurationItem("Enable DEV MODE (Developers ONLY)") { Value = false };
|
|
||||||
HardDriveCache = new BoolConfigurationItem("Enable HARD DRIVE CACHE (Developers ONLY)") { Value = false };
|
|
||||||
HardDriveCacheKeepTime = new StringConfigurationItem("Keep Cached files for (ms)") { Value = "300000" };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user