mirror of
https://github.com/Jackett/Jackett
synced 2025-03-09 13:52:03 +00:00
norbits: refactor parsing (#13955)
This commit is contained in:
parent
40fcb1e43b
commit
0ba4d305b0
1 changed files with 44 additions and 66 deletions
|
@ -27,8 +27,6 @@ namespace Jackett.Common.Indexers
|
|||
private string LoginUrl => SiteLink + "login.php";
|
||||
private string LoginCheckUrl => SiteLink + "takelogin.php";
|
||||
private string SearchUrl => SiteLink + "browse.php";
|
||||
private string TorrentDetailsUrl => SiteLink + "details.php?id={id}";
|
||||
private string TorrentDownloadUrl => SiteLink + "download.php?id={id}&passkey={passkey}";
|
||||
|
||||
private ConfigurationDataNorbits ConfigData => (ConfigurationDataNorbits)configData;
|
||||
|
||||
|
@ -218,14 +216,14 @@ namespace Jackett.Common.Indexers
|
|||
// Check login before performing a query
|
||||
await CheckLoginAsync();
|
||||
|
||||
var SearchTerms = new List<string> { exactSearchTerm };
|
||||
var searchTerms = new List<string> { exactSearchTerm };
|
||||
|
||||
// duplicate search without diacritics
|
||||
var baseSearchTerm = StringUtil.RemoveDiacritics(exactSearchTerm);
|
||||
if (baseSearchTerm != exactSearchTerm)
|
||||
SearchTerms.Add(baseSearchTerm);
|
||||
searchTerms.Add(baseSearchTerm);
|
||||
|
||||
foreach (var searchTerm in SearchTerms)
|
||||
foreach (var searchTerm in searchTerms)
|
||||
{
|
||||
// Build our query
|
||||
var request = BuildQuery(searchTerm, query, searchUrl);
|
||||
|
@ -259,49 +257,38 @@ namespace Jackett.Common.Indexers
|
|||
logger.Info("\nNorBits - Found " + nbResults + " result(s) (+/- " + firstPageRows.Length + ") in " + pageLinkCount + " page(s) for this query !");
|
||||
logger.Info("\nNorBits - There are " + firstPageRows.Length + " results on the first page !");
|
||||
|
||||
// Loop on results
|
||||
|
||||
foreach (var row in firstPageRows)
|
||||
{
|
||||
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
|
||||
var categoryName = row.QuerySelector("td:nth-of-type(1) > div > a:nth-of-type(1)").GetAttribute("title"); // Category
|
||||
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 cat = mainCat;
|
||||
if (qSubCat2 != null)
|
||||
cat += '&' + qSubCat2.GetAttribute("href").Split('?').Last();
|
||||
var seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(9)").TextContent); // Seeders
|
||||
var leechers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(10)").TextContent); // Leechers
|
||||
var regexObj = new Regex(@"[^\d]"); // Completed
|
||||
var completed2 = row.QuerySelector("td:nth-of-type(8)").TextContent;
|
||||
var completed = ParseUtil.CoerceLong(regexObj.Replace(completed2, ""));
|
||||
var qFiles = row.QuerySelector("td:nth-of-type(3) > a"); // Files
|
||||
var files = qFiles != null ? ParseUtil.CoerceInt(Regex.Match(qFiles.TextContent, @"\d+").Value) : 1;
|
||||
var humanSize = row.QuerySelector("td:nth-of-type(7)").TextContent.ToLowerInvariant(); // Size
|
||||
var size = ReleaseInfo.GetBytes(humanSize); // Date
|
||||
var dateTimeOrig = row.QuerySelector("td:nth-of-type(5)").TextContent;
|
||||
var dateTime = Regex.Replace(dateTimeOrig, @"<[^>]+>| ", "").Trim();
|
||||
var date = DateTime.ParseExact(dateTime, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
|
||||
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
|
||||
var key = Regex.Match(passkey, "(?<=passkey\\=)([a-zA-z0-9]*)");
|
||||
var downloadLink = new Uri(TorrentDownloadUrl.Replace("{id}", id.ToString()).Replace("{passkey}", key.ToString()));
|
||||
var link = new Uri(SiteLink + row.QuerySelector("td:nth-of-type(2) > a[href*=\"download.php?id=\"]")?.GetAttribute("href").TrimStart('/'));
|
||||
var qDetails = row.QuerySelector("td:nth-of-type(2) > a[href*=\"details.php?id=\"]");
|
||||
|
||||
var title = qDetails?.GetAttribute("title").Trim();
|
||||
var details = new Uri(SiteLink + qDetails?.GetAttribute("href").TrimStart('/'));
|
||||
|
||||
var mainCategory = row.QuerySelector("td:nth-of-type(1) > div > a[href*=\"main_cat[]\"]")?.GetAttribute("href")?.Split('?').Last();
|
||||
var secondCategory = row.QuerySelector("td:nth-of-type(1) > div > a[href*=\"sub2_cat[]\"]")?.GetAttribute("href")?.Split('?').Last();
|
||||
|
||||
var categoryList = new[] { mainCategory, secondCategory };
|
||||
var cat = string.Join("&", categoryList.Where(c => !string.IsNullOrWhiteSpace(c)));
|
||||
|
||||
var seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(9)").TextContent);
|
||||
var leechers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(10)").TextContent);
|
||||
|
||||
// Building release infos
|
||||
var release = new ReleaseInfo
|
||||
{
|
||||
Category = MapTrackerCatToNewznab(cat),
|
||||
Title = name,
|
||||
Seeders = seeders,
|
||||
Peers = seeders + leechers,
|
||||
PublishDate = date,
|
||||
Size = size,
|
||||
Files = files,
|
||||
Grabs = completed,
|
||||
Guid = details,
|
||||
Details = details,
|
||||
Link = downloadLink,
|
||||
Link = link,
|
||||
Title = title,
|
||||
Category = MapTrackerCatToNewznab(cat),
|
||||
Size = ReleaseInfo.GetBytes(row.QuerySelector("td:nth-of-type(7)").TextContent),
|
||||
Files = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(3) > a")?.TextContent.Trim()),
|
||||
Grabs = ParseUtil.CoerceLong(row.QuerySelector("td:nth-of-type(8)")?.FirstChild?.TextContent.Trim()),
|
||||
Seeders = seeders,
|
||||
Peers = seeders + leechers,
|
||||
PublishDate = DateTime.ParseExact(row.QuerySelector("td:nth-of-type(5)")?.TextContent.Trim(), "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture),
|
||||
DownloadVolumeFactor = 1,
|
||||
UploadVolumeFactor = 1,
|
||||
MinimumRatio = 1,
|
||||
MinimumSeedTime = 172800 // 48 hours
|
||||
};
|
||||
|
@ -311,8 +298,7 @@ namespace Jackett.Common.Indexers
|
|||
{
|
||||
genres = genres.Trim().Replace("\xA0", " ").Replace("(", "").Replace(")", "").Replace(" | ", ",");
|
||||
release.Description = genres;
|
||||
if (release.Genres == null)
|
||||
release.Genres = new List<string>();
|
||||
release.Genres ??= new List<string>();
|
||||
release.Genres = release.Genres.Union(genres.Split(',')).ToList();
|
||||
}
|
||||
|
||||
|
@ -326,10 +312,6 @@ namespace Jackett.Common.Indexers
|
|||
release.DownloadVolumeFactor = 0.5;
|
||||
else if (row.QuerySelector("img[title=\"90% Freeleech\"]") != null)
|
||||
release.DownloadVolumeFactor = 0.1;
|
||||
else
|
||||
release.DownloadVolumeFactor = 1;
|
||||
|
||||
release.UploadVolumeFactor = 1;
|
||||
|
||||
releases.Add(release);
|
||||
}
|
||||
|
@ -348,29 +330,26 @@ namespace Jackett.Common.Indexers
|
|||
/// </summary>
|
||||
/// <param name="term">Term to search</param>
|
||||
/// <param name="query">Torznab Query for categories mapping</param>
|
||||
/// <param name="url">Search url for provider</param>
|
||||
/// <param name="searchUrl">Search url for provider</param>
|
||||
/// <param name="page">Page number to request</param>
|
||||
/// <returns>URL to query for parsing and processing results</returns>
|
||||
private string BuildQuery(string term, TorznabQuery query, string url, int page = 0)
|
||||
private string BuildQuery(string term, TorznabQuery query, string searchUrl, int page = 0)
|
||||
{
|
||||
var parameters = new NameValueCollection();
|
||||
var categoriesList = MapTorznabCapsToTrackers(query);
|
||||
var searchterm = term;
|
||||
|
||||
// Building our tracker query
|
||||
parameters.Add("incldead", "1");
|
||||
parameters.Add("fullsearch", ConfigData.UseFullSearch.Value ? "1" : "0");
|
||||
parameters.Add("scenerelease", "0");
|
||||
var parameters = new NameValueCollection
|
||||
{
|
||||
{ "incldead", "1" },
|
||||
{ "fullsearch", ConfigData.UseFullSearch.Value ? "1" : "0" },
|
||||
{ "scenerelease", "0" }
|
||||
};
|
||||
|
||||
// If search term provided
|
||||
if (!string.IsNullOrWhiteSpace(query.ImdbID))
|
||||
{
|
||||
searchterm = "imdbsearch=" + query.ImdbID;
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(term))
|
||||
{
|
||||
searchterm = "search=" + WebUtilityHelpers.UrlEncode(term, Encoding.GetEncoding(28591));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Showing all torrents (just for output function)
|
||||
|
@ -378,17 +357,16 @@ namespace Jackett.Common.Indexers
|
|||
term = "all";
|
||||
}
|
||||
|
||||
var CatQryStr = "";
|
||||
foreach (var cat in categoriesList)
|
||||
CatQryStr += "&" + cat;
|
||||
|
||||
// Building our query
|
||||
url += "?" + searchterm + "&" + parameters.GetQueryString() + "&" + CatQryStr;
|
||||
searchUrl += "?" + searchterm + "&" + parameters.GetQueryString();
|
||||
|
||||
logger.Info("\nBuilded query for \"" + term + "\"... " + url);
|
||||
var categoriesList = MapTorznabCapsToTrackers(query);
|
||||
if (categoriesList.Any())
|
||||
searchUrl += "&" + string.Join("&", categoriesList);
|
||||
|
||||
// Return our search url
|
||||
return url;
|
||||
logger.Info("\nBuilded query for \"" + term + "\"... " + searchUrl);
|
||||
|
||||
return searchUrl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Add table
Reference in a new issue