Jackett/src/Jackett.Common/Indexers/TorrentLeech.cs

215 lines
8.9 KiB
C#
Raw Normal View History

2017-10-29 06:50:47 +00:00
using System;
2015-04-26 02:32:03 +00:00
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
2015-04-26 02:32:03 +00:00
using System.Text;
using System.Threading.Tasks;
using System.Web;
2017-10-29 06:50:47 +00:00
using CsQuery;
using Jackett.Models;
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;
2017-10-29 06:50:47 +00:00
using Jackett.Utils;
using Jackett.Utils.Clients;
using Newtonsoft.Json.Linq;
using NLog;
2015-04-26 02:32:03 +00:00
namespace Jackett.Indexers
{
public class TorrentLeech : BaseWebIndexer
2015-04-26 02:32:03 +00:00
{
private string LoginUrl { get { return SiteLink + "user/account/login/"; } }
private string SearchUrl { get { return SiteLink + "torrents/browse/index/"; } }
2015-04-26 02:32:03 +00:00
2017-10-29 06:50:47 +00:00
private new ConfigurationDataBasicLogin configData
{
get { return (ConfigurationDataBasicLogin)base.configData; }
set { base.configData = value; }
}
public TorrentLeech(IIndexerConfigurationService configService, Utils.Clients.WebClient wc, Logger l, IProtectionService ps)
: base(name: "TorrentLeech",
description: "This is what happens when you seed",
2015-10-07 23:17:54 +00:00
link: "https://www.torrentleech.org/",
2015-08-11 18:48:25 +00:00
caps: TorznabUtil.CreateDefaultTorznabTVCaps(),
configService: configService,
client: wc,
logger: l,
2015-08-07 19:09:13 +00:00
p: ps,
2015-10-07 23:17:54 +00:00
downloadBase: "https://www.torrentleech.org/download/",
configData: new ConfigurationDataBasicLogin("For best results, change the 'Default Number of Torrents per Page' setting to the maximum in your profile on the TorrentLeech webpage."))
2015-04-26 02:32:03 +00:00
{
Encoding = Encoding.GetEncoding("iso-8859-1");
2016-12-09 17:20:58 +00:00
Language = "en-us";
Type = "private";
AddCategoryMapping(8, TorznabCatType.MoviesSD); // cam
AddCategoryMapping(9, TorznabCatType.MoviesSD); //ts
AddCategoryMapping(10, TorznabCatType.MoviesSD); // Sceener
AddCategoryMapping(11, TorznabCatType.MoviesSD);
AddCategoryMapping(12, TorznabCatType.MoviesSD);
AddCategoryMapping(13, TorznabCatType.MoviesHD);
AddCategoryMapping(14, TorznabCatType.MoviesHD);
AddCategoryMapping(15, TorznabCatType.Movies); // Boxsets
AddCategoryMapping(29, TorznabCatType.TVDocumentary);
AddCategoryMapping(41, TorznabCatType.MoviesHD, "4K Upscaled");
AddCategoryMapping(47, TorznabCatType.MoviesHD, "Real 4K UltraHD HDR");
2016-12-29 11:14:35 +00:00
AddCategoryMapping(36, TorznabCatType.MoviesForeign);
AddCategoryMapping(37, TorznabCatType.MoviesWEBDL);
AddCategoryMapping(43, TorznabCatType.MoviesSD, "Movies/HDRip");
AddCategoryMapping(26, TorznabCatType.TVSD);
AddCategoryMapping(27, TorznabCatType.TV); // Boxsets
AddCategoryMapping(32, TorznabCatType.TVHD);
2016-12-29 11:14:35 +00:00
AddCategoryMapping(44, TorznabCatType.TVFOREIGN, "TV/Foreign");
AddCategoryMapping(17, TorznabCatType.PCGames);
AddCategoryMapping(18, TorznabCatType.ConsoleXbox);
AddCategoryMapping(19, TorznabCatType.ConsoleXbox360);
2016-12-29 11:14:35 +00:00
AddCategoryMapping(40, TorznabCatType.ConsoleXbox, "Games/XBOXONE");
AddCategoryMapping(20, TorznabCatType.ConsolePS3); // PS2
AddCategoryMapping(21, TorznabCatType.ConsolePS3);
AddCategoryMapping(22, TorznabCatType.ConsolePSP);
AddCategoryMapping(28, TorznabCatType.ConsoleWii);
AddCategoryMapping(30, TorznabCatType.ConsoleNDS);
2016-12-29 11:14:35 +00:00
AddCategoryMapping(39, TorznabCatType.ConsolePS4);
AddCategoryMapping(42, TorznabCatType.PCMac, "Games/Mac");
AddCategoryMapping(16, TorznabCatType.AudioVideo);
AddCategoryMapping(31, TorznabCatType.Audio);
AddCategoryMapping(34, TorznabCatType.TVAnime);
AddCategoryMapping(35, TorznabCatType.TV); // Cartoons
AddCategoryMapping(5, TorznabCatType.Books);
2016-12-29 11:14:35 +00:00
AddCategoryMapping(45, TorznabCatType.BooksEbook, "Books/EBooks");
AddCategoryMapping(46, TorznabCatType.BooksComics, "Books/Comics");
AddCategoryMapping(23, TorznabCatType.PCISO);
AddCategoryMapping(24, TorznabCatType.PCMac);
AddCategoryMapping(25, TorznabCatType.PCPhoneOther);
AddCategoryMapping(33, TorznabCatType.PC0day);
2016-12-29 11:14:35 +00:00
AddCategoryMapping(38, TorznabCatType.Other, "Education");
2015-04-26 02:32:03 +00:00
}
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
2015-04-26 02:32:03 +00:00
{
LoadValuesFromJson(configJson);
await DoLogin();
return IndexerConfigurationStatus.RequiresTesting;
}
private async Task DoLogin()
{
2015-04-26 02:32:03 +00:00
var pairs = new Dictionary<string, string> {
{ "username", configData.Username.Value },
{ "password", configData.Password.Value }
};
2015-04-26 02:32:03 +00:00
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, LoginUrl);
await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("/user/account/logout"), () =>
2015-04-26 02:32:03 +00:00
{
CQ dom = result.Content;
var errorMessage = dom["div#login_heading + div.card-panel-error"].Text();
throw new ExceptionWithConfigData(errorMessage, configData);
});
2015-04-26 02:32:03 +00:00
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
2015-04-26 02:32:03 +00:00
{
var releases = new List<ReleaseInfo>();
var searchString = query.GetQueryString();
searchString = searchString.Replace('-', ' '); // remove dashes as they exclude search strings
var searchUrl = SearchUrl;
if (!string.IsNullOrWhiteSpace(searchString))
{
searchUrl += "query/" + WebUtility.UrlEncode(searchString) + "/";
}
string.Format(SearchUrl, WebUtility.UrlEncode(searchString));
var cats = MapTorznabCapsToTrackers(query);
if (cats.Count > 0)
{
searchUrl += "categories/";
foreach (var cat in cats)
{
if (!searchUrl.EndsWith("/"))
searchUrl += ",";
searchUrl += cat;
}
}
else
{
searchUrl += "newfilter/2"; // include 0day and music
}
var results = await RequestStringWithCookiesAndRetry(searchUrl);
if (!results.Content.Contains("/user/account/logout"))
{
//Cookie appears to expire after a period of time or logging in to the site via browser
await DoLogin();
results = await RequestStringWithCookiesAndRetry(searchUrl);
}
try
2015-04-26 02:32:03 +00:00
{
CQ dom = results.Content;
2015-04-26 02:32:03 +00:00
CQ qRows = dom["#torrenttable > tbody > tr"];
2015-04-26 02:32:03 +00:00
foreach (var row in qRows)
{
var release = new ReleaseInfo();
2015-04-26 02:32:03 +00:00
var qRow = row.Cq();
2015-04-26 02:32:03 +00:00
var debug = qRow.Html();
2015-04-26 02:32:03 +00:00
release.MinimumRatio = 1;
release.MinimumSeedTime = 172800;
2015-04-26 02:32:03 +00:00
CQ qLink = qRow.Find(".title > a").First();
release.Guid = new Uri(SiteLink + qLink.Attr("href").Substring(1));
release.Comments = release.Guid;
release.Title = qLink.Text();
2016-12-29 11:01:42 +00:00
if (!query.MatchQueryStringAND(release.Title))
2016-12-29 11:01:42 +00:00
continue;
2015-04-26 02:32:03 +00:00
2016-12-11 15:41:02 +00:00
release.Link = new Uri(qRow.Find(".quickdownload > a").Attr("href"));
2015-04-26 02:32:03 +00:00
2016-12-17 12:24:57 +00:00
var dateString = qRow.Find("span.addedInLine").Get(0).LastChild.NodeValue.Replace("on", string.Empty).Trim(); ;
2016-12-11 15:36:48 +00:00
release.PublishDate = DateTime.ParseExact(dateString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
2015-04-26 02:32:03 +00:00
var sizeStr = qRow.Children().ElementAt(4).InnerText;
release.Size = ReleaseInfo.GetBytes(sizeStr);
2015-04-26 02:32:03 +00:00
release.Seeders = ParseUtil.CoerceInt(qRow.Find(".seeders").Text());
release.Peers = release.Seeders + ParseUtil.CoerceInt(qRow.Find(".leechers").Text());
2015-05-04 04:12:14 +00:00
var category = qRow.Find(".category a").Attr("href").Replace("/torrents/browse/index/categories/", string.Empty);
release.Category = MapTrackerCatToNewznab(category);
2016-10-30 12:21:32 +00:00
var grabs = qRow.Find("td:nth-child(6)").Get(0).FirstChild.ToString();
release.Grabs = ParseUtil.CoerceInt(grabs);
release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 1;
releases.Add(release);
2015-04-26 02:32:03 +00:00
}
}
catch (Exception ex)
{
OnParseError(results.Content, ex);
}
2015-05-04 04:12:14 +00:00
return releases;
2015-04-26 02:32:03 +00:00
}
}
}