Jackett/src/Jackett/Indexers/HDTorrents.cs

139 lines
5.7 KiB
C#
Raw Normal View History

2015-07-11 19:27:57 +00:00
using CsQuery;
2015-07-19 00:27:41 +00:00
using Jackett.Models;
2015-07-19 17:18:54 +00:00
using Jackett.Services;
2015-07-19 00:27:41 +00:00
using Jackett.Utils;
using Jackett.Utils.Clients;
2015-07-11 19:27:57 +00:00
using Newtonsoft.Json.Linq;
2015-07-19 00:27:41 +00:00
using NLog;
2015-07-11 19:27:57 +00:00
using System;
using System.Collections.Generic;
2015-07-12 15:48:37 +00:00
using System.Globalization;
2015-07-11 19:27:57 +00:00
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
2015-07-12 15:48:37 +00:00
using System.Web;
2015-07-11 19:27:57 +00:00
namespace Jackett.Indexers
{
2015-07-19 17:18:54 +00:00
public class HDTorrents : BaseIndexer, IIndexer
2015-07-11 19:27:57 +00:00
{
2015-07-28 19:22:23 +00:00
private string SearchUrl { get { return SiteLink + "torrents.php?search={0}&active=1&options=0&category%5B%5D=59&category%5B%5D=60&category%5B%5D=30&category%5B%5D=38&page=0"; } }
private string LoginUrl { get { return SiteLink + "login.php"; } }
2015-07-12 15:48:37 +00:00
private const int MAXPAGES = 3;
public HDTorrents(IIndexerManagerService i, Logger l, IWebClient w)
: base(name: "HD-Torrents",
description: "HD-Torrents is a private torrent website with HD torrents and strict rules on their content.",
link: "http://hdts.ru/",// Of the accessible domains the .ru seems the most reliable. https://hdts.ru | https://hd-torrents.org | https://hd-torrents.net | https://hd-torrents.me
caps: TorznabCapsUtil.CreateDefaultTorznabTVCaps(),
manager: i,
client: w,
logger: l)
2015-07-11 19:27:57 +00:00
{
}
2015-07-12 15:48:37 +00:00
public Task<ConfigurationData> GetConfigurationForSetup()
2015-07-11 19:27:57 +00:00
{
return Task.FromResult<ConfigurationData>(new ConfigurationDataBasicLogin());
2015-07-11 19:27:57 +00:00
}
public async Task ApplyConfiguration(JToken configJson)
{
var incomingConfig = new ConfigurationDataBasicLogin();
incomingConfig.LoadValuesFromJson(configJson);
2015-07-28 19:22:23 +00:00
var loginPage = await RequestStringWithCookies(LoginUrl, string.Empty);
2015-07-12 15:48:37 +00:00
2015-07-11 19:27:57 +00:00
var pairs = new Dictionary<string, string> {
{ "uid", incomingConfig.Username.Value },
{ "pwd", incomingConfig.Password.Value }
};
2015-07-11 19:27:57 +00:00
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginPage.Cookies, true, null, LoginUrl);
2015-07-11 19:27:57 +00:00
2015-07-28 19:22:23 +00:00
ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("If your browser doesn't have javascript enabled"), () =>
2015-07-11 19:27:57 +00:00
{
2015-07-12 15:48:37 +00:00
var errorMessage = "Couldn't login";
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)incomingConfig);
});
2015-07-11 19:27:57 +00:00
}
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
2015-07-11 19:27:57 +00:00
{
var releases = new List<ReleaseInfo>();
var searchurls = new List<string>();
2015-07-12 15:48:37 +00:00
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
2015-07-28 19:22:23 +00:00
var searchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString.Trim()));
var results = await RequestStringWithCookies(searchUrl);
try
2015-07-12 15:48:37 +00:00
{
2015-07-28 19:22:23 +00:00
CQ dom = results.Content;
ReleaseInfo release;
2015-07-12 15:48:37 +00:00
2015-07-28 19:22:23 +00:00
int rowCount = 0;
var rows = dom[".mainblockcontenttt > tbody > tr"];
foreach (var row in rows)
2015-07-12 15:48:37 +00:00
{
2015-07-28 19:22:23 +00:00
CQ qRow = row.Cq();
if (rowCount < 2 || qRow.Children().Count() != 12) //skip 2 rows because there's an empty row & a title/sort row
2015-07-12 15:48:37 +00:00
{
2015-07-28 19:22:23 +00:00
rowCount++;
continue;
}
2015-07-12 15:48:37 +00:00
2015-07-28 19:22:23 +00:00
release = new ReleaseInfo();
2015-07-12 15:48:37 +00:00
2015-07-28 19:22:23 +00:00
release.Title = qRow.Find("td.mainblockcontent b a").Text();
release.Description = release.Title;
2015-07-12 15:48:37 +00:00
2015-07-28 19:22:23 +00:00
if (0 != qRow.Find("td.mainblockcontent u").Length)
{
var imdbStr = qRow.Find("td.mainblockcontent u").Parent().First().Attr("href").Replace("http://www.imdb.com/title/tt", "").Replace("/", "");
long imdb;
if (ParseUtil.TryCoerceLong(imdbStr, out imdb))
2015-07-12 19:50:24 +00:00
{
2015-07-28 19:22:23 +00:00
release.Imdb = imdb;
2015-07-12 19:50:24 +00:00
}
2015-07-28 19:22:23 +00:00
}
2015-07-12 15:48:37 +00:00
2015-07-28 19:22:23 +00:00
release.MinimumRatio = 1;
release.MinimumSeedTime = 172800;
2015-07-12 15:48:37 +00:00
2015-07-12 15:48:37 +00:00
2015-07-28 19:22:23 +00:00
int seeders, peers;
if (ParseUtil.TryCoerceInt(qRow.Find("td").Get(9).FirstChild.FirstChild.InnerText, out seeders))
{
release.Seeders = seeders;
if (ParseUtil.TryCoerceInt(qRow.Find("td").Get(10).FirstChild.FirstChild.InnerText, out peers))
2015-07-12 19:50:24 +00:00
{
2015-07-28 19:22:23 +00:00
release.Peers = peers + release.Seeders;
2015-07-12 19:50:24 +00:00
}
2015-07-28 19:22:23 +00:00
}
2015-07-12 15:48:37 +00:00
2015-07-28 19:22:23 +00:00
string fullSize = qRow.Find("td.mainblockcontent").Get(6).InnerText;
release.Size = ReleaseInfo.GetBytes(fullSize);
2015-07-12 15:48:37 +00:00
2015-07-28 19:22:23 +00:00
release.Guid = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent b a").Attr("href"));
release.Link = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent").Get(3).FirstChild.GetAttribute("href"));
release.Comments = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent b a").Attr("href") + "#comments");
2015-07-12 15:48:37 +00:00
2015-07-28 19:22:23 +00:00
string[] dateSplit = qRow.Find("td.mainblockcontent").Get(5).InnerHTML.Split(',');
string dateString = dateSplit[1].Substring(0, dateSplit[1].IndexOf('>'));
release.PublishDate = DateTime.Parse(dateString, CultureInfo.InvariantCulture);
2015-07-28 19:22:23 +00:00
releases.Add(release);
2015-07-12 15:48:37 +00:00
}
}
2015-07-28 19:22:23 +00:00
catch (Exception ex)
{
OnParseError(results.Content, ex);
}
2015-07-11 19:27:57 +00:00
return releases.ToArray();
}
}
}