2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2017-10-29 06:21:18 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
2020-02-28 21:40:27 +00:00
|
|
|
using AngleSharp.Dom;
|
|
|
|
using AngleSharp.Html.Parser;
|
2018-03-10 08:05:56 +00:00
|
|
|
using Jackett.Common.Models;
|
|
|
|
using Jackett.Common.Models.IndexerConfig;
|
|
|
|
using Jackett.Common.Services.Interfaces;
|
|
|
|
using Jackett.Common.Utils;
|
|
|
|
using Jackett.Common.Utils.Clients;
|
2017-04-15 08:45:10 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Indexers
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2017-07-10 20:58:44 +00:00
|
|
|
public class DigitalHive : BaseWebIndexer
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
private string SearchUrl => SiteLink + "browse.php";
|
|
|
|
private string LoginUrl => SiteLink + "login.php?returnto=%2F";
|
|
|
|
private string AjaxLoginUrl => SiteLink + "takelogin.php";
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2017-10-29 06:21:18 +00:00
|
|
|
private new ConfigurationDataRecaptchaLogin configData
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
get => (ConfigurationDataRecaptchaLogin)base.configData;
|
|
|
|
set => base.configData = value;
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
public DigitalHive(IIndexerConfigurationService configService, WebClient w, Logger l, IProtectionService ps)
|
2017-04-15 08:45:10 +00:00
|
|
|
: base(name: "DigitalHive",
|
|
|
|
description: "DigitalHive is one of the oldest general trackers",
|
|
|
|
link: "https://www.digitalhive.org/",
|
|
|
|
caps: new TorznabCapabilities(),
|
2017-07-10 20:58:44 +00:00
|
|
|
configService: configService,
|
2017-04-15 08:45:10 +00:00
|
|
|
client: w,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationDataRecaptchaLogin())
|
|
|
|
{
|
|
|
|
Encoding = Encoding.GetEncoding("iso-8859-1");
|
|
|
|
Language = "en-us";
|
|
|
|
Type = "private";
|
|
|
|
|
|
|
|
AddCategoryMapping(0, TorznabCatType.Other);
|
|
|
|
AddCategoryMapping(48, TorznabCatType.Other); // 0Day
|
|
|
|
AddCategoryMapping(56, TorznabCatType.XXXImageset); // 0Day-Imagesets
|
|
|
|
AddCategoryMapping(6, TorznabCatType.Audio); // 0Day-Music
|
|
|
|
AddCategoryMapping(51, TorznabCatType.XXX); // 0Day-XXX
|
|
|
|
AddCategoryMapping(2, TorznabCatType.TVAnime); // Anime
|
|
|
|
AddCategoryMapping(59, TorznabCatType.MoviesBluRay); // BluRay
|
|
|
|
AddCategoryMapping(40, TorznabCatType.TVDocumentary); // Documentary
|
|
|
|
AddCategoryMapping(20, TorznabCatType.MoviesDVD); // DVD-R
|
|
|
|
AddCategoryMapping(25, TorznabCatType.BooksEbook); // Ebooks
|
|
|
|
AddCategoryMapping(38, TorznabCatType.PCPhoneIOS); // HandHeld
|
|
|
|
AddCategoryMapping(38, TorznabCatType.PCPhoneAndroid); // HandHeld
|
|
|
|
AddCategoryMapping(38, TorznabCatType.PCPhoneOther); // HandHeld
|
|
|
|
AddCategoryMapping(37, TorznabCatType.Other); // Kids Stuff
|
|
|
|
AddCategoryMapping(23, TorznabCatType.PC); // Linux
|
|
|
|
AddCategoryMapping(24, TorznabCatType.PCMac); // Mac
|
|
|
|
AddCategoryMapping(22, TorznabCatType.OtherMisc); // Misc
|
|
|
|
AddCategoryMapping(35, TorznabCatType.MoviesOther); // Movie Pack
|
|
|
|
AddCategoryMapping(36, TorznabCatType.MoviesHD); // Movie-HD
|
|
|
|
AddCategoryMapping(19, TorznabCatType.MoviesSD); // Movie-SD
|
|
|
|
AddCategoryMapping(50, TorznabCatType.Audio); // Music
|
|
|
|
AddCategoryMapping(53, TorznabCatType.AudioLossless); // Music-FLAC
|
|
|
|
AddCategoryMapping(49, TorznabCatType.AudioVideo); // MVID
|
|
|
|
AddCategoryMapping(1, TorznabCatType.PC); // PC Apps
|
|
|
|
AddCategoryMapping(4, TorznabCatType.PCGames); // PC Games
|
|
|
|
AddCategoryMapping(17, TorznabCatType.ConsolePS3); // Playstation
|
|
|
|
AddCategoryMapping(17, TorznabCatType.ConsolePS4); // Playstation
|
|
|
|
AddCategoryMapping(17, TorznabCatType.ConsolePSVita); // Playstation
|
|
|
|
AddCategoryMapping(17, TorznabCatType.ConsolePSP); // Playstation
|
|
|
|
AddCategoryMapping(28, TorznabCatType.ConsolePSP); // PSP
|
|
|
|
AddCategoryMapping(34, TorznabCatType.TVOTHER); // TV Pack
|
|
|
|
AddCategoryMapping(32, TorznabCatType.TVHD); // TV-HD
|
|
|
|
AddCategoryMapping(55, TorznabCatType.TVOTHER); // TV-HDRip
|
|
|
|
AddCategoryMapping(7, TorznabCatType.TVSD); // TV-SD
|
|
|
|
AddCategoryMapping(57, TorznabCatType.TVOTHER); // TV-SDRip
|
|
|
|
AddCategoryMapping(33, TorznabCatType.ConsoleWii); // WII
|
|
|
|
AddCategoryMapping(33, TorznabCatType.ConsoleWiiU); // WII
|
|
|
|
AddCategoryMapping(45, TorznabCatType.ConsoleXbox); // XBox
|
|
|
|
AddCategoryMapping(45, TorznabCatType.ConsoleXbox360); // XBox
|
|
|
|
AddCategoryMapping(45, TorznabCatType.ConsoleXBOX360DLC); // XBox
|
|
|
|
AddCategoryMapping(45, TorznabCatType.ConsoleXboxOne); // XBox
|
|
|
|
AddCategoryMapping(9, TorznabCatType.XXX); // XXX
|
|
|
|
AddCategoryMapping(52, TorznabCatType.XXXOther); // XXX-ISO
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<ConfigurationData> GetConfigurationForSetup()
|
|
|
|
{
|
|
|
|
var loginPage = await RequestStringWithCookies(LoginUrl, configData.CookieHeader.Value);
|
2020-02-28 21:40:27 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var cq = parser.ParseDocument(loginPage.Content);
|
2020-03-21 00:17:54 +00:00
|
|
|
var recaptchaSiteKey = cq.QuerySelector(".g-recaptcha")?.GetAttribute("data-sitekey");
|
2017-09-14 13:00:33 +00:00
|
|
|
if (recaptchaSiteKey != null)
|
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var result = configData;
|
2017-09-14 13:00:33 +00:00
|
|
|
result.CookieHeader.Value = loginPage.Cookies;
|
|
|
|
result.Captcha.SiteKey = recaptchaSiteKey;
|
|
|
|
result.Captcha.Version = "2";
|
|
|
|
return result;
|
|
|
|
}
|
2020-03-26 22:15:28 +00:00
|
|
|
|
|
|
|
return new ConfigurationDataBasicLogin
|
2017-09-14 13:00:33 +00:00
|
|
|
{
|
2020-03-26 22:15:28 +00:00
|
|
|
SiteLink = {Value = configData.SiteLink.Value},
|
|
|
|
Instructions = {Value = configData.Instructions.Value},
|
|
|
|
Username = {Value = configData.Username.Value},
|
|
|
|
Password = {Value = configData.Password.Value},
|
|
|
|
CookieHeader = {Value = loginPage.Cookies}
|
|
|
|
};
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 05:31:38 +00:00
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
|
|
|
LoadValuesFromJson(configJson);
|
|
|
|
var pairs = new Dictionary<string, string> {
|
|
|
|
{ "returnto" , "/" },
|
|
|
|
{ "username", configData.Username.Value },
|
|
|
|
{ "password", configData.Password.Value },
|
|
|
|
{ "g-recaptcha-response", configData.Captcha.Value }
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(configData.Captcha.Cookie))
|
|
|
|
{
|
|
|
|
// Cookie was manually supplied
|
|
|
|
CookieHeader = configData.Captcha.Cookie;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var results = await PerformQuery(new TorznabQuery());
|
|
|
|
if (!results.Any())
|
|
|
|
{
|
|
|
|
throw new Exception("Your cookie did not work");
|
|
|
|
}
|
|
|
|
|
|
|
|
IsConfigured = true;
|
2017-05-06 17:39:02 +00:00
|
|
|
SaveConfig();
|
2017-04-15 08:45:10 +00:00
|
|
|
return IndexerConfigurationStatus.Completed;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
IsConfigured = false;
|
|
|
|
throw new Exception("Your cookie did not work: " + e.Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var result = await RequestLoginAndFollowRedirect(AjaxLoginUrl, pairs, configData.CookieHeader.Value, true, SiteLink, LoginUrl);
|
|
|
|
|
|
|
|
await ConfigureIfOK(result.Cookies, result.Content.Contains("logout.php"), () =>
|
|
|
|
{
|
2020-02-28 21:40:27 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var errorMessage = parser.ParseDocument(result.Content);
|
2017-11-06 14:13:02 +00:00
|
|
|
throw new ExceptionWithConfigData(errorMessage.Text(), configData);
|
2017-04-15 08:45:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return IndexerConfigurationStatus.RequiresTesting;
|
|
|
|
}
|
|
|
|
|
2017-07-03 05:15:47 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var releases = new List<ReleaseInfo>();
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
var queryCollection = new NameValueCollection();
|
|
|
|
var searchString = query.GetQueryString();
|
|
|
|
var searchUrl = SearchUrl;
|
|
|
|
|
|
|
|
foreach (var cat in MapTorznabCapsToTrackers(query))
|
|
|
|
{
|
|
|
|
queryCollection.Add("c" + cat, "1");
|
|
|
|
}
|
2017-10-29 06:21:18 +00:00
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(searchString))
|
|
|
|
{
|
|
|
|
queryCollection.Add("search", searchString);
|
|
|
|
}
|
|
|
|
|
|
|
|
queryCollection.Add("blah", "0");
|
|
|
|
|
|
|
|
var results = await RequestStringWithCookiesAndRetry(searchUrl + "?" + queryCollection.GetQueryString());
|
|
|
|
if (results.IsRedirect)
|
|
|
|
{
|
|
|
|
// re-login
|
|
|
|
await ApplyConfiguration(null);
|
|
|
|
results = await RequestStringWithCookiesAndRetry(searchUrl + "?" + queryCollection.GetQueryString());
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
releases.AddRange(contentToReleaseInfos(query, results.Content));
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
OnParseError(results.Content, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
|
2020-02-28 21:40:27 +00:00
|
|
|
private IEnumerable<ReleaseInfo> contentToReleaseInfos(TorznabQuery query, string content)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-02-28 21:40:27 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var dom = parser.ParseDocument(content);
|
2020-02-10 22:16:19 +00:00
|
|
|
var releases = new List<ReleaseInfo>();
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
// Doesn't handle pagination yet...
|
2020-02-28 21:40:27 +00:00
|
|
|
var rows = dom.QuerySelectorAll("div.panel-body > table.table > tbody > tr");
|
2017-04-15 08:45:10 +00:00
|
|
|
foreach (var row in rows)
|
|
|
|
{
|
|
|
|
var release = new ReleaseInfo();
|
|
|
|
release.MinimumRatio = 1;
|
|
|
|
release.MinimumSeedTime = 259200;
|
|
|
|
|
2020-02-28 21:40:27 +00:00
|
|
|
|
|
|
|
release.Title = row.QuerySelector("td:nth-child(2) > a").TextContent.Trim();
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2019-05-11 03:27:25 +00:00
|
|
|
if ((query.ImdbID == null || !TorznabCaps.SupportsImdbMovieSearch) && !query.MatchQueryStringAND(release.Title))
|
2017-04-15 08:45:10 +00:00
|
|
|
continue;
|
|
|
|
|
2020-02-28 21:40:27 +00:00
|
|
|
release.Guid = new Uri(SiteLink + row.QuerySelector("td:nth-child(2) > a").GetAttribute("href"));
|
2017-04-15 08:45:10 +00:00
|
|
|
release.Comments = release.Guid;
|
2020-02-28 21:40:27 +00:00
|
|
|
release.Link = new Uri(SiteLink + row.QuerySelector("td:nth-child(3) > a").GetAttribute("href"));
|
|
|
|
var pubDateElement = row.QuerySelector("td:nth-child(2) > span");
|
|
|
|
// remove snatchinfo links (added after completing a torrent)
|
|
|
|
foreach (var element in pubDateElement.QuerySelectorAll("a"))
|
|
|
|
element.Remove();
|
|
|
|
var pubDate = pubDateElement.TextContent.Trim().Replace("Added: ", "");
|
2017-04-15 08:45:10 +00:00
|
|
|
release.PublishDate = DateTime.Parse(pubDate).ToLocalTime();
|
2020-02-28 21:40:27 +00:00
|
|
|
release.Category = MapTrackerCatToNewznab(row.QuerySelector("td:nth-child(1) > a").GetAttribute("href").Split('=')[1]);
|
|
|
|
release.Size = ReleaseInfo.GetBytes(row.QuerySelector("td:nth-child(7)").TextContent);
|
|
|
|
release.Seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(9)").TextContent);
|
|
|
|
release.Peers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(10)").TextContent) + release.Seeders;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-02-28 21:40:27 +00:00
|
|
|
var files = row.QuerySelector("td:nth-child(5)").TextContent;
|
2017-04-15 08:45:10 +00:00
|
|
|
release.Files = ParseUtil.CoerceInt(files);
|
|
|
|
|
2020-02-28 21:40:27 +00:00
|
|
|
var grabs = row.QuerySelector("td:nth-child(8)").TextContent;
|
2017-04-15 08:45:10 +00:00
|
|
|
release.Grabs = ParseUtil.CoerceInt(grabs);
|
|
|
|
|
2020-02-28 21:40:27 +00:00
|
|
|
if (row.QuerySelector("i.fa-star") != null)
|
2017-04-15 08:45:10 +00:00
|
|
|
release.DownloadVolumeFactor = 0;
|
|
|
|
else
|
|
|
|
release.DownloadVolumeFactor = 1;
|
|
|
|
|
|
|
|
release.UploadVolumeFactor = 1;
|
|
|
|
|
|
|
|
releases.Add(release);
|
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
}
|