Revert "Update TorrentHeaven with user provided html. Resolves #7586"

This reverts commit 0b45557292.
This commit is contained in:
cadatoiva 2020-03-10 12:05:57 -05:00
parent 0b45557292
commit 74e3dec4ed
1 changed files with 96 additions and 76 deletions

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AngleSharp.Dom;
using AngleSharp.Html.Parser;
using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig;
@ -19,15 +20,12 @@ namespace Jackett.Common.Indexers
{
public class TorrentHeaven : BaseWebIndexer
{
public override string[] LegacySiteLinks { get; protected set; } =
{
"https://torrentheaven.myfqdn.info/"
public override string[] LegacySiteLinks { get; protected set; } = new string[] {
"https://torrentheaven.myfqdn.info/",
};
private string IndexUrl => SiteLink + "index.php";
private string LoginCompleteUrl =>
SiteLink + "index.php?strWebValue=account&strWebAction=login_complete&ancestry=verify";
private string LoginCompleteUrl => SiteLink + "index.php?strWebValue=account&strWebAction=login_complete&ancestry=verify";
private new ConfigurationDataCaptchaLogin configData
{
@ -35,23 +33,23 @@ namespace Jackett.Common.Indexers
set => base.configData = value;
}
public TorrentHeaven(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps) :
base(
name: "TorrentHeaven",
description: "A German general tracker.",
link: "https://newheaven.nl/",
caps: TorznabUtil.CreateDefaultTorznabTVCaps(),
configService: configService,
client: wc,
logger: l,
p: ps,
configData: new ConfigurationDataCaptchaLogin())
public TorrentHeaven(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
: base(name: "TorrentHeaven",
description: "A German general tracker.",
link: "https://newheaven.nl/",
caps: TorznabUtil.CreateDefaultTorznabTVCaps(),
configService: configService,
client: wc,
logger: l,
p: ps,
configData: new ConfigurationDataCaptchaLogin())
{
Encoding = Encoding.GetEncoding("iso-8859-1");
Language = "de-de";
Type = "private";
// incomplete CA chain
wc.AddTrustedCertificate(new Uri(SiteLink).Host, "cbf23ac75b07255ad7548a87567a839d23f31576");
wc.AddTrustedCertificate(new Uri(SiteLink).Host, "cbf23ac75b07255ad7548a87567a839d23f31576"); // incomplete CA chain
AddCategoryMapping(1, TorznabCatType.PCGames, "GAMES/PC");
AddCategoryMapping(3, TorznabCatType.Console, "GAMES/Sonstige");
AddCategoryMapping(59, TorznabCatType.ConsolePS4, "GAMES/PlayStation");
@ -60,6 +58,7 @@ namespace Jackett.Common.Indexers
AddCategoryMapping(67, TorznabCatType.ConsoleXbox360, "GAMES/XBOX 360");
AddCategoryMapping(68, TorznabCatType.PCPhoneOther, "GAMES/PDA / Handy");
AddCategoryMapping(72, TorznabCatType.ConsoleNDS, "GAMES/NDS");
AddCategoryMapping(7, TorznabCatType.MoviesDVD, "MOVIES/DVD");
AddCategoryMapping(8, TorznabCatType.MoviesSD, "MOVIES/SD");
AddCategoryMapping(37, TorznabCatType.MoviesDVD, "MOVIES/DVD Spezial");
@ -70,12 +69,14 @@ namespace Jackett.Common.Indexers
AddCategoryMapping(104, TorznabCatType.MoviesBluRay, "MOVIES/Bluray");
AddCategoryMapping(106, TorznabCatType.Movies3D, "MOVIES/3D");
AddCategoryMapping(109, TorznabCatType.MoviesUHD, "MOVIES/4K");
AddCategoryMapping(14, TorznabCatType.Audio, "AUDIO/Musik");
AddCategoryMapping(15, TorznabCatType.AudioAudiobook, "AUDIO/Hörbücher");
AddCategoryMapping(16, TorznabCatType.AudioAudiobook, "AUDIO/Hörspiele");
AddCategoryMapping(36, TorznabCatType.AudioLossless, "AUDIO/Flac");
AddCategoryMapping(42, TorznabCatType.AudioOther, "AUDIO/Soundtracks");
AddCategoryMapping(58, TorznabCatType.AudioVideo, "AUDIO/Musikvideos");
AddCategoryMapping(18, TorznabCatType.TVSD, "TV/Serien SD");
AddCategoryMapping(19, TorznabCatType.TVHD, "TV/Serien HD 720p");
AddCategoryMapping(20, TorznabCatType.TVHD, "TV/Serien HD 1080p");
@ -85,10 +86,12 @@ namespace Jackett.Common.Indexers
AddCategoryMapping(53, TorznabCatType.TV, "TV/Serien Complete Packs");
AddCategoryMapping(54, TorznabCatType.TVSport, "TV/Sport");
AddCategoryMapping(66, TorznabCatType.TVFOREIGN, "TV/International");
AddCategoryMapping(22, TorznabCatType.Books, "MISC/EBooks");
AddCategoryMapping(24, TorznabCatType.Other, "MISC/Sonstiges");
AddCategoryMapping(25, TorznabCatType.Other, "MISC/Tonspuren");
AddCategoryMapping(108, TorznabCatType.TVAnime, "MISC/Anime");
AddCategoryMapping(28, TorznabCatType.PC, "APPLICATIONS/PC");
AddCategoryMapping(29, TorznabCatType.PCPhoneOther, "APPLICATIONS/Mobile");
AddCategoryMapping(30, TorznabCatType.PC, "APPLICATIONS/Sonstige");
@ -109,8 +112,9 @@ namespace Jackett.Common.Indexers
configData.CaptchaImage.Value = captchaImage.Content;
}
else
configData.CaptchaImage.Value = Array.Empty<byte>();
{
configData.CaptchaImage.Value = new byte[0];
}
configData.CaptchaCookie.Value = loginPage.Cookies;
return configData;
}
@ -118,20 +122,24 @@ namespace Jackett.Common.Indexers
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
{
LoadValuesFromJson(configJson);
var pairs = new Dictionary<string, string>
{
{"strWebAction", "login"},
{"strWebValue", "account"},
{"jsenabled", "1"},
{"screenwidth", "2560"},
{"username", configData.Username.Value},
{"password", configData.Password.Value}
{ "strWebAction", "login" },
{ "strWebValue", "account" },
{ "jsenabled", "1" },
{ "screenwidth", "2560" },
{ "username", configData.Username.Value },
{ "password", configData.Password.Value }
};
if (!string.IsNullOrWhiteSpace(configData.CaptchaText.Value))
{
pairs.Add("proofcode", configData.CaptchaText.Value);
var result = await RequestLoginAndFollowRedirect(IndexUrl, pairs, configData.CaptchaCookie.Value, true, referer: IndexUrl, accumulateCookies: true);
if (result.Content == null || (!result.Content.Contains("login_complete") &&
!result.Content.Contains("index.php?strWebValue=account&strWebAction=logout")))
}
var result = await RequestLoginAndFollowRedirect(IndexUrl, pairs, configData.CaptchaCookie.Value, true, null, IndexUrl, true);
if (result.Content == null || (!result.Content.Contains("login_complete") && !result.Content.Contains("index.php?strWebValue=account&strWebAction=logout")))
{
var parser = new HtmlParser();
var dom = parser.ParseDocument(result.Content);
@ -141,99 +149,111 @@ namespace Jackett.Common.Indexers
}
var result2 = await RequestStringWithCookies(LoginCompleteUrl, result.Cookies);
await ConfigureIfOK(
result2.Cookies, result2.Cookies?.Contains("pass") == true,
() => throw new ExceptionWithConfigData("Didn't get a user/pass cookie", configData));
await ConfigureIfOK(result2.Cookies, result2.Cookies != null && result2.Cookies.Contains("pass"), () =>
{
var errorMessage = "Didn't get a user/pass cookie";
throw new ExceptionWithConfigData(errorMessage, configData);
});
return IndexerConfigurationStatus.RequiresTesting;
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
{
var startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(
new DateTime(1, 1, 1, 3, 0, 0), 3, 5, DayOfWeek.Sunday);
var endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(
new DateTime(1, 1, 1, 4, 0, 0), 10, 5, DayOfWeek.Sunday);
var startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 3, 5, DayOfWeek.Sunday);
var endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 0, 0), 10, 5, DayOfWeek.Sunday);
var delta = new TimeSpan(1, 0, 0);
var adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(
new DateTime(1999, 10, 1), DateTime.MaxValue.Date, delta, startTransition,
endTransition);
TimeZoneInfo.AdjustmentRule[] adjustments =
{
adjustment
};
var germanyTz = TimeZoneInfo.CreateCustomTimeZone(
"W. Europe Standard Time", new TimeSpan(1, 0, 0), "(GMT+01:00) W. Europe Standard Time",
"W. Europe Standard Time", "W. Europe DST Time", adjustments);
var adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1999, 10, 1), DateTime.MaxValue.Date, delta, startTransition, endTransition);
TimeZoneInfo.AdjustmentRule[] adjustments = { adjustment };
var germanyTz = TimeZoneInfo.CreateCustomTimeZone("W. Europe Standard Time", new TimeSpan(1, 0, 0), "(GMT+01:00) W. Europe Standard Time", "W. Europe Standard Time", "W. Europe DST Time", adjustments);
var releases = new List<ReleaseInfo>();
var searchString = query.GetQueryString();
var searchUrl = IndexUrl;
var queryCollection = new NameValueCollection
{
{"strWebValue", "torrent"},
{"strWebAction", "search"},
{"sort", "torrent_added"},
{"by", "d"},
{"type", "0"},
{"do_search", "suchen"},
{"time", "0"},
{"details", "title"}
};
var queryCollection = new NameValueCollection();
queryCollection.Add("strWebValue", "torrent");
queryCollection.Add("strWebAction", "search");
queryCollection.Add("sort", "torrent_added");
queryCollection.Add("by", "d");
queryCollection.Add("type", "0");
queryCollection.Add("do_search", "suchen");
queryCollection.Add("time", "0");
queryCollection.Add("details", "title");
if (!string.IsNullOrWhiteSpace(searchString))
{
queryCollection.Add("searchstring", searchString);
}
foreach (var cat in MapTorznabCapsToTrackers(query))
{
queryCollection.Add("dirs" + cat, "1");
}
searchUrl += "?" + queryCollection.GetQueryString();
var response = await RequestStringWithCookies(searchUrl);
var titleRegexp = new Regex(@"^return buildTable\('(.*?)',\s+");
var TitleRegexp = new Regex(@"^return buildTable\('(.*?)',\s+");
try
{
var parser = new HtmlParser();
var dom = parser.ParseDocument(response.Content);
var rows = dom.QuerySelectorAll("table.torrenttable > tbody > tr");
foreach (var row in rows.Skip(1))
{
var release = new ReleaseInfo();
release.MinimumRatio = 0.8;
release.MinimumSeedTime = 0;
var qDetailsLink = row.QuerySelector("a[href^=\"index.php?strWebValue=torrent&strWebAction=details\"]");
release.Title = titleRegexp.Match(qDetailsLink.GetAttribute("onmouseover")).Groups[1].Value;
release.Title = TitleRegexp.Match(qDetailsLink.GetAttribute("onmouseover")).Groups[1].Value;
var qCatLink = row.QuerySelector("a[href^=\"index.php?strWebValue=torrent&strWebAction=search&dir=\"]");
var qDlLink = row.QuerySelector("a[href^=\"index.php?strWebValue=torrent&strWebAction=download&id=\"]");
var qSeeders = row.QuerySelectorAll("td.column1")[3];
var qLeechers = row.QuerySelectorAll("td.column2")[3];
var qSeeders = row.QuerySelector("td.column1:nth-of-type(4)");
var qLeechers = row.QuerySelector("td.column2:nth-of-type(4)");
var qDateStr = row.QuerySelector("font:has(a)");
var qSize = row.QuerySelector("td.column2[align=center]");
var catStr = qCatLink.GetAttribute("href").Split('=')[3].Split('#')[0];
release.Category = MapTrackerCatToNewznab(catStr);
release.Link = new Uri(SiteLink + qDlLink.GetAttribute("href"));
release.Comments = new Uri(SiteLink + qDetailsLink.GetAttribute("href"));
release.Guid = release.Link;
var sizeStr = qSize.TextContent;
var sizeStr = qSize.Text();
release.Size = ReleaseInfo.GetBytes(sizeStr);
release.Seeders = ParseUtil.CoerceInt(qSeeders.TextContent);
release.Peers = ParseUtil.CoerceInt(qLeechers.TextContent) + release.Seeders;
var dateStr = qDateStr.TextContent.Trim();
var dateStrParts = dateStr.Split();
var dateGerman = dateStrParts[0] switch
{
"Heute" => (DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateStrParts[1])),
"Gestern" => (DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateStrParts[1])
- TimeSpan.FromDays(1)),
_ => DateTime.SpecifyKind( DateTime.ParseExact(
dateStrParts[0] + dateStrParts[1], "dd.MM.yyyyHH:mm", CultureInfo.InvariantCulture),
DateTimeKind.Unspecified)
};
release.PublishDate = TimeZoneInfo.ConvertTime(dateGerman, germanyTz, TimeZoneInfo.Local);
var dateStr = qDateStr.Text().Trim();
var dateStrParts = dateStr.Split();
DateTime dateGerman;
if (dateStrParts[0] == "Heute")
dateGerman = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateStrParts[1]);
else if (dateStrParts[0] == "Gestern")
dateGerman = DateTime.SpecifyKind(DateTime.UtcNow.Date, DateTimeKind.Unspecified) + TimeSpan.Parse(dateStrParts[1]) - TimeSpan.FromDays(1);
else
dateGerman = DateTime.SpecifyKind(DateTime.ParseExact(dateStrParts[0] + dateStrParts[1], "dd.MM.yyyyHH:mm", CultureInfo.InvariantCulture), DateTimeKind.Unspecified);
var pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(dateGerman, germanyTz);
release.PublishDate = pubDateUtc.ToLocalTime();
var grabs = row.QuerySelector("td:nth-child(7)").TextContent;
release.Grabs = ParseUtil.CoerceInt(grabs);
if (row.QuerySelector("img[src=\"themes/images/onlyup.png\"]") != null)
if (row.QuerySelector("img[src=\"themes/images/freeleech.png\"]") != null)
release.DownloadVolumeFactor = 0;
else if (row.QuerySelector("img[src=\"themes/images/DL50.png\"]") != null)
release.DownloadVolumeFactor = 0.5;
else
release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 1;
releases.Add(release);
}
}