Jackett/src/Jackett.Common/Indexers/GFTracker.cs

246 lines
11 KiB
C#
Raw Normal View History

using System;
2015-10-22 22:31:59 +00:00
using System.Collections.Generic;
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;
using CsQuery;
using Jackett.Models;
2015-10-22 22:31:59 +00:00
using Jackett.Models.IndexerConfig;
Feature/netcore preparation (#2035) * Move to use package reference for restoring nuget packages. * Return a task result for this async method. * Update to a supported version of the .NET Framework. This also has the side effect of allowing us to automatically generate our binding redirects on build. * Set the solution to target VS2017 * Update test solution csproj file to support being built through MSBuild 15 * Move to use package reference for restoring nuget packages. * Return a task result for this async method. * Update to a supported version of the .NET Framework. This also has the side effect of allowing us to automatically generate our binding redirects on build. * Set the solution to target VS2017 * Update test solution csproj file to support being built through MSBuild 15 * DateTimeRoutines does not have Nuget packages that support .NET Standard (and therefore .NET Core). We will have to include them for now until we can get rid of this dependency. * Move the interfaces into their own files. This will be useful when we share them between the .NET Core and .NET Framework WebAPI * Stage services that need to point to the new interface namespace. * Update CurlSharp to fix memory leak issue and support better runtime compatibility with OSX and Linux * Start spliting some interfaces into their own files - this will help by allowing us to split them out in the future into a seperate project so the actual implementations can stay within their respective architectures when required
2017-10-29 10:19:09 +00:00
using Jackett.Services.Interfaces;
using Jackett.Utils;
using Jackett.Utils.Clients;
using Newtonsoft.Json.Linq;
using NLog;
2015-10-22 22:31:59 +00:00
namespace Jackett.Indexers
{
//
// Quick and dirty indexer for GFTracker.
//
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"; } }
private new ConfigurationDataRecaptchaLogin configData
2015-10-22 22:31:59 +00:00
{
get { return (ConfigurationDataRecaptchaLogin)base.configData; }
set { base.configData = value; }
}
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(),
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";
Type = "private";
2016-12-09 17:20:58 +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;
var result = this.configData;
2015-10-22 22:31:59 +00:00
CQ recaptcha = cq.Find(".g-recaptcha").Attr("data-sitekey");
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");
result.Captcha.Version = "2";
2015-10-22 22:31:59 +00:00
return result;
}
else
2015-10-22 22:31:59 +00:00
{
var stdResult = new ConfigurationDataBasicLogin();
stdResult.SiteLink.Value = configData.SiteLink.Value;
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;
}
2015-10-22 22:31:59 +00:00
}
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
2015-10-22 22:31:59 +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);
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;
}
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
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
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)
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);
}
2015-10-22 22:31:59 +00:00
}
return releases;
}
}
}