2017-10-29 06:21:18 +00:00
|
|
|
|
using System;
|
2015-10-22 22:31:59 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-10-29 06:21:18 +00:00
|
|
|
|
using System.Collections.Specialized;
|
2015-10-22 22:31:59 +00:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-10-29 06:21:18 +00:00
|
|
|
|
using CsQuery;
|
|
|
|
|
using Jackett.Models;
|
2015-10-22 22:31:59 +00:00
|
|
|
|
using Jackett.Models.IndexerConfig;
|
2017-10-29 10:19:09 +00:00
|
|
|
|
using Jackett.Services.Interfaces;
|
2017-10-29 06:21:18 +00:00
|
|
|
|
using Jackett.Utils;
|
|
|
|
|
using Jackett.Utils.Clients;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using NLog;
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
|
|
|
|
namespace Jackett.Indexers
|
|
|
|
|
{
|
|
|
|
|
//
|
2017-10-29 06:21:18 +00:00
|
|
|
|
// Quick and dirty indexer for GFTracker.
|
|
|
|
|
//
|
2017-07-10 20:58:44 +00:00
|
|
|
|
public class GFTracker : BaseWebIndexer
|
2015-10-22 22:31:59 +00:00
|
|
|
|
{
|
|
|
|
|
private string StartPageUrl { get { return SiteLink + "login.php?returnto=%2F"; } }
|
|
|
|
|
private string LoginUrl { get { return SiteLink + "loginsite.php"; } }
|
|
|
|
|
private string SearchUrl { get { return SiteLink + "browse.php"; } }
|
|
|
|
|
|
2017-10-29 06:21:18 +00:00
|
|
|
|
private new ConfigurationDataRecaptchaLogin configData
|
2015-10-22 22:31:59 +00:00
|
|
|
|
{
|
|
|
|
|
get { return (ConfigurationDataRecaptchaLogin)base.configData; }
|
|
|
|
|
set { base.configData = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
|
public GFTracker(IIndexerConfigurationService configService, WebClient w, Logger l, IProtectionService ps)
|
2015-10-22 22:31:59 +00:00
|
|
|
|
: base(name: "GFTracker",
|
|
|
|
|
description: "Home of user happiness",
|
|
|
|
|
link: "https://www.thegft.org/",
|
|
|
|
|
caps: TorznabUtil.CreateDefaultTorznabTVCaps(),
|
2017-07-10 20:58:44 +00:00
|
|
|
|
configService: configService,
|
2015-10-22 22:31:59 +00:00
|
|
|
|
client: w,
|
|
|
|
|
logger: l,
|
|
|
|
|
p: ps,
|
|
|
|
|
configData: new ConfigurationDataRecaptchaLogin())
|
|
|
|
|
{
|
2016-12-09 17:20:58 +00:00
|
|
|
|
Encoding = Encoding.UTF8;
|
|
|
|
|
Language = "en-us";
|
2017-01-27 15:57:32 +00:00
|
|
|
|
Type = "private";
|
2016-12-09 17:20:58 +00:00
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
|
AddCategoryMapping(2, TorznabCatType.PC0day, "0DAY");
|
|
|
|
|
AddCategoryMapping(16, TorznabCatType.TVAnime, "Anime");
|
|
|
|
|
AddCategoryMapping(1, TorznabCatType.PC0day, "APPS");
|
|
|
|
|
AddCategoryMapping(9, TorznabCatType.Other, "E-Learning");
|
|
|
|
|
AddCategoryMapping(35, TorznabCatType.TVFOREIGN, "Foreign");
|
|
|
|
|
AddCategoryMapping(32, TorznabCatType.ConsoleNDS, "Games/NDS");
|
|
|
|
|
AddCategoryMapping(6, TorznabCatType.PCGames, "Games/PC");
|
|
|
|
|
AddCategoryMapping(36, TorznabCatType.ConsolePS4, "Games/Playstation");
|
|
|
|
|
AddCategoryMapping(29, TorznabCatType.ConsolePSP, "Games/PSP");
|
|
|
|
|
AddCategoryMapping(23, TorznabCatType.ConsoleWii, "Games/WII");
|
|
|
|
|
AddCategoryMapping(12, TorznabCatType.ConsoleXbox, "Games/XBOX");
|
|
|
|
|
AddCategoryMapping(11, TorznabCatType.Other, "Misc");
|
|
|
|
|
AddCategoryMapping(48, TorznabCatType.MoviesBluRay, "Movies/BLURAY");
|
|
|
|
|
AddCategoryMapping(8, TorznabCatType.MoviesDVD, "Movies/DVDR");
|
|
|
|
|
AddCategoryMapping(18, TorznabCatType.MoviesHD, "Movies/X264-HD");
|
|
|
|
|
AddCategoryMapping(49, TorznabCatType.MoviesSD, "Movies/X264-SD");
|
|
|
|
|
AddCategoryMapping(7, TorznabCatType.MoviesSD, "Movies/XVID");
|
|
|
|
|
AddCategoryMapping(38, TorznabCatType.AudioOther, "Music/DVDR");
|
|
|
|
|
AddCategoryMapping(46, TorznabCatType.AudioLossless, "Music/FLAC");
|
|
|
|
|
AddCategoryMapping(5, TorznabCatType.AudioMP3, "Music/MP3");
|
|
|
|
|
AddCategoryMapping(13, TorznabCatType.AudioVideo, "Music/Vids");
|
|
|
|
|
AddCategoryMapping(26, TorznabCatType.TVHD, "TV/BLURAY");
|
|
|
|
|
AddCategoryMapping(37, TorznabCatType.TVSD, "TV/DVDR");
|
|
|
|
|
AddCategoryMapping(19, TorznabCatType.TVSD, "TV/DVDRIP");
|
|
|
|
|
AddCategoryMapping(47, TorznabCatType.TVSD, "TV/SD");
|
|
|
|
|
AddCategoryMapping(17, TorznabCatType.TVHD, "TV/X264");
|
|
|
|
|
AddCategoryMapping(4, TorznabCatType.TVSD, "TV/XVID");
|
|
|
|
|
AddCategoryMapping(22, TorznabCatType.XXX, "XXX/0DAY");
|
|
|
|
|
AddCategoryMapping(25, TorznabCatType.XXXDVD, "XXX/DVDR");
|
|
|
|
|
AddCategoryMapping(20, TorznabCatType.XXX, "XXX/HD");
|
2017-01-03 15:09:07 +00:00
|
|
|
|
AddCategoryMapping(3, TorznabCatType.XXXXviD, "XXX/XVID");
|
2015-10-22 22:31:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async Task<ConfigurationData> GetConfigurationForSetup()
|
|
|
|
|
{
|
|
|
|
|
var loginPage = await RequestStringWithCookies(StartPageUrl, string.Empty);
|
|
|
|
|
CQ cq = loginPage.Content;
|
2016-10-27 07:26:11 +00:00
|
|
|
|
var result = this.configData;
|
2015-10-22 22:31:59 +00:00
|
|
|
|
CQ recaptcha = cq.Find(".g-recaptcha").Attr("data-sitekey");
|
2017-10-29 06:21:18 +00:00
|
|
|
|
if (recaptcha.Length != 0) // recaptcha not always present in login form, perhaps based on cloudflare uid or just phase of the moon
|
2015-10-22 22:31:59 +00:00
|
|
|
|
{
|
|
|
|
|
result.CookieHeader.Value = loginPage.Cookies;
|
|
|
|
|
result.Captcha.SiteKey = cq.Find(".g-recaptcha").Attr("data-sitekey");
|
2016-10-27 07:26:11 +00:00
|
|
|
|
result.Captcha.Version = "2";
|
2015-10-22 22:31:59 +00:00
|
|
|
|
return result;
|
2017-10-29 06:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2015-10-22 22:31:59 +00:00
|
|
|
|
{
|
|
|
|
|
var stdResult = new ConfigurationDataBasicLogin();
|
2017-01-02 20:39:28 +00:00
|
|
|
|
stdResult.SiteLink.Value = configData.SiteLink.Value;
|
2016-10-27 07:26:11 +00:00
|
|
|
|
stdResult.Username.Value = configData.Username.Value;
|
|
|
|
|
stdResult.Password.Value = configData.Password.Value;
|
2015-10-22 22:31:59 +00:00
|
|
|
|
stdResult.CookieHeader.Value = loginPage.Cookies;
|
|
|
|
|
return stdResult;
|
2017-10-29 06:21:18 +00:00
|
|
|
|
}
|
2015-10-22 22:31:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-28 05:31:38 +00:00
|
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
2015-10-22 22:31:59 +00:00
|
|
|
|
{
|
2017-01-02 20:39:28 +00:00
|
|
|
|
LoadValuesFromJson(configJson);
|
2015-10-22 22:31:59 +00:00
|
|
|
|
var pairs = new Dictionary<string, string> {
|
|
|
|
|
{ "username", configData.Username.Value },
|
|
|
|
|
{ "password", configData.Password.Value },
|
|
|
|
|
{ "g-recaptcha-response", configData.Captcha.Value }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(configData.Captcha.Cookie))
|
|
|
|
|
{
|
|
|
|
|
CookieHeader = configData.Captcha.Cookie;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var results = await PerformQuery(new TorznabQuery());
|
|
|
|
|
if (results.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Your cookie did not work");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IsConfigured = true;
|
2017-05-06 17:39:02 +00:00
|
|
|
|
SaveConfig();
|
2015-10-22 22:31:59 +00:00
|
|
|
|
return IndexerConfigurationStatus.Completed;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
IsConfigured = false;
|
|
|
|
|
throw new Exception("Your cookie did not work: " + e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 15:09:07 +00:00
|
|
|
|
var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, configData.CookieHeader.Value, true, SearchUrl, StartPageUrl);
|
|
|
|
|
UpdateCookieHeader(response.Cookies);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
UpdateCookieHeader("mybbuser=;"); // add dummy cookie, otherwise we get logged out after each request
|
|
|
|
|
|
2017-01-03 15:09:07 +00:00
|
|
|
|
await ConfigureIfOK(configData.CookieHeader.Value, response.Content != null && response.Content.Contains("logout.php"), () =>
|
2015-10-22 22:31:59 +00:00
|
|
|
|
{
|
|
|
|
|
CQ dom = response.Content;
|
2017-01-03 15:09:07 +00:00
|
|
|
|
var messageEl = dom["div:has(h2)"].Last();
|
2015-10-22 22:31:59 +00:00
|
|
|
|
messageEl.Children("a").Remove();
|
|
|
|
|
messageEl.Children("style").Remove();
|
|
|
|
|
var errorMessage = messageEl.Text().Trim();
|
2017-01-03 15:09:07 +00:00
|
|
|
|
IsConfigured = false;
|
2015-10-22 22:31:59 +00:00
|
|
|
|
throw new ExceptionWithConfigData(errorMessage, configData);
|
|
|
|
|
});
|
|
|
|
|
return IndexerConfigurationStatus.RequiresTesting;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-03 05:15:47 +00:00
|
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
2015-10-22 22:31:59 +00:00
|
|
|
|
{
|
|
|
|
|
var releases = new List<ReleaseInfo>();
|
|
|
|
|
var searchString = query.GetQueryString();
|
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
// search in normal + gems view
|
2017-10-29 06:21:18 +00:00
|
|
|
|
foreach (var view in new string[] { "0", "1" })
|
2015-10-22 22:31:59 +00:00
|
|
|
|
{
|
2017-02-27 18:55:02 +00:00
|
|
|
|
var queryCollection = new NameValueCollection();
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
queryCollection.Add("view", view);
|
|
|
|
|
queryCollection.Add("searchtype", "1");
|
|
|
|
|
queryCollection.Add("incldead", "1");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchString))
|
|
|
|
|
{
|
|
|
|
|
queryCollection.Add("search", searchString);
|
|
|
|
|
}
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
foreach (var cat in MapTorznabCapsToTrackers(query))
|
|
|
|
|
{
|
|
|
|
|
queryCollection.Add(string.Format("c{0}", cat), "1");
|
|
|
|
|
}
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
var searchUrl = SearchUrl + "?" + queryCollection.GetQueryString();
|
2017-01-03 15:09:07 +00:00
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
|
var results = await RequestStringWithCookiesAndRetry(searchUrl);
|
|
|
|
|
if (results.IsRedirect)
|
|
|
|
|
{
|
|
|
|
|
// re-login
|
|
|
|
|
await ApplyConfiguration(null);
|
|
|
|
|
results = await RequestStringWithCookiesAndRetry(searchUrl);
|
2017-02-27 18:55:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
2015-10-22 22:31:59 +00:00
|
|
|
|
{
|
2017-02-27 18:55:02 +00:00
|
|
|
|
CQ dom = results.Content;
|
|
|
|
|
var rows = dom["#torrentBrowse > table > tbody > tr"];
|
|
|
|
|
foreach (var row in rows.Skip(1))
|
|
|
|
|
{
|
|
|
|
|
var release = new ReleaseInfo();
|
|
|
|
|
CQ qRow = row.Cq();
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
release.MinimumRatio = 0;
|
|
|
|
|
release.MinimumSeedTime = 2 * 24 * 60 * 60;
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
var qLink = qRow.Find("a[title][href^=\"details.php?id=\"]");
|
|
|
|
|
release.Title = qLink.Attr("title");
|
|
|
|
|
release.Guid = new Uri(SiteLink + qLink.Attr("href").TrimStart('/'));
|
|
|
|
|
release.Comments = release.Guid;
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
qLink = qRow.Children().ElementAt(3).Cq().Children("a").First();
|
|
|
|
|
release.Link = new Uri(string.Format("{0}{1}", SiteLink, qLink.Attr("href")));
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
var catUrl = qRow.Children().ElementAt(0).FirstElementChild.Cq().Attr("href");
|
|
|
|
|
var catNum = catUrl.Split(new char[] { '=', '&' })[2].Replace("c", "");
|
|
|
|
|
release.Category = MapTrackerCatToNewznab(catNum);
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
var dateString = qRow.Children().ElementAt(6).Cq().Text().Trim();
|
|
|
|
|
if (dateString.Contains("ago"))
|
|
|
|
|
release.PublishDate = DateTimeUtil.FromTimeAgo(dateString);
|
|
|
|
|
else
|
|
|
|
|
release.PublishDate = DateTime.ParseExact(dateString, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture);
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
var sizeStr = qRow.Children().ElementAt(7).Cq().Text().Split(new char[] { '/' })[0];
|
|
|
|
|
release.Size = ReleaseInfo.GetBytes(sizeStr);
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
release.Seeders = ParseUtil.CoerceInt(qRow.Children().ElementAt(8).Cq().Text().Split(new char[] { '/' })[0].Trim());
|
|
|
|
|
release.Peers = ParseUtil.CoerceInt(qRow.Children().ElementAt(8).Cq().Text().Split(new char[] { '/' })[1].Trim()) + release.Seeders;
|
|
|
|
|
release.Files = ParseUtil.CoerceLong(qRow.Find("td:nth-child(5)").Text());
|
|
|
|
|
release.Grabs = ParseUtil.CoerceLong(qRow.Find("a[href^=\"snatches.php?id=\"]").Text().Split(' ')[0]);
|
2017-01-03 15:09:07 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
release.DownloadVolumeFactor = 0;
|
|
|
|
|
release.UploadVolumeFactor = 1;
|
2017-01-03 15:09:07 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
var desc = qRow.Find("td:nth-child(2)");
|
|
|
|
|
desc.Find("a").Remove();
|
|
|
|
|
desc.Find("small").Remove(); // Remove release name (if enabled in the user cp)
|
2017-10-29 06:21:18 +00:00
|
|
|
|
release.Description = desc.Text().Trim(new char[] { '-', ' ' });
|
2015-10-22 22:31:59 +00:00
|
|
|
|
|
2017-02-27 18:55:02 +00:00
|
|
|
|
releases.Add(release);
|
|
|
|
|
}
|
2015-10-22 22:31:59 +00:00
|
|
|
|
}
|
2017-02-27 18:55:02 +00:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
OnParseError(results.Content, ex);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
}
|
2015-10-22 22:31:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|