2015-04-19 21:56:20 +00:00
|
|
|
|
using CsQuery;
|
2015-07-19 00:27:41 +00:00
|
|
|
|
using Jackett.Models;
|
|
|
|
|
using Jackett.Utils;
|
2015-04-19 21:56:20 +00:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2015-07-19 00:27:41 +00:00
|
|
|
|
using NLog;
|
2015-04-19 21:56:20 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
|
|
|
|
namespace Jackett.Indexers
|
|
|
|
|
{
|
2015-07-19 13:22:50 +00:00
|
|
|
|
public class BitHdtv : IIndexer
|
2015-05-04 04:12:14 +00:00
|
|
|
|
{
|
2015-07-19 13:22:50 +00:00
|
|
|
|
public event Action<IIndexer, string, Exception> OnResultParsingError;
|
2015-05-04 04:12:14 +00:00
|
|
|
|
|
|
|
|
|
public string DisplayName
|
|
|
|
|
{
|
|
|
|
|
get { return "BIT-HDTV"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string DisplayDescription
|
|
|
|
|
{
|
|
|
|
|
get { return "Home of high definition invites"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Uri SiteLink
|
|
|
|
|
{
|
|
|
|
|
get { return new Uri(BaseUrl); }
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 20:35:02 +00:00
|
|
|
|
public bool RequiresRageIDLookupDisabled { get { return true; } }
|
|
|
|
|
|
2015-05-04 04:12:14 +00:00
|
|
|
|
static string BaseUrl = "https://www.bit-hdtv.com";
|
|
|
|
|
static string LoginUrl = BaseUrl + "/takelogin.php";
|
|
|
|
|
static string SearchUrl = BaseUrl + "/torrents.php?cat=0&search=";
|
|
|
|
|
static string DownloadUrl = BaseUrl + "/download.php?/{0}/dl.torrent";
|
|
|
|
|
|
|
|
|
|
CookieContainer cookies;
|
|
|
|
|
HttpClientHandler handler;
|
|
|
|
|
HttpClient client;
|
2015-07-19 00:27:41 +00:00
|
|
|
|
Logger loggger;
|
2015-05-04 04:12:14 +00:00
|
|
|
|
|
2015-07-19 00:27:41 +00:00
|
|
|
|
public BitHdtv(Logger l)
|
2015-05-04 04:12:14 +00:00
|
|
|
|
{
|
2015-07-19 00:27:41 +00:00
|
|
|
|
loggger = l;
|
2015-05-04 04:12:14 +00:00
|
|
|
|
IsConfigured = false;
|
|
|
|
|
cookies = new CookieContainer();
|
|
|
|
|
handler = new HttpClientHandler
|
|
|
|
|
{
|
|
|
|
|
CookieContainer = cookies,
|
|
|
|
|
AllowAutoRedirect = true,
|
|
|
|
|
UseCookies = true,
|
|
|
|
|
};
|
|
|
|
|
client = new HttpClient(handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ConfigurationData> GetConfigurationForSetup()
|
|
|
|
|
{
|
|
|
|
|
var config = new ConfigurationDataBasicLogin();
|
|
|
|
|
return Task.FromResult<ConfigurationData>(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ApplyConfiguration(JToken configJson)
|
|
|
|
|
{
|
|
|
|
|
var config = new ConfigurationDataBasicLogin();
|
|
|
|
|
config.LoadValuesFromJson(configJson);
|
|
|
|
|
|
|
|
|
|
var pairs = new Dictionary<string, string> {
|
2015-04-23 06:44:21 +00:00
|
|
|
|
{ "username", config.Username.Value },
|
|
|
|
|
{ "password", config.Password.Value }
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-04 04:12:14 +00:00
|
|
|
|
var content = new FormUrlEncodedContent(pairs);
|
|
|
|
|
|
|
|
|
|
var response = await client.PostAsync(LoginUrl, content);
|
|
|
|
|
var responseContent = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
if (!responseContent.Contains("logout.php"))
|
|
|
|
|
{
|
|
|
|
|
CQ dom = responseContent;
|
|
|
|
|
var messageEl = dom["table.detail td.text"].Last();
|
|
|
|
|
messageEl.Children("a").Remove();
|
|
|
|
|
messageEl.Children("style").Remove();
|
|
|
|
|
var errorMessage = messageEl.Text().Trim();
|
|
|
|
|
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var configSaveData = new JObject();
|
2015-07-11 18:54:15 +00:00
|
|
|
|
cookies.DumpToJson(SiteLink, configSaveData);
|
2015-05-04 04:12:14 +00:00
|
|
|
|
|
|
|
|
|
if (OnSaveConfigurationRequested != null)
|
|
|
|
|
OnSaveConfigurationRequested(this, configSaveData);
|
|
|
|
|
|
|
|
|
|
IsConfigured = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 13:22:50 +00:00
|
|
|
|
public event Action<IIndexer, JToken> OnSaveConfigurationRequested;
|
2015-05-04 04:12:14 +00:00
|
|
|
|
|
|
|
|
|
public bool IsConfigured { get; private set; }
|
|
|
|
|
|
|
|
|
|
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
|
|
|
|
{
|
2015-07-19 00:27:41 +00:00
|
|
|
|
cookies.FillFromJson(new Uri(BaseUrl), jsonConfig, loggger);
|
2015-05-04 04:12:14 +00:00
|
|
|
|
IsConfigured = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
|
|
|
|
{
|
|
|
|
|
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
|
|
|
|
|
2015-07-18 20:35:02 +00:00
|
|
|
|
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
|
|
|
|
|
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
|
|
|
|
|
var results = await client.GetStringAsync(episodeSearchUrl);
|
|
|
|
|
try
|
2015-05-04 04:12:14 +00:00
|
|
|
|
{
|
2015-07-18 20:35:02 +00:00
|
|
|
|
CQ dom = results;
|
|
|
|
|
dom["#needseed"].Remove();
|
|
|
|
|
var rows = dom["table[width='750'] > tbody"].Children();
|
|
|
|
|
foreach (var row in rows.Skip(1))
|
2015-05-04 04:12:14 +00:00
|
|
|
|
{
|
2015-07-18 20:35:02 +00:00
|
|
|
|
|
|
|
|
|
var release = new ReleaseInfo();
|
|
|
|
|
|
|
|
|
|
var qRow = row.Cq();
|
|
|
|
|
var qLink = qRow.Children().ElementAt(2).Cq().Children("a").First();
|
|
|
|
|
|
|
|
|
|
release.MinimumRatio = 1;
|
|
|
|
|
release.MinimumSeedTime = 172800;
|
|
|
|
|
release.Title = qLink.Attr("title");
|
|
|
|
|
release.Description = release.Title;
|
|
|
|
|
release.Guid = new Uri(BaseUrl + qLink.Attr("href"));
|
|
|
|
|
release.Comments = release.Guid;
|
|
|
|
|
release.Link = new Uri(string.Format(DownloadUrl, qLink.Attr("href").Split('=')[1]));
|
|
|
|
|
|
|
|
|
|
var dateString = qRow.Children().ElementAt(5).Cq().Text().Trim();
|
|
|
|
|
var pubDate = DateTime.ParseExact(dateString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
|
|
|
|
|
release.PublishDate = DateTime.SpecifyKind(pubDate, DateTimeKind.Local);
|
|
|
|
|
|
|
|
|
|
var sizeCol = qRow.Children().ElementAt(6);
|
|
|
|
|
var sizeVal = sizeCol.ChildNodes[0].NodeValue;
|
|
|
|
|
var sizeUnit = sizeCol.ChildNodes[2].NodeValue;
|
|
|
|
|
release.Size = ReleaseInfo.GetBytes(sizeUnit, ParseUtil.CoerceFloat(sizeVal));
|
|
|
|
|
|
|
|
|
|
release.Seeders = ParseUtil.CoerceInt(qRow.Children().ElementAt(8).Cq().Text().Trim());
|
|
|
|
|
release.Peers = ParseUtil.CoerceInt(qRow.Children().ElementAt(9).Cq().Text().Trim()) + release.Seeders;
|
|
|
|
|
|
|
|
|
|
releases.Add(release);
|
2015-05-04 04:12:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-18 20:35:02 +00:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
OnResultParsingError(this, results, ex);
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
2015-05-04 04:12:14 +00:00
|
|
|
|
|
|
|
|
|
return releases.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<byte[]> Download(Uri link)
|
|
|
|
|
{
|
|
|
|
|
return client.GetByteArrayAsync(link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2015-04-19 21:56:20 +00:00
|
|
|
|
}
|