Fixed: (assorted) Use GetArgumentFromQueryString and other minor fixes

pull/1386/head
Bogdan 2 years ago
parent b6018a4cd7
commit d4f22f3596

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -93,12 +94,7 @@ namespace NzbDrone.Core.Indexers.Definitions
protected override bool CheckIfLoginNeeded(HttpResponse httpResponse) protected override bool CheckIfLoginNeeded(HttpResponse httpResponse)
{ {
if (!httpResponse.Content.Contains("logout.php")) return !httpResponse.Content.Contains("logout.php");
{
return true;
}
return false;
} }
private IndexerCapabilities SetCapabilities() private IndexerCapabilities SetCapabilities()
@ -155,26 +151,30 @@ namespace NzbDrone.Core.Indexers.Definitions
private IEnumerable<IndexerRequest> GetPagedRequests(string term, int[] categories, string imdb = null) private IEnumerable<IndexerRequest> GetPagedRequests(string term, int[] categories, string imdb = null)
{ {
var searchUrl = string.Format("{0}/index.php?page=torrents&", Settings.BaseUrl.TrimEnd('/'));
var queryCollection = new NameValueCollection var queryCollection = new NameValueCollection
{ {
{ "page", "torrents" },
{ "active", "0" }, { "active", "0" },
{ "category", string.Join(";", Capabilities.Categories.MapTorznabCapsToTrackers(categories)) }
}; };
if (imdb != null) var catList = Capabilities.Categories.MapTorznabCapsToTrackers(categories);
if (catList.Any())
{ {
queryCollection.Add("options", "2"); queryCollection.Set("category", string.Join(";", catList));
queryCollection.Add("search", imdb); }
if (imdb.IsNotNullOrWhiteSpace())
{
queryCollection.Set("options", "2");
queryCollection.Set("search", imdb);
} }
else else
{ {
queryCollection.Add("options", "0"); queryCollection.Set("options", "0");
queryCollection.Add("search", term.Replace(".", " ")); queryCollection.Set("search", term.Replace(".", " "));
} }
searchUrl += queryCollection.GetQueryString(); var searchUrl = $"{Settings.BaseUrl.TrimEnd('/')}/index.php?{queryCollection.GetQueryString()}";
var request = new IndexerRequest(searchUrl, HttpAccept.Html); var request = new IndexerRequest(searchUrl, HttpAccept.Html);
@ -267,15 +267,10 @@ namespace NzbDrone.Core.Indexers.Definitions
release.DownloadUrl = _settings.BaseUrl + downloadUrl; release.DownloadUrl = _settings.BaseUrl + downloadUrl;
// Use the torrent filename as release title // Use the torrent filename as release title
var torrentTitle = ParseUtil.GetArgumentFromQueryString(downloadUrl, "f")? var torrentTitle = ParseUtil.GetArgumentFromQueryString(downloadUrl, "f")?.Replace(".torrent", "").Trim();
.Replace("&amp;", "&")
.Replace("&#039;", "'")
.Replace(".torrent", "")
.Trim();
if (torrentTitle.IsNotNullOrWhiteSpace()) if (torrentTitle.IsNotNullOrWhiteSpace())
{ {
release.Title = torrentTitle; release.Title = WebUtility.HtmlDecode(torrentTitle);
} }
var qGenres = row.QuerySelector("td:nth-child(2) span[style=\"color: #000000 \"]"); var qGenres = row.QuerySelector("td:nth-child(2) span[style=\"color: #000000 \"]");
@ -318,8 +313,9 @@ namespace NzbDrone.Core.Indexers.Definitions
} }
release.UploadVolumeFactor = 1; release.UploadVolumeFactor = 1;
var qCat = row.QuerySelector("a[href^=\"index.php?page=torrents&category=\"]");
var cat = qCat.GetAttribute("href").Split('=')[2]; var categoryLink = row.QuerySelector("a[href^=\"index.php?page=torrents&category=\"]").GetAttribute("href");
var cat = ParseUtil.GetArgumentFromQueryString(categoryLink, "category");
release.Categories = _categories.MapTrackerCatToNewznab(cat); release.Categories = _categories.MapTrackerCatToNewznab(cat);
torrentInfos.Add(release); torrentInfos.Add(release);

@ -222,7 +222,7 @@ namespace NzbDrone.Core.Indexers.Definitions
private readonly UserPassTorrentBaseSettings _settings; private readonly UserPassTorrentBaseSettings _settings;
private readonly IndexerCapabilitiesCategories _categories; private readonly IndexerCapabilitiesCategories _categories;
private readonly Regex _posterRegex = new Regex(@"src=\\'./([^']+)\\'", RegexOptions.IgnoreCase); private readonly Regex _posterRegex = new (@"src=\\'./([^']+)\\'", RegexOptions.IgnoreCase);
private readonly HashSet<string> _freeleechRanks = new (StringComparer.OrdinalIgnoreCase) private readonly HashSet<string> _freeleechRanks = new (StringComparer.OrdinalIgnoreCase)
{ {
"VIP", "VIP",
@ -263,15 +263,14 @@ namespace NzbDrone.Core.Indexers.Definitions
: null; : null;
var link = new Uri(_settings.BaseUrl + row.Children[4].FirstElementChild.GetAttribute("href")); var link = new Uri(_settings.BaseUrl + row.Children[4].FirstElementChild.GetAttribute("href"));
var description = row.Children[2].QuerySelector("span").TextContent; var description = row.Children[2].QuerySelector("span")?.TextContent.Trim();
var size = ParseUtil.GetBytes(row.Children[7].TextContent); var size = ParseUtil.GetBytes(row.Children[7].TextContent);
var dateTag = row.Children[6].FirstElementChild; var dateAdded = string.Join(" ", row.Children[6].FirstElementChild.Attributes.Select(a => a.Name).Take(4));
var dateString = string.Join(" ", dateTag.Attributes.Select(attr => attr.Name)); var publishDate = DateTime.ParseExact(dateAdded, "dd MMM yyyy HH:mm:ss", CultureInfo.InvariantCulture);
var publishDate = DateTime.ParseExact(dateString, "dd MMM yyyy HH:mm:ss zz00", CultureInfo.InvariantCulture).ToLocalTime();
var catStr = row.FirstElementChild.FirstElementChild.GetAttribute("href").Split('=')[1]; var categoryLink = row.FirstElementChild.FirstElementChild.GetAttribute("href");
var cat = _categories.MapTrackerCatToNewznab(catStr); var cat = ParseUtil.GetArgumentFromQueryString(categoryLink, "category");
// Sometimes the uploader column is missing, so seeders, leechers, and grabs may be at a different index. // Sometimes the uploader column is missing, so seeders, leechers, and grabs may be at a different index.
// There's room for improvement, but this works for now. // There's room for improvement, but this works for now.
@ -340,12 +339,13 @@ namespace NzbDrone.Core.Indexers.Definitions
var release = new TorrentInfo var release = new TorrentInfo
{ {
Title = title, Title = title,
Description = description,
Guid = details.AbsoluteUri, Guid = details.AbsoluteUri,
DownloadUrl = link.AbsoluteUri, DownloadUrl = link.AbsoluteUri,
InfoUrl = details.AbsoluteUri, InfoUrl = details.AbsoluteUri,
PosterUrl = poster, PosterUrl = poster,
PublishDate = publishDate, PublishDate = publishDate,
Categories = cat, Categories = _categories.MapTrackerCatToNewznab(cat),
ImdbId = imdb ?? 0, ImdbId = imdb ?? 0,
Size = size, Size = size,
Grabs = grabs, Grabs = grabs,

@ -1,9 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using AngleSharp.Html.Parser; using AngleSharp.Html.Parser;
using NLog; using NLog;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
@ -24,7 +24,7 @@ namespace NzbDrone.Core.Indexers.Definitions
public override string[] IndexerUrls => new[] { "https://www.scenetime.com/" }; public override string[] IndexerUrls => new[] { "https://www.scenetime.com/" };
public override string Description => "Always on time"; public override string Description => "Always on time";
public override string Language => "en-US"; public override string Language => "en-US";
public override Encoding Encoding => Encoding.GetEncoding("iso-8859-1"); public override Encoding Encoding => Encoding.UTF8;
public override DownloadProtocol Protocol => DownloadProtocol.Torrent; public override DownloadProtocol Protocol => DownloadProtocol.Torrent;
public override IndexerPrivacy Privacy => IndexerPrivacy.Private; public override IndexerPrivacy Privacy => IndexerPrivacy.Private;
public override IndexerCapabilities Capabilities => SetCapabilities(); public override IndexerCapabilities Capabilities => SetCapabilities();
@ -121,20 +121,20 @@ namespace NzbDrone.Core.Indexers.Definitions
var catList = Capabilities.Categories.MapTorznabCapsToTrackers(categories); var catList = Capabilities.Categories.MapTorznabCapsToTrackers(categories);
foreach (var cat in catList) foreach (var cat in catList)
{ {
qc.Add("c" + cat, "1"); qc.Set($"c{cat}", "1");
} }
if (term.IsNotNullOrWhiteSpace()) if (term.IsNotNullOrWhiteSpace())
{ {
qc.Add("search", term); qc.Set("search", term);
} }
if (Settings.FreeLeechOnly) if (Settings.FreeLeechOnly)
{ {
qc.Add("freeleech", "on"); qc.Set("freeleech", "on");
} }
var searchUrl = string.Format("{0}/browse.php?{1}", Settings.BaseUrl.TrimEnd('/'), qc.GetQueryString()); var searchUrl = $"{Settings.BaseUrl.TrimEnd('/')}/browse.php?{qc.GetQueryString()}";
var request = new IndexerRequest(searchUrl, HttpAccept.Html); var request = new IndexerRequest(searchUrl, HttpAccept.Html);
@ -203,7 +203,7 @@ namespace NzbDrone.Core.Indexers.Definitions
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse) public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
{ {
var torrentInfos = new List<ReleaseInfo>(); var releaseInfos = new List<ReleaseInfo>();
var parser = new HtmlParser(); var parser = new HtmlParser();
var dom = parser.ParseDocument(indexerResponse.Content); var dom = parser.ParseDocument(indexerResponse.Content);
@ -211,11 +211,11 @@ namespace NzbDrone.Core.Indexers.Definitions
var table = dom.QuerySelector("table.movehere"); var table = dom.QuerySelector("table.movehere");
if (table == null) if (table == null)
{ {
return torrentInfos; // no results return releaseInfos; // no results
} }
var headerColumns = table.QuerySelectorAll("tbody > tr > td.cat_Head") var headerColumns = table.QuerySelectorAll("tbody > tr > td.cat_Head")
.Select(x => x.TextContent).ToList(); .Select(x => x.TextContent).ToList();
var categoryIndex = headerColumns.FindIndex(x => x.Equals("Type")); var categoryIndex = headerColumns.FindIndex(x => x.Equals("Type"));
var nameIndex = headerColumns.FindIndex(x => x.Equals("Name")); var nameIndex = headerColumns.FindIndex(x => x.Equals("Name"));
var sizeIndex = headerColumns.FindIndex(x => x.Equals("Size")); var sizeIndex = headerColumns.FindIndex(x => x.Equals("Size"));
@ -226,30 +226,29 @@ namespace NzbDrone.Core.Indexers.Definitions
foreach (var row in rows) foreach (var row in rows)
{ {
// TODO convert to initializer
var qDescCol = row.Children[nameIndex]; var qDescCol = row.Children[nameIndex];
var qLink = qDescCol.QuerySelector("a"); var qLink = qDescCol.QuerySelector("a");
var details = _settings.BaseUrl + "/" + qLink.GetAttribute("href"); var infoUrl = _settings.BaseUrl + qLink.GetAttribute("href").TrimStart('/');
var torrentId = qLink.GetAttribute("href").Split('=')[1]; var torrentId = ParseUtil.GetArgumentFromQueryString(infoUrl, "id");
var sizeStr = row.Children[sizeIndex].TextContent;
var seeders = ParseUtil.CoerceInt(row.Children[seedersIndex].TextContent.Trim()); var seeders = ParseUtil.CoerceInt(row.Children[seedersIndex].TextContent.Trim());
var catId = "82"; // default var categoryLink = row.Children[categoryIndex].QuerySelector("a").GetAttribute("href");
var qCatLink = row.Children[categoryIndex].QuerySelector("a"); var cat = categoryLink != null ? ParseUtil.GetArgumentFromQueryString(categoryLink, "cat") : "82"; // default
if (qCatLink != null)
{ var dateAdded = qDescCol.QuerySelector("span[class=\"elapsedDate\"]").GetAttribute("title").Trim();
catId = new Regex(@"\?cat=(\d*)").Match(qCatLink.GetAttribute("href")).Groups[1].ToString().Trim(); var publishDate = DateTime.TryParseExact(dateAdded, "dddd, MMMM d, yyyy \\a\\t h:mmtt", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var date)
} ? date
: DateTimeUtil.FromTimeAgo(qDescCol.QuerySelector("span[class=\"elapsedDate\"]").TextContent.Trim());
var release = new TorrentInfo var release = new TorrentInfo
{ {
Guid = infoUrl,
InfoUrl = infoUrl,
DownloadUrl = $"{_settings.BaseUrl}download.php/{torrentId}/download.torrent",
Title = qLink.TextContent, Title = qLink.TextContent,
InfoUrl = details, Categories = _categories.MapTrackerCatToNewznab(cat),
Categories = _categories.MapTrackerCatToNewznab(catId), PublishDate = publishDate,
DownloadUrl = string.Format("{0}/download.php/{1}/download.torrent", _settings.BaseUrl, torrentId), Size = ParseUtil.GetBytes(row.Children[sizeIndex].TextContent),
Guid = details,
PublishDate = DateTimeUtil.FromTimeAgo(qDescCol.ChildNodes.Last().TextContent),
Size = ParseUtil.GetBytes(sizeStr),
Seeders = seeders, Seeders = seeders,
Peers = ParseUtil.CoerceInt(row.Children[leechersIndex].TextContent.Trim()) + seeders, Peers = ParseUtil.CoerceInt(row.Children[leechersIndex].TextContent.Trim()) + seeders,
DownloadVolumeFactor = row.QuerySelector("font > b:contains(Freeleech)") != null ? 0 : 1, DownloadVolumeFactor = row.QuerySelector("font > b:contains(Freeleech)") != null ? 0 : 1,
@ -258,15 +257,13 @@ namespace NzbDrone.Core.Indexers.Definitions
MinimumSeedTime = 259200 // 72 hours MinimumSeedTime = 259200 // 72 hours
}; };
release.Categories = _categories.MapTrackerCatToNewznab(catId);
//TODO Do something with this filtering //TODO Do something with this filtering
//if (!query.MatchQueryStringAND(release.Title)) //if (!query.MatchQueryStringAND(release.Title))
// continue; // continue;
torrentInfos.Add(release); releaseInfos.Add(release);
} }
return torrentInfos.ToArray(); return releaseInfos.ToArray();
} }
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; } public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }

Loading…
Cancel
Save