Jackett/src/Jackett.Common/Indexers/HDSpace.cs

189 lines
8.6 KiB
C#
Raw Normal View History

2020-02-09 02:35:16 +00:00
using System;
2015-07-26 03:48:18 +00:00
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
2015-07-26 03:48:18 +00:00
using System.Text;
using System.Text.RegularExpressions;
2015-07-26 03:48:18 +00:00
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig;
using Jackett.Common.Services.Interfaces;
using Jackett.Common.Utils;
using Jackett.Common.Utils.Clients;
using Newtonsoft.Json.Linq;
using NLog;
namespace Jackett.Common.Indexers
2015-07-26 03:48:18 +00:00
{
[ExcludeFromCodeCoverage]
public class HDSpace : BaseWebIndexer
2015-07-26 03:48:18 +00:00
{
private string LoginUrl => SiteLink + "index.php?page=login";
private string SearchUrl => SiteLink + "index.php?page=torrents&";
2015-07-26 03:48:18 +00:00
private new ConfigurationDataBasicLogin configData => (ConfigurationDataBasicLogin)base.configData;
public HDSpace(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
: base(id: "hdspace",
name: "HD-Space",
description: "Sharing The Universe",
link: "https://hd-space.org/",
caps: new TorznabCapabilities
{
SupportsImdbMovieSearch = true
//SupportsImdbTVSearch = true; (supported by the site but disabled due to #8107)
},
configService: configService,
client: wc,
logger: l,
p: ps,
configData: new ConfigurationDataBasicLogin())
2015-07-26 03:48:18 +00:00
{
Encoding = Encoding.UTF8;
2016-12-09 17:20:58 +00:00
Language = "en-us";
Type = "private";
AddCategoryMapping(15, TorznabCatType.MoviesBluRay); // Movie / Blu-ray
AddMultiCategoryMapping(TorznabCatType.MoviesHD,
19, // Movie / 1080p
18, // Movie / 720p
40, // Movie / Remux
16 // Movie / HD-DVD
);
AddMultiCategoryMapping(TorznabCatType.TVHD,
21, // TV Show / 720p HDTV
22 // TV Show / 1080p HDTV
);
AddMultiCategoryMapping(TorznabCatType.TVDocumentary,
24, // Documentary / 720p
25 // Documentary / 1080p
);
AddMultiCategoryMapping(TorznabCatType.TVAnime,
27, // Animation / 720p
28 // Animation / 1080p
);
AddCategoryMapping(30, TorznabCatType.AudioLossless); // Music / HQ Audio
AddCategoryMapping(31, TorznabCatType.AudioVideo); // Music / Videos
AddMultiCategoryMapping(TorznabCatType.XXX,
33, // XXX / 720p
34 // XXX / 1080p
);
AddCategoryMapping(36, TorznabCatType.MoviesOther); // Trailers
AddCategoryMapping(37, TorznabCatType.PC); // Software
AddCategoryMapping(38, TorznabCatType.Other); // Others
AddCategoryMapping(41, TorznabCatType.MoviesUHD); // Movie / 4K UHD
}
2015-07-26 03:48:18 +00:00
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
2015-07-26 03:48:18 +00:00
{
LoadValuesFromJson(configJson);
var loginPage = await RequestWithCookiesAsync(LoginUrl, string.Empty);
var pairs = new Dictionary<string, string>
{
{"uid", configData.Username.Value},
{"pwd", configData.Password.Value}
2015-07-26 03:48:18 +00:00
};
// Send Post
var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginPage.Cookies, true, referer: LoginUrl);
2015-07-26 03:48:18 +00:00
await ConfigureIfOK(response.Cookies, response.ContentString?.Contains("logout.php") == true, () =>
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.ContentString).Groups[1].ToString();
var attempts = Regex.Replace(remainingAttemptSpan, "<.*?>", string.Empty);
2015-07-26 03:48:18 +00:00
var errorMessage = string.Format(errorStr, attempts);
throw new ExceptionWithConfigData(errorMessage, configData);
2015-07-26 03:48:18 +00:00
});
return IndexerConfigurationStatus.RequiresTesting;
2015-07-26 03:48:18 +00:00
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
2015-07-26 03:48:18 +00:00
{
var releases = new List<ReleaseInfo>();
var queryCollection = new NameValueCollection
{
{"active", "0"},
{"category", string.Join(";", MapTorznabCapsToTrackers(query))}
};
if (query.IsImdbQuery)
{
queryCollection.Add("options", "2");
queryCollection.Add("search", query.ImdbIDShort);
}
else
{
queryCollection.Add("options", "0");
queryCollection.Add("search", query.GetQueryString());
}
var response = await RequestWithCookiesAndRetryAsync(SearchUrl + queryCollection.GetQueryString());
2015-07-26 03:48:18 +00:00
try
{
var resultParser = new HtmlParser();
var searchResultDocument = resultParser.ParseDocument(response.ContentString);
var rows = searchResultDocument.QuerySelectorAll("table.lista > tbody > tr");
2015-07-26 03:48:18 +00:00
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 || !string.Equals(prev.NodeName, "style", StringComparison.OrdinalIgnoreCase))
2020-02-09 02:35:16 +00:00
continue;
2015-07-26 03:48:18 +00:00
var release = new ReleaseInfo();
release.MinimumRatio = 1;
release.MinimumSeedTime = 172800; // 48 hours
2015-07-26 03:48:18 +00:00
var qLink = row.Children[1].FirstElementChild;
release.Title = qLink.TextContent.Trim();
release.Comments = new Uri(SiteLink + qLink.GetAttribute("href"));
2015-07-26 03:48:18 +00:00
release.Guid = release.Comments;
var imdbLink = row.Children[1].QuerySelector("a[href*=imdb]");
if (imdbLink != null)
release.Imdb = ParseUtil.GetImdbID(imdbLink.GetAttribute("href").Split('/').Last());
var qDownload = row.Children[3].FirstElementChild;
release.Link = new Uri(SiteLink + qDownload.GetAttribute("href"));
2015-07-26 03:48:18 +00:00
var dateStr = row.Children[4].TextContent.Trim();
//"July 11, 2015, 13:34:09", "Today|Yesterday at 20:04:23"
release.PublishDate = DateTimeUtil.FromUnknown(dateStr);
var sizeStr = row.Children[5].TextContent;
2015-07-26 03:48:18 +00:00
release.Size = ReleaseInfo.GetBytes(sizeStr);
release.Seeders = ParseUtil.CoerceInt(row.Children[7].TextContent);
release.Peers = ParseUtil.CoerceInt(row.Children[8].TextContent) + release.Seeders;
var grabs = row.QuerySelector("td:nth-child(10)").TextContent;
grabs = grabs.Replace("---", "0");
release.Grabs = ParseUtil.CoerceInt(grabs);
if (row.QuerySelector("img[title=\"FreeLeech\"]") != null)
release.DownloadVolumeFactor = 0;
else if (row.QuerySelector("img[src=\"images/sf.png\"]") != null) // side freeleech
release.DownloadVolumeFactor = 0;
else if (row.QuerySelector("img[title=\"Half FreeLeech\"]") != null)
release.DownloadVolumeFactor = 0.5;
else
release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 1;
var qCat = row.QuerySelector("a[href^=\"index.php?page=torrents&category=\"]");
var cat = qCat.GetAttribute("href").Split('=')[2];
release.Category = MapTrackerCatToNewznab(cat);
2015-07-26 03:48:18 +00:00
releases.Add(release);
}
}
catch (Exception ex)
{
OnParseError(response.ContentString, ex);
2015-07-26 03:48:18 +00:00
}
return releases;
2015-07-26 03:48:18 +00:00
}
}
}