diff --git a/src/Jackett/Indexers/SceneTime.cs b/src/Jackett/Indexers/SceneTime.cs index ec005fe24..2bead4472 100644 --- a/src/Jackett/Indexers/SceneTime.cs +++ b/src/Jackett/Indexers/SceneTime.cs @@ -7,14 +7,11 @@ using Newtonsoft.Json.Linq; using NLog; using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; -using System.Net; -using System.Net.Http; -using System.Text; using System.Threading.Tasks; -using System.Web; using Jackett.Models.IndexerConfig; +using System.Text.RegularExpressions; +using System.Collections.Specialized; namespace Jackett.Indexers { @@ -34,13 +31,15 @@ namespace Jackett.Indexers : base(name: "SceneTime", description: "Always on time", link: "https://www.scenetime.com/", - caps: TorznabUtil.CreateDefaultTorznabTVCaps(), + caps: new TorznabCapabilities(), manager: i, client: w, logger: l, p: ps, - configData: new ConfigurationDataBasicLogin()) + configData: new ConfigurationDataBasicLogin("For best results, change the 'Torrents per page' setting to the maximum in your profile on the SceneTime webpage.")) { + AddCategoryMapping(77, TorznabCatType.TVSD); + AddCategoryMapping(9, TorznabCatType.TVHD); } public async Task ApplyConfiguration(JToken configJson) @@ -62,23 +61,47 @@ namespace Jackett.Indexers return IndexerConfigurationStatus.RequiresTesting; } - private Dictionary GetSearchFormData(string searchString) - { - return new Dictionary { - { "c2", "1" }, { "c43", "1" }, { "c9", "1" }, { "c63", "1" }, { "c77", "1" }, { "c100", "1" }, { "c101", "1" }, - { "cata", "yes" }, { "sec", "jax" }, - { "search", searchString} - }; - } public async Task> PerformQuery(TorznabQuery query) { - var releases = new List(); - var results = await PostDataWithCookiesAndRetry(SearchUrl, GetSearchFormData(query.GetQueryString())); + NameValueCollection qParams = new NameValueCollection(); + qParams.Add("cata", "yes"); + qParams.Add("sec", "jax"); + + List catList = MapTorznabCapsToTrackers(query); + foreach (string cat in catList) + { + qParams.Add("c" + cat, "1"); + } + + if (!string.IsNullOrEmpty(query.SanitizedSearchTerm)) + { + qParams.Add("search", query.GetQueryString()); + } + + string torrentSearchUrl = $"{SearchUrl}?{qParams.GetQueryString()}"; + + var results = await RequestStringWithCookiesAndRetry(torrentSearchUrl); + List releases = ParseResponse(results.Content); + + return releases; + } + + public List ParseResponse(string htmlResponse) + { + List releases = new List(); try { - CQ dom = results.Content; + CQ dom = htmlResponse; + + List headerColumns = dom["table[class*='movehere']"].First().Find("tbody > tr > td[class='cat_Head']").Select(x => x.Cq().Text()).ToList(); + int categoryIndex = headerColumns.FindIndex(x => x.Equals("Type")); + int nameIndex = headerColumns.FindIndex(x => x.Equals("Name")); + int sizeIndex = headerColumns.FindIndex(x => x.Equals("Size")); + int seedersIndex = headerColumns.FindIndex(x => x.Equals("Seeders")); + int leechersIndex = headerColumns.FindIndex(x => x.Equals("Leechers")); + var rows = dom["tr.browse"]; foreach (var row in rows) { @@ -86,7 +109,12 @@ namespace Jackett.Indexers release.MinimumRatio = 1; release.MinimumSeedTime = 172800; - var descCol = row.ChildElements.ElementAt(1); + var categoryCol = row.ChildElements.ElementAt(categoryIndex); + string catLink = categoryCol.Cq().Find("a").Attr("href"); + string catId = new Regex(@"\?cat=(\d*)").Match(catLink).Groups[1].ToString().Trim(); + release.Category = MapTrackerCatToNewznab(catId); + + var descCol = row.ChildElements.ElementAt(nameIndex); var qDescCol = descCol.Cq(); var qLink = qDescCol.Find("a"); release.Title = qLink.Text(); @@ -98,19 +126,20 @@ namespace Jackett.Indexers release.PublishDate = DateTimeUtil.FromTimeAgo(descCol.ChildNodes.Last().InnerText); - var sizeStr = row.ChildElements.ElementAt(3).Cq().Text(); + var sizeStr = row.ChildElements.ElementAt(sizeIndex).Cq().Text(); release.Size = ReleaseInfo.GetBytes(sizeStr); - release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(4).Cq().Text().Trim()); - release.Peers = ParseUtil.CoerceInt(row.ChildElements.ElementAt(5).Cq().Text().Trim()) + release.Seeders; + release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(seedersIndex).Cq().Text().Trim()); + release.Peers = ParseUtil.CoerceInt(row.ChildElements.ElementAt(leechersIndex).Cq().Text().Trim()) + release.Seeders; releases.Add(release); } } catch (Exception ex) { - OnParseError(results.Content, ex); + OnParseError(htmlResponse, ex); } + return releases; } }