2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2016-12-29 18:56:35 +00:00
|
|
|
using System.Collections.Generic;
|
2017-04-15 08:45:10 +00:00
|
|
|
using System.Collections.Specialized;
|
2017-11-05 09:42:03 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Net;
|
2017-10-29 06:50:47 +00:00
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using AngleSharp.Dom;
|
2019-01-20 00:09:27 +00:00
|
|
|
using AngleSharp.Html.Parser;
|
2018-03-10 08:05:56 +00:00
|
|
|
using Jackett.Common.Models;
|
|
|
|
using Jackett.Common.Models.IndexerConfig;
|
|
|
|
using Jackett.Common.Services.Interfaces;
|
|
|
|
using Jackett.Common.Utils;
|
|
|
|
using Jackett.Common.Utils.Clients;
|
2017-11-05 09:42:03 +00:00
|
|
|
using Microsoft.AspNetCore.WebUtilities;
|
2017-10-29 06:50:47 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Indexers
|
2016-12-29 18:56:35 +00:00
|
|
|
{
|
2017-07-10 20:58:44 +00:00
|
|
|
public class Torrentech : BaseWebIndexer
|
2016-12-29 18:56:35 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
private string LoginUrl => SiteLink + "index.php?act=Login&CODE=01&CookieDate=1";
|
|
|
|
private string IndexUrl => SiteLink + "index.php";
|
2016-12-29 18:56:35 +00:00
|
|
|
|
2017-10-29 06:50:47 +00:00
|
|
|
private new ConfigurationDataBasicLoginWithRSSAndDisplay configData
|
2016-12-29 18:56:35 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
get => (ConfigurationDataBasicLoginWithRSSAndDisplay)base.configData;
|
|
|
|
set => base.configData = value;
|
2016-12-29 18:56:35 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
public Torrentech(IIndexerConfigurationService configService, Utils.Clients.WebClient wc, Logger l, IProtectionService ps)
|
2016-12-29 18:56:35 +00:00
|
|
|
: base(name: "Torrentech",
|
2017-10-01 09:26:07 +00:00
|
|
|
description: "TorrenTech (TTH) is a Private Torrent Tracker for ELECTRONIC MUSIC",
|
2016-12-29 18:56:35 +00:00
|
|
|
link: "https://www.torrentech.org/",
|
|
|
|
caps: TorznabUtil.CreateDefaultTorznabTVCaps(),
|
2017-07-10 20:58:44 +00:00
|
|
|
configService: configService,
|
2016-12-29 18:56:35 +00:00
|
|
|
client: wc,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationDataBasicLoginWithRSSAndDisplay())
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2016-12-29 18:56:35 +00:00
|
|
|
Encoding = Encoding.UTF8;
|
|
|
|
Language = "en-us";
|
2017-01-27 15:57:32 +00:00
|
|
|
Type = "private";
|
2016-12-29 18:56:35 +00:00
|
|
|
|
|
|
|
AddCategoryMapping(1, TorznabCatType.AudioMP3);
|
|
|
|
AddCategoryMapping(2, TorznabCatType.AudioLossless);
|
|
|
|
AddCategoryMapping(3, TorznabCatType.AudioOther);
|
|
|
|
}
|
|
|
|
|
2017-06-28 05:31:38 +00:00
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
2016-12-29 18:56:35 +00:00
|
|
|
{
|
2017-01-02 20:39:28 +00:00
|
|
|
LoadValuesFromJson(configJson);
|
2016-12-29 18:56:35 +00:00
|
|
|
|
|
|
|
var pairs = new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{ "UserName", configData.Username.Value },
|
|
|
|
{ "PassWord", configData.Password.Value }
|
|
|
|
};
|
|
|
|
|
|
|
|
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, LoginUrl, true);
|
2017-04-15 08:45:10 +00:00
|
|
|
await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("Logged in as: "), () =>
|
|
|
|
{
|
|
|
|
var errorMessage = result.Content;
|
|
|
|
throw new ExceptionWithConfigData(errorMessage, configData);
|
2016-12-29 18:56:35 +00:00
|
|
|
});
|
|
|
|
return IndexerConfigurationStatus.RequiresTesting;
|
|
|
|
}
|
|
|
|
|
2017-07-03 05:15:47 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
2016-12-29 18:56:35 +00:00
|
|
|
{
|
|
|
|
var releases = new List<ReleaseInfo>();
|
2017-04-15 08:45:10 +00:00
|
|
|
var searchString = query.GetQueryString();
|
|
|
|
|
|
|
|
WebClientStringResult results = null;
|
|
|
|
var queryCollection = new NameValueCollection();
|
|
|
|
|
|
|
|
queryCollection.Add("act", "search");
|
|
|
|
queryCollection.Add("forums", "all");
|
|
|
|
queryCollection.Add("torrents", "1");
|
|
|
|
queryCollection.Add("search_in", "titles");
|
|
|
|
queryCollection.Add("result_type", "topics");
|
|
|
|
|
|
|
|
// if the search string is empty use the getnew view
|
|
|
|
if (string.IsNullOrWhiteSpace(searchString))
|
|
|
|
{
|
|
|
|
queryCollection.Add("CODE", "getnew");
|
|
|
|
queryCollection.Add("active", "1");
|
2016-12-29 18:56:35 +00:00
|
|
|
}
|
2017-04-15 08:45:10 +00:00
|
|
|
else // use the normal search
|
|
|
|
{
|
|
|
|
searchString = searchString.Replace("-", " ");
|
|
|
|
queryCollection.Add("CODE", "01");
|
|
|
|
queryCollection.Add("keywords", searchString);
|
2016-12-29 18:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var searchUrl = IndexUrl + "?" + queryCollection.GetQueryString();
|
2017-04-15 08:45:10 +00:00
|
|
|
results = await RequestStringWithCookies(searchUrl);
|
|
|
|
if (results.IsRedirect && results.RedirectingTo.Contains("CODE=show"))
|
|
|
|
{
|
|
|
|
results = await RequestStringWithCookies(results.RedirectingTo);
|
|
|
|
}
|
2016-12-29 18:56:35 +00:00
|
|
|
try
|
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var RowsSelector = "div.borderwrap:has(div.maintitle) > table > tbody > tr:has(a[href*=\"index.php?showtopic=\"])";
|
2016-12-29 18:56:35 +00:00
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
var SearchResultParser = new HtmlParser();
|
2019-01-20 00:09:27 +00:00
|
|
|
var SearchResultDocument = SearchResultParser.ParseDocument(results.Content);
|
2017-04-15 08:45:10 +00:00
|
|
|
var Rows = SearchResultDocument.QuerySelectorAll(RowsSelector);
|
|
|
|
foreach (var Row in Rows)
|
2016-12-29 18:56:35 +00:00
|
|
|
{
|
2017-04-15 08:45:10 +00:00
|
|
|
try
|
2016-12-29 18:56:35 +00:00
|
|
|
{
|
|
|
|
var release = new ReleaseInfo();
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
var StatsElements = Row.QuerySelector("td:nth-child(5)");
|
|
|
|
var stats = StatsElements.TextContent.Split('·');
|
|
|
|
if (stats.Length != 3) // not a torrent
|
|
|
|
continue;
|
|
|
|
|
|
|
|
release.Seeders = ParseUtil.CoerceInt(stats[0]);
|
|
|
|
release.Peers = ParseUtil.CoerceInt(stats[1]) + release.Seeders;
|
2016-12-29 18:56:35 +00:00
|
|
|
release.Grabs = ParseUtil.CoerceInt(stats[2]);
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
release.MinimumRatio = 0.51;
|
2016-12-29 18:56:35 +00:00
|
|
|
release.MinimumSeedTime = 0;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
var qDetailsLink = Row.QuerySelector("a[onmouseover][href*=\"index.php?showtopic=\"]");
|
|
|
|
release.Title = qDetailsLink.TextContent;
|
|
|
|
release.Comments = new Uri(qDetailsLink.GetAttribute("href"));
|
|
|
|
release.Link = release.Comments;
|
|
|
|
release.Guid = release.Link;
|
|
|
|
|
|
|
|
release.DownloadVolumeFactor = 1;
|
|
|
|
release.UploadVolumeFactor = 1;
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
var id = QueryHelpers.ParseQuery(release.Comments.Query)["showtopic"].FirstOrDefault();
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
var desc = Row.QuerySelector("span.desc");
|
|
|
|
var forange = desc.QuerySelector("font.forange");
|
|
|
|
if (forange != null)
|
|
|
|
{
|
|
|
|
var DownloadVolumeFactor = forange.QuerySelector("i:contains(\"freeleech\")");
|
|
|
|
if (DownloadVolumeFactor != null)
|
|
|
|
release.DownloadVolumeFactor = 0;
|
|
|
|
|
|
|
|
var UploadVolumeFactor = forange.QuerySelector("i:contains(\"x upload]\")");
|
|
|
|
if (UploadVolumeFactor != null)
|
|
|
|
release.UploadVolumeFactor = ParseUtil.CoerceDouble(UploadVolumeFactor.TextContent.Split(' ')[0].Substring(1).Replace("x", ""));
|
|
|
|
forange.Remove();
|
|
|
|
}
|
|
|
|
var format = desc.TextContent;
|
|
|
|
release.Title += " [" + format + "]";
|
|
|
|
|
|
|
|
var preview = SearchResultDocument.QuerySelector("div#d21-tph-preview-data-" + id);
|
|
|
|
if (preview != null)
|
|
|
|
{
|
|
|
|
release.Description = "";
|
|
|
|
foreach (var e in preview.ChildNodes)
|
|
|
|
{
|
|
|
|
if (e.NodeType == NodeType.Text)
|
|
|
|
release.Description += e.NodeValue;
|
|
|
|
else
|
|
|
|
release.Description += e.TextContent + "\n";
|
|
|
|
}
|
|
|
|
}
|
2017-11-05 09:42:03 +00:00
|
|
|
release.Description = WebUtility.HtmlEncode(release.Description.Trim());
|
2017-04-15 08:45:10 +00:00
|
|
|
release.Description = release.Description.Replace("\n", "<br>");
|
|
|
|
|
|
|
|
if (format.Contains("MP3"))
|
|
|
|
release.Category = new List<int> { TorznabCatType.AudioMP3.ID };
|
|
|
|
else if (format.Contains("AAC"))
|
|
|
|
release.Category = new List<int> { TorznabCatType.AudioOther.ID };
|
|
|
|
else if (format.Contains("Lossless"))
|
|
|
|
release.Category = new List<int> { TorznabCatType.AudioLossless.ID };
|
|
|
|
else
|
|
|
|
release.Category = new List<int> { TorznabCatType.AudioOther.ID };
|
|
|
|
|
|
|
|
var lastAction = Row.QuerySelector("td:nth-child(9) > span").FirstChild.NodeValue;
|
|
|
|
release.PublishDate = DateTimeUtil.FromUnknown(lastAction, "UK");
|
|
|
|
|
|
|
|
releases.Add(release);
|
2016-12-29 18:56:35 +00:00
|
|
|
}
|
2017-04-15 08:45:10 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
logger.Error(string.Format("{0}: Error while parsing row '{1}':\n\n{2}", ID, Row.OuterHtml, ex));
|
|
|
|
}
|
|
|
|
}
|
2016-12-29 18:56:35 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
OnParseError(results.Content, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
public override async Task<byte[]> Download(Uri link)
|
|
|
|
{
|
|
|
|
var response = await RequestStringWithCookies(link.ToString());
|
|
|
|
var results = response.Content;
|
|
|
|
var SearchResultParser = new HtmlParser();
|
2019-01-20 00:09:27 +00:00
|
|
|
var SearchResultDocument = SearchResultParser.ParseDocument(results);
|
2017-04-15 08:45:10 +00:00
|
|
|
var downloadSelector = "a[title=\"Download attachment\"]";
|
|
|
|
var DlUri = SearchResultDocument.QuerySelector(downloadSelector);
|
|
|
|
if (DlUri != null)
|
|
|
|
{
|
|
|
|
logger.Debug(string.Format("{0}: Download selector {1} matched:{2}", ID, downloadSelector, DlUri.OuterHtml));
|
|
|
|
var href = DlUri.GetAttribute("href");
|
|
|
|
link = new Uri(href);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logger.Error(string.Format("{0}: Download selector {1} didn't match:\n{2}", ID, downloadSelector, results));
|
|
|
|
throw new Exception(string.Format("Download selector {0} didn't match", downloadSelector));
|
|
|
|
}
|
|
|
|
return await base.Download(link);
|
2016-12-29 18:56:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|