Jackett/src/Jackett.Common/Indexers/BitHDTV.cs

189 lines
8.6 KiB
C#
Raw Normal View History

2020-02-09 02:35:16 +00:00
using System;
2015-04-19 21:56:20 +00:00
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
2015-04-19 21:56:20 +00:00
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
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;
2015-04-19 21:56:20 +00:00
namespace Jackett.Common.Indexers
2015-04-19 21:56:20 +00:00
{
[ExcludeFromCodeCoverage]
public class BitHDTV : BaseWebIndexer
2015-05-04 04:12:14 +00:00
{
private string SearchUrl => SiteLink + "torrents.php";
2015-05-04 04:12:14 +00:00
private new ConfigurationDataCookie configData => (ConfigurationDataCookie)base.configData;
public BitHDTV(IIndexerConfigurationService configService, WebClient w, Logger l, IProtectionService ps,
ICacheService cs)
: base(id: "bithdtv",
name: "BIT-HDTV",
description: "BIT-HDTV - Home of High Definition",
link: "https://www.bit-hdtv.com/",
caps: new TorznabCapabilities
{
TvSearchParams = new List<TvSearchParam>
{
TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep, TvSearchParam.ImdbId
},
MovieSearchParams = new List<MovieSearchParam>
{
MovieSearchParam.Q, MovieSearchParam.ImdbId
}
},
configService: configService,
client: w,
logger: l,
p: ps,
cacheService: cs,
configData: new ConfigurationDataCookie("For best results, change the 'Torrents per page' setting to 100 in your profile."))
2015-05-04 04:12:14 +00:00
{
2016-12-09 17:20:58 +00:00
Encoding = Encoding.GetEncoding("iso-8859-1");
Language = "en-US";
Type = "private";
AddCategoryMapping(1, TorznabCatType.TVAnime, "Anime");
AddCategoryMapping(2, TorznabCatType.MoviesBluRay, "Movies/Blu-ray");
AddCategoryMapping(4, TorznabCatType.TVDocumentary, "Documentaries");
AddCategoryMapping(6, TorznabCatType.AudioLossless, "HQ Audio");
AddCategoryMapping(7, TorznabCatType.Movies, "Movies");
AddCategoryMapping(8, TorznabCatType.AudioVideo, "Music Videos");
AddCategoryMapping(9, TorznabCatType.Other, "Other");
AddCategoryMapping(5, TorznabCatType.TVSport, "Sports");
AddCategoryMapping(10, TorznabCatType.TV, "TV");
AddCategoryMapping(12, TorznabCatType.TV, "TV/Seasonpack");
AddCategoryMapping(11, TorznabCatType.XXX, "XXX");
2015-05-04 04:12:14 +00:00
}
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
2015-05-04 04:12:14 +00:00
{
LoadValuesFromJson(configJson);
CookieHeader = configData.Cookie.Value;
try
2017-06-03 14:46:27 +00:00
{
var results = await PerformQuery(new TorznabQuery());
if (!results.Any())
throw new Exception("Found 0 results in the tracker");
2017-06-03 14:46:27 +00:00
IsConfigured = true;
SaveConfig();
return IndexerConfigurationStatus.Completed;
}
catch (Exception e)
2015-05-04 04:12:14 +00:00
{
IsConfigured = false;
throw new Exception("Your cookie did not work: " + e.Message);
}
2015-05-04 04:12:14 +00:00
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
2015-05-04 04:12:14 +00:00
{
var releases = new List<ReleaseInfo>();
var qc = new NameValueCollection
{
{"cat", MapTorznabCapsToTrackers(query, true).FirstIfSingleOrDefault("0")}
};
var results = new List<WebResult>();
var search = new UriBuilder(SearchUrl);
if (query.IsImdbQuery)
2015-08-22 22:06:07 +00:00
{
2020-03-08 13:12:08 +00:00
qc.Add("search", query.ImdbID);
qc.Add("options", "4"); //Search URL field for IMDB link
search.Query = qc.GetQueryString();
results.Add(await RequestWithCookiesAndRetryAsync(search.ToString()));
qc["Options"] = "1"; //Search Title and Description
search.Query = qc.GetQueryString();
results.Add(await RequestWithCookiesAndRetryAsync(search.ToString()));
2015-08-22 22:06:07 +00:00
}
else
2020-03-08 13:12:08 +00:00
{
//Site handles empty string on search param. No need to check for IsNullOrEmpty()
2020-03-08 13:12:08 +00:00
qc.Add("search", query.GetQueryString());
qc.Add("options", "0"); //Search Title Only
search.Query = qc.GetQueryString();
results.Add(await RequestWithCookiesAndRetryAsync(search.ToString()));
2020-03-08 13:12:08 +00:00
}
2015-08-22 22:06:07 +00:00
var parser = new HtmlParser();
foreach (var result in results)
try
2015-05-04 04:12:14 +00:00
{
var dom = parser.ParseDocument(result.ContentString);
foreach (var child in dom.QuerySelectorAll("#needseed"))
child.Remove();
var table = dom.QuerySelector("table[align=center] + br + table > tbody");
if (table == null) // No results, so skip this search
continue;
foreach (var row in table.Children.Skip(1))
{
var release = new ReleaseInfo();
var qLink = row.Children[2].QuerySelector("a");
release.MinimumRatio = 1;
release.MinimumSeedTime = 172800; // 48 hours
release.Title = qLink.GetAttribute("title");
var detailsLink = new Uri(qLink.GetAttribute("href"));
//Skip irrelevant and duplicate entries
if (!query.MatchQueryStringAND(release.Title) || releases.Any(r => r.Guid == detailsLink))
continue;
release.Files = ParseUtil.CoerceLong(row.Children[3].TextContent);
release.Grabs = ParseUtil.CoerceLong(row.Children[7].TextContent);
release.Guid = detailsLink;
release.Details = release.Guid;
release.Link = new Uri(SiteLink + row.QuerySelector("a[href^=\"download.php\"]").GetAttribute("href"));
var catUrl = new Uri(SiteLink + row.Children[1].FirstElementChild.GetAttribute("href"));
var catQuery = HttpUtility.ParseQueryString(catUrl.Query);
var catNum = catQuery["cat"];
release.Category = MapTrackerCatToNewznab(catNum);
var dateString = row.Children[5].TextContent.Trim();
2017-06-08 08:34:53 +00:00
var pubDate = DateTime.ParseExact(dateString, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture);
release.PublishDate = DateTime.SpecifyKind(pubDate, DateTimeKind.Local);
var sizeStr = row.Children[6].TextContent;
release.Size = ReleaseInfo.GetBytes(sizeStr);
release.Seeders = ParseUtil.CoerceInt(row.Children[8].TextContent.Trim());
release.Peers = ParseUtil.CoerceInt(row.Children[9].TextContent.Trim()) + release.Seeders;
switch (row.GetAttribute("bgcolor"))
{
case "#DDDDDD":
release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 2;
break;
case "#FFFF99":
release.DownloadVolumeFactor = 0;
release.UploadVolumeFactor = 1;
break;
case "#CCFF99":
release.DownloadVolumeFactor = 0;
release.UploadVolumeFactor = 2;
break;
default:
release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 1;
break;
}
releases.Add(release);
}
2015-05-04 04:12:14 +00:00
}
catch (Exception ex)
{
OnParseError(result.ContentString, ex);
}
2015-05-04 04:12:14 +00:00
return releases;
2015-05-04 04:12:14 +00:00
}
}
2015-04-19 21:56:20 +00:00
}