Jackett/src/Jackett/Indexers/HDSpace.cs

125 lines
5.3 KiB
C#
Raw Normal View History

2015-07-26 03:48:18 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Jackett.Models;
using Newtonsoft.Json.Linq;
using Jackett.Utils.Clients;
using Jackett.Services;
using NLog;
using Jackett.Utils;
using CsQuery;
using System.Web;
using System.Text.RegularExpressions;
using System.Globalization;
using Jackett.Models.IndexerConfig;
2015-07-26 03:48:18 +00:00
namespace Jackett.Indexers
{
public class HDSpace : BaseIndexer, IIndexer
{
private string LoginUrl { get { return SiteLink + "index.php?page=login"; } }
private string SearchUrl { get { return SiteLink + "index.php?page=torrents&active=0&options=0&category=21%3B22&search={0}"; } }
2015-07-26 03:48:18 +00:00
new ConfigurationDataBasicLogin configData
{
get { return (ConfigurationDataBasicLogin)base.configData; }
set { base.configData = value; }
}
2015-08-07 19:09:13 +00:00
public HDSpace(IIndexerManagerService i, IWebClient wc, Logger l, IProtectionService ps)
2015-07-26 03:48:18 +00:00
: base(name: "HD-Space",
description: "Sharing The Universe",
link: "https://hd-space.org/",
2015-08-11 18:48:25 +00:00
caps: TorznabUtil.CreateDefaultTorznabTVCaps(),
2015-07-26 03:48:18 +00:00
manager: i,
client: wc,
logger: l,
2015-08-07 19:09:13 +00:00
p: ps,
configData: new ConfigurationDataBasicLogin())
2015-07-26 03:48:18 +00:00
{
}
public async Task ApplyConfiguration(JToken configJson)
{
configData.LoadValuesFromJson(configJson);
2015-07-26 03:48:18 +00:00
2015-07-28 19:22:23 +00:00
var loginPage = await RequestStringWithCookies(LoginUrl, string.Empty);
2015-07-26 03:48:18 +00:00
var pairs = new Dictionary<string, string> {
{ "uid", configData.Username.Value },
{ "pwd", configData.Password.Value }
2015-07-26 03:48:18 +00:00
};
// Send Post
2015-07-28 19:22:23 +00:00
var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginPage.Cookies, true, null, LoginUrl);
2015-07-26 03:48:18 +00:00
await ConfigureIfOK(response.Cookies, response.Content != null && response.Content.Contains("logout.php"), () =>
2015-07-26 03:48:18 +00:00
{
var errorStr = "You have {0} remaining login attempts";
var remainingAttemptSpan = new Regex(string.Format(errorStr, "(.*?)")).Match(loginPage.Content).Groups[1].ToString();
var attempts = Regex.Replace(remainingAttemptSpan, "<.*?>", String.Empty);
var errorMessage = string.Format(errorStr, attempts);
throw new ExceptionWithConfigData(errorMessage, configData);
2015-07-26 03:48:18 +00:00
});
}
public async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
2015-07-26 03:48:18 +00:00
{
var releases = new List<ReleaseInfo>();
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(query.GetQueryString()));
var response = await RequestStringWithCookiesAndRetry(episodeSearchUrl);
2015-07-26 03:48:18 +00:00
var results = response.Content;
try
{
CQ dom = results;
var rows = dom["table.lista > tbody > tr"];
foreach (var row in rows)
{
// this tracker has horrible markup, find the result rows by looking for the style tag before each one
var prev = row.PreviousElementSibling;
if (prev == null || prev.NodeName.ToLowerInvariant() != "style") continue;
CQ qRow = row.Cq();
var release = new ReleaseInfo();
release.MinimumRatio = 1;
release.MinimumSeedTime = 172800;
var qLink = row.ChildElements.ElementAt(1).FirstElementChild.Cq();
release.Title = qLink.Text().Trim();
release.Comments = new Uri(SiteLink + qLink.Attr("href"));
release.Guid = release.Comments;
var qDownload = row.ChildElements.ElementAt(3).FirstElementChild.Cq();
release.Link = new Uri(SiteLink + qDownload.Attr("href"));
//"July 11, 2015, 13:34:09", "Today at 20:04:23"
var dateStr = row.ChildElements.ElementAt(4).Cq().Text().Trim();
if (dateStr.StartsWith("Today"))
release.PublishDate = DateTime.Today + TimeSpan.ParseExact(dateStr.Replace("Today at ", ""), "hh\\:mm\\:ss", CultureInfo.InvariantCulture);
else if (dateStr.StartsWith("Yesterday"))
release.PublishDate = DateTime.Today - TimeSpan.FromDays(1) + TimeSpan.ParseExact(dateStr.Replace("Yesterday at ", ""), "hh\\:mm\\:ss", CultureInfo.InvariantCulture);
else
release.PublishDate = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "MMMM dd, yyyy, HH:mm:ss", CultureInfo.InvariantCulture), DateTimeKind.Local);
var sizeStr = row.ChildElements.ElementAt(5).Cq().Text();
release.Size = ReleaseInfo.GetBytes(sizeStr);
release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(7).Cq().Text());
release.Peers = ParseUtil.CoerceInt(row.ChildElements.ElementAt(8).Cq().Text()) + release.Seeders;
releases.Add(release);
}
}
catch (Exception ex)
{
OnParseError(results, ex);
}
return releases;
2015-07-26 03:48:18 +00:00
}
}
}