From c20e4d0dfa810abdeb2c4d15f5a69d2fd90ceb0c Mon Sep 17 00:00:00 2001 From: flightlevel Date: Fri, 29 Jan 2016 23:50:23 +1100 Subject: [PATCH] Revert "Freshon: Changed parser to AngleSharp" --- src/Jackett/Indexers/Freshon.cs | 88 +++++++++++++++++---------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/src/Jackett/Indexers/Freshon.cs b/src/Jackett/Indexers/Freshon.cs index e786c1a88..ced6c9cb5 100644 --- a/src/Jackett/Indexers/Freshon.cs +++ b/src/Jackett/Indexers/Freshon.cs @@ -1,4 +1,6 @@ -using Jackett.Models; +using CsQuery; +using Jackett.Indexers; +using Jackett.Models; using Jackett.Services; using Jackett.Utils; using Jackett.Utils.Clients; @@ -8,10 +10,14 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; using System.Threading.Tasks; using System.Web; +using System.Web.UI.WebControls; using Jackett.Models.IndexerConfig; -using AngleSharp; namespace Jackett.Indexers { @@ -36,7 +42,7 @@ namespace Jackett.Indexers client: c, logger: l, p: ps, - configData: new ConfigurationDataBasicLogin("For best results, change the 'Torrents per page' setting to 100 in your profile on the FreshOn webpage.")) + configData: new ConfigurationDataBasicLogin()) { } @@ -54,32 +60,15 @@ namespace Jackett.Indexers await ConfigureIfOK(response.Cookies, response.Content != null && response.Content.Contains("/logout.php"), () => { - var parser = new AngleSharp.Parser.Html.HtmlParser(); - var document = parser.Parse(response.Content); - var messageEl = document.QuerySelector(".error_text"); - var errorMessage = messageEl.TextContent.Trim(); + CQ dom = response.Content; + var messageEl = dom[".error_text"]; + var errorMessage = messageEl.Text().Trim(); throw new ExceptionWithConfigData(errorMessage, configData); }); return IndexerConfigurationStatus.RequiresTesting; } public async Task> PerformQuery(TorznabQuery query) - { - string Url; - if (string.IsNullOrEmpty(query.GetQueryString())) - Url = SearchUrl; - else - { - Url = $"{SearchUrl}?search={HttpUtility.UrlEncode(query.GetQueryString())}&cat=0"; - } - - var response = await RequestStringWithCookiesAndRetry(Url); - List releases = ParseResponse(response.Content); - - return releases; - } - - private List ParseResponse(string htmlResponse) { TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 3, 5, DayOfWeek.Sunday); TimeZoneInfo.TransitionTime endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 0, 0), 10, 5, DayOfWeek.Sunday); @@ -88,40 +77,53 @@ namespace Jackett.Indexers TimeZoneInfo.AdjustmentRule[] adjustments = { adjustment }; TimeZoneInfo romaniaTz = TimeZoneInfo.CreateCustomTimeZone("Romania Time", new TimeSpan(2, 0, 0), "(GMT+02:00) Romania Time", "Romania Time", "Romania Daylight Time", adjustments); - List releases = new List(); + var releases = new List(); + string episodeSearchUrl; + if (string.IsNullOrEmpty(query.GetQueryString())) + episodeSearchUrl = SearchUrl; + else + { + episodeSearchUrl = $"{SearchUrl}?search={HttpUtility.UrlEncode(query.GetQueryString())}&cat=0"; + } + + var results = await RequestStringWithCookiesAndRetry(episodeSearchUrl); try { - var parser = new AngleSharp.Parser.Html.HtmlParser(); - var document = parser.Parse(htmlResponse); - var rows = document.QuerySelectorAll("#highlight > tbody > tr:not(:First-child)"); + CQ dom = results.Content; - foreach (var row in rows) + var rows = dom["#highlight > tbody > tr"]; + + foreach (var row in rows.Skip(1)) { var release = new ReleaseInfo(); - var linkNameElement = row.QuerySelector("a.torrent_name_link"); + var qRow = row.Cq(); + var qLink = qRow.Find("a.torrent_name_link").First(); - release.Title = linkNameElement.GetAttribute("title"); - release.Description = release.Title; - release.Guid = new Uri(SiteLink + linkNameElement.GetAttribute("href")); - release.Comments = release.Guid; - release.Link = new Uri(SiteLink + row.QuerySelector("td.table_links > a").GetAttribute("href")); - release.Category = TvCategoryParser.ParseTvShowQuality(release.Title); - release.Seeders = ParseUtil.CoerceInt(row.QuerySelector("td.table_seeders").TextContent.Trim()); - release.Peers = ParseUtil.CoerceInt(row.QuerySelector("td.table_leechers").TextContent.Trim()) + release.Seeders; - release.Size = ReleaseInfo.GetBytes(row.QuerySelector("td.table_size").TextContent); release.MinimumRatio = 1; release.MinimumSeedTime = 172800; + release.Title = qLink.Attr("title"); + release.Description = release.Title; + release.Guid = new Uri(SiteLink + qLink.Attr("href")); + release.Comments = release.Guid; + release.Link = new Uri(SiteLink + qRow.Find("td.table_links > a").First().Attr("href")); + release.Category = TvCategoryParser.ParseTvShowQuality(release.Title); + + release.Seeders = ParseUtil.CoerceInt(qRow.Find("td.table_seeders").Text().Trim()); + release.Peers = ParseUtil.CoerceInt(qRow.Find("td.table_leechers").Text().Trim()) + release.Seeders; + + var sizeStr = qRow.Find("td.table_size")[0].Cq().Text(); + release.Size = ReleaseInfo.GetBytes(sizeStr); DateTime pubDateRomania; - var dateString = row.QuerySelector("td.table_added").TextContent.Trim(); + var dateString = qRow.Find("td.table_added").Text().Trim(); if (dateString.StartsWith("Today ")) - { pubDateRomania = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateString.Split(' ')[1]); } + { pubDateRomania = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateString.Split(' ')[1]); } else if (dateString.StartsWith("Yesterday ")) - { pubDateRomania = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateString.Split(' ')[1]) - TimeSpan.FromDays(1); } + { pubDateRomania = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateString.Split(' ')[1]) - TimeSpan.FromDays(1); } else - { pubDateRomania = DateTime.SpecifyKind(DateTime.ParseExact(dateString, "d-MMM-yyyy HH:mm:ss", CultureInfo.InvariantCulture), DateTimeKind.Unspecified); } + { pubDateRomania = DateTime.SpecifyKind(DateTime.ParseExact(dateString, "d-MMM-yyyy HH:mm:ss", CultureInfo.InvariantCulture), DateTimeKind.Unspecified); } DateTime pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(pubDateRomania, romaniaTz); release.PublishDate = pubDateUtc.ToLocalTime(); @@ -131,7 +133,7 @@ namespace Jackett.Indexers } catch (Exception ex) { - OnParseError(htmlResponse, ex); + OnParseError(results.Content, ex); } return releases;