1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-01-04 06:22:45 +00:00

speedcd: fix category search and add alternative domain (#7946)

This commit is contained in:
Diego Heras 2020-03-31 22:26:07 +02:00 committed by GitHub
parent 2672ade767
commit 6727b28cf1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 48 deletions

View file

@ -1,10 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AngleSharp.Dom;
using AngleSharp.Html.Parser; using AngleSharp.Html.Parser;
using Jackett.Common.Models; using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig; using Jackett.Common.Models.IndexerConfig;
@ -21,14 +19,15 @@ namespace Jackett.Common.Indexers
private string LoginUrl => SiteLink + "take_login.php"; private string LoginUrl => SiteLink + "take_login.php";
private string SearchUrl => SiteLink + "browse.php"; private string SearchUrl => SiteLink + "browse.php";
private new ConfigurationDataBasicLogin configData public override string[] AlternativeSiteLinks { get; protected set; } = {
{ "https://speed.cd/",
get => (ConfigurationDataBasicLogin)base.configData; "https://speed.click/"
set => base.configData = value; };
}
private new ConfigurationDataBasicLogin configData => (ConfigurationDataBasicLogin)base.configData;
public SpeedCD(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps) public SpeedCD(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
: base(name: "Speed.cd", : base("Speed.cd",
description: "Your home now!", description: "Your home now!",
link: "https://speed.cd/", link: "https://speed.cd/",
caps: new TorznabCapabilities(), caps: new TorznabCapabilities(),
@ -36,14 +35,17 @@ namespace Jackett.Common.Indexers
client: wc, client: wc,
logger: l, logger: l,
p: ps, p: ps,
configData: new ConfigurationDataBasicLogin(@"Speed.Cd have increased their security. If you are having problems please check the security tab in your Speed.Cd profile. configData: new ConfigurationDataBasicLogin(
eg. Geo Locking, your seedbox may be in a different country to the one where you login via your web browser")) @"Speed.Cd have increased their security. If you are having problems please check the security tab
in your Speed.Cd profile. Eg. Geo Locking, your seedbox may be in a different country to the one where you login via your
web browser.<br><br>For best results, change the 'Torrents per page' setting to 100 in 'Profile Settings > Torrents'."))
{ {
Encoding = Encoding.UTF8; Encoding = Encoding.UTF8;
Language = "en-us"; Language = "en-us";
Type = "private"; Type = "private";
TorznabCaps.SupportsImdbMovieSearch = true; TorznabCaps.SupportsImdbMovieSearch = true;
TorznabCaps.SupportsImdbTVSearch = true;
AddCategoryMapping(1, TorznabCatType.MoviesOther, "Movies/XviD"); AddCategoryMapping(1, TorznabCatType.MoviesOther, "Movies/XviD");
AddCategoryMapping(42, TorznabCatType.Movies, "Movies/Packs"); AddCategoryMapping(42, TorznabCatType.Movies, "Movies/Packs");
@ -81,9 +83,7 @@ namespace Jackett.Common.Indexers
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson) public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
{ {
LoadValuesFromJson(configJson); LoadValuesFromJson(configJson);
await DoLogin(); await DoLogin();
return IndexerConfigurationStatus.RequiresTesting; return IndexerConfigurationStatus.RequiresTesting;
} }
@ -96,12 +96,12 @@ namespace Jackett.Common.Indexers
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink); var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink);
await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("/browse.php"), () => await ConfigureIfOK(result.Cookies, result.Content?.Contains("/browse.php") == true, () =>
{ {
var parser = new HtmlParser(); var parser = new HtmlParser();
var dom = parser.ParseDocument(result.Content); var dom = parser.ParseDocument(result.Content);
var errorMessage = dom.Text(); var errorMessage = dom.QuerySelector("h5")?.TextContent;
if (errorMessage.Contains("Wrong Captcha!")) if (result.Content.Contains("Wrong Captcha!"))
errorMessage = "Captcha requiered due to a failed login attempt. Login via a browser to whitelist your IP and then reconfigure jackett."; errorMessage = "Captcha requiered due to a failed login attempt. Login via a browser to whitelist your IP and then reconfigure jackett.";
throw new ExceptionWithConfigData(errorMessage, configData); throw new ExceptionWithConfigData(errorMessage, configData);
}); });
@ -111,79 +111,69 @@ namespace Jackett.Common.Indexers
{ {
var releases = new List<ReleaseInfo>(); var releases = new List<ReleaseInfo>();
var qParams = new NameValueCollection(); var qc = new List<KeyValuePair<string, string>>(); // NameValueCollection don't support c[]=30&c[]=52
if (query.IsImdbQuery)
if (!string.IsNullOrWhiteSpace(query.ImdbID))
{ {
qParams.Add("search", query.ImdbID); qc.Add("search", query.ImdbID);
qParams.Add("d", "on"); qc.Add("d", "on");
}
else if (!string.IsNullOrEmpty(query.GetQueryString()))
{
qParams.Add("search", query.GetQueryString());
} }
else
qc.Add("search", query.GetQueryString());
var catList = MapTorznabCapsToTrackers(query); var catList = MapTorznabCapsToTrackers(query);
foreach (var cat in catList) foreach (var cat in catList)
{ qc.Add("c[]", cat);
qParams.Add("c" + cat, "1");
}
var urlSearch = SearchUrl; var searchUrl = SearchUrl + "?" + qc.GetQueryString();
if (qParams.Count > 0) var response = await RequestStringWithCookiesAndRetry(searchUrl);
if (!response.Content.Contains("/logout.php")) // re-login
{ {
urlSearch += $"?{qParams.GetQueryString()}";
}
var response = await RequestStringWithCookiesAndRetry(urlSearch);
if (!response.Content.Contains("/logout.php"))
{
//Cookie appears to expire after a period of time or logging in to the site via browser
await DoLogin(); await DoLogin();
response = await RequestStringWithCookiesAndRetry(urlSearch); response = await RequestStringWithCookiesAndRetry(searchUrl);
} }
try try
{ {
var parser = new HtmlParser(); var parser = new HtmlParser();
var dom = parser.ParseDocument(response.Content); var dom = parser.ParseDocument(response.Content);
var rows = dom.QuerySelectorAll("div[id='torrentTable'] > div[class^='box torrentBox'] > div[class='boxContent'] > table > tbody > tr"); var rows = dom.QuerySelectorAll("div.boxContent > table > tbody > tr");
foreach (var row in rows) foreach (var row in rows)
{ {
var cells = row.QuerySelectorAll("td"); var cells = row.QuerySelectorAll("td");
var title = row.QuerySelector("td[class='lft'] > div > a").TextContent.Trim(); var title = row.QuerySelector("td[class='lft'] > div > a").TextContent.Trim();
var link = new Uri(SiteLink + row.QuerySelector("img[title='Download']").ParentElement.GetAttribute("href").Trim()); var link = new Uri(SiteLink + row.QuerySelector("img[title='Download']").ParentElement.GetAttribute("href").TrimStart('/'));
var comments = new Uri(SiteLink + row.QuerySelector("td[class='lft'] > div > a").GetAttribute("href").Trim().Remove(0, 1)); var comments = new Uri(SiteLink + row.QuerySelector("td[class='lft'] > div > a").GetAttribute("href").TrimStart('/'));
var size = ReleaseInfo.GetBytes(cells[4].TextContent); var size = ReleaseInfo.GetBytes(cells[4].TextContent);
var grabs = ParseUtil.CoerceInt(cells[5].TextContent); var grabs = ParseUtil.CoerceInt(cells[5].TextContent);
var seeders = ParseUtil.CoerceInt(cells[6].TextContent); var seeders = ParseUtil.CoerceInt(cells[6].TextContent);
var leechers = ParseUtil.CoerceInt(cells[7].TextContent); var leechers = ParseUtil.CoerceInt(cells[7].TextContent);
var pubDateStr = row.QuerySelector("span[class^='elapsedDate']").GetAttribute("title").Trim().Replace(" at", ""); var pubDateStr = row.QuerySelector("span[class^='elapsedDate']").GetAttribute("title").Replace(" at", "");
var publishDate = DateTime.ParseExact(pubDateStr, "dddd, MMMM d, yyyy h:mmtt", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime(); var publishDate = DateTime.ParseExact(pubDateStr, "dddd, MMMM d, yyyy h:mmtt", CultureInfo.InvariantCulture);
var cat = row.QuerySelector("img[class^='Tcat']").ParentElement.GetAttribute("href").Trim().Remove(0, 5); var cat = row.QuerySelector("a[href^='?c[]=']").GetAttribute("href").Replace("?c[]=", "");
long.TryParse(cat, out var category);
var downloadVolumeFactor = row.QuerySelector("span:contains(\"[Freeleech]\")") != null ? 0 : 1; var downloadVolumeFactor = row.QuerySelector("span:contains(\"[Freeleech]\")") != null ? 0 : 1;
var release = new ReleaseInfo var release = new ReleaseInfo
{ {
Title = title, Title = title,
Guid = link,
Link = link, Link = link,
Guid = link,
Comments = comments,
PublishDate = publishDate, PublishDate = publishDate,
Category = MapTrackerCatToNewznab(cat),
Size = size, Size = size,
Grabs = grabs, Grabs = grabs,
Seeders = seeders, Seeders = seeders,
Peers = seeders + leechers, Peers = seeders + leechers,
MinimumRatio = 1, MinimumRatio = 1,
MinimumSeedTime = 172800, // 48 hours MinimumSeedTime = 172800, // 48 hours
Category = MapTrackerCatToNewznab(category.ToString()),
Comments = comments,
DownloadVolumeFactor = downloadVolumeFactor, DownloadVolumeFactor = downloadVolumeFactor,
UploadVolumeFactor = 1 UploadVolumeFactor = 1
}; };
releases.Add(release); releases.Add(release);
} }
} }

View file

@ -5,8 +5,9 @@ namespace Jackett.Common.Models.IndexerConfig
{ {
public StringItem Cookie { get; private set; } public StringItem Cookie { get; private set; }
public DisplayItem CookieInstructions { get; private set; } public DisplayItem CookieInstructions { get; private set; }
public DisplayItem Instructions { get; private set; }
public ConfigurationDataCookie() public ConfigurationDataCookie(string instructionMessageOptional = null)
{ {
Cookie = new StringItem { Name = "Cookie" }; Cookie = new StringItem { Name = "Cookie" };
CookieInstructions = new DisplayItem( CookieInstructions = new DisplayItem(
@ -15,6 +16,7 @@ namespace Jackett.Common.Models.IndexerConfig
{ {
Name = "Cookie Instructions" Name = "Cookie Instructions"
}; };
Instructions = new DisplayItem(instructionMessageOptional) { Name = "" };
} }
} }