Jackett/src/Jackett.Common/Indexers/BB.cs

205 lines
9.0 KiB
C#
Raw Normal View History

2020-02-09 02:35:16 +00:00
using System;
2015-07-19 20:21:31 +00:00
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
2015-07-19 20:21:31 +00:00
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
2015-07-19 20:21:31 +00:00
using System.Threading.Tasks;
2020-02-28 22:32:43 +00:00
using AngleSharp.Dom;
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-19 20:21:31 +00:00
{
// To comply with the rules for this tracker, only the acronym is used and no publicly displayed URLs to the site.
[ExcludeFromCodeCoverage]
public class BB : BaseWebIndexer
2015-07-19 20:21:31 +00:00
{
private string BaseUrl => StringUtil.FromBase64("aHR0cHM6Ly9iYWNvbmJpdHMub3JnLw==");
private Uri BaseUri => new Uri(BaseUrl);
private string LoginUrl => BaseUri + "login.php";
private string SearchUrl => BaseUri + "torrents.php?searchtags=&tags_type=0&order_by=s3&order_way=desc&disablegrouping=1&";
2015-07-19 20:21:31 +00:00
private new ConfigurationDataBasicLogin configData
{
get => (ConfigurationDataBasicLogin)base.configData;
set => base.configData = value;
}
public BB(IIndexerConfigurationService configService, WebClient w, Logger l, IProtectionService ps)
: base(id: "bb",
name: "bB",
description: "BaconBits (bB) is a Private Torrent Tracker for 0DAY / GENERAL",
link: StringUtil.FromBase64("aHR0cHM6Ly9iYWNvbmJpdHMub3JnLw=="),
caps: new TorznabCapabilities(),
configService: configService,
client: w,
logger: l,
p: ps,
configData: new ConfigurationDataBasicLogin())
2015-07-19 20:21:31 +00:00
{
Encoding = Encoding.UTF8;
2016-12-09 17:20:58 +00:00
Language = "en-us";
Type = "private";
2015-08-11 01:36:42 +00:00
AddCategoryMapping(1, TorznabCatType.Audio);
AddCategoryMapping(1, TorznabCatType.AudioMP3);
AddCategoryMapping(1, TorznabCatType.AudioLossless);
2015-08-11 01:36:42 +00:00
AddCategoryMapping(2, TorznabCatType.PC);
2015-08-12 17:31:59 +00:00
AddCategoryMapping(3, TorznabCatType.BooksEbook);
AddCategoryMapping(4, TorznabCatType.AudioAudiobook);
AddCategoryMapping(7, TorznabCatType.BooksComics);
2015-08-12 17:31:59 +00:00
AddCategoryMapping(8, TorznabCatType.TVAnime);
2015-08-11 01:36:42 +00:00
AddCategoryMapping(9, TorznabCatType.Movies);
AddCategoryMapping(10, TorznabCatType.TVHD);
AddCategoryMapping(10, TorznabCatType.TVSD);
AddCategoryMapping(10, TorznabCatType.TV);
2015-08-11 01:36:42 +00:00
AddCategoryMapping(11, TorznabCatType.PCGames);
2015-07-19 20:21:31 +00:00
}
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
2015-07-19 20:21:31 +00:00
{
LoadValuesFromJson(configJson);
2015-07-19 20:21:31 +00:00
var pairs = new Dictionary<string, string> {
{ "username", configData.Username.Value },
{ "password", configData.Password.Value },
2015-07-19 20:21:31 +00:00
{ "keeplogged", "1" },
{ "login", "Log In!" }
};
2015-07-19 20:21:31 +00:00
var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink);
await ConfigureIfOK(response.Cookies, response.ContentString != null && response.ContentString.Contains("logout.php"), () =>
2015-07-19 20:21:31 +00:00
{
2020-02-28 22:32:43 +00:00
var parser = new HtmlParser();
var dom = parser.ParseDocument(response.ContentString);
2020-02-28 22:32:43 +00:00
var messageEl = dom.QuerySelectorAll("#loginform");
2015-07-19 20:21:31 +00:00
var messages = new List<string>();
for (var i = 0; i < 13; i++)
{
var child = messageEl[0].ChildNodes[i];
2020-02-28 22:32:43 +00:00
messages.Add(child.Text().Trim());
2015-07-19 20:21:31 +00:00
}
var message = string.Join(" ", messages);
throw new ExceptionWithConfigData(message, configData);
});
return IndexerConfigurationStatus.RequiresTesting;
2015-07-19 20:21:31 +00:00
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
2015-07-19 20:21:31 +00:00
{
var releases = new List<ReleaseInfo>();
var searchStrings = new List<string>(new string[] { query.GetQueryString() });
if (string.IsNullOrEmpty(query.Episode) && (query.Season > 0))
// Tracker naming rules: If query is for a whole season, "Season #" instead of "S##".
searchStrings.Add((query.SanitizedSearchTerm + " " + string.Format("\"Season {0}\"", query.Season)).Trim());
var categories = MapTorznabCapsToTrackers(query);
var request_urls = new List<string>();
foreach (var searchString in searchStrings)
2015-08-11 01:36:42 +00:00
{
var queryCollection = new NameValueCollection();
queryCollection.Add("action", "basic");
2015-08-11 01:36:42 +00:00
if (!string.IsNullOrWhiteSpace(searchString))
{
queryCollection.Add("searchstr", searchString);
}
2015-08-11 01:36:42 +00:00
foreach (var cat in categories)
{
queryCollection.Add("filter_cat[" + cat + "]", "1");
}
request_urls.Add(SearchUrl + queryCollection.GetQueryString());
}
var downloadTasksQuery = from url in request_urls select RequestWithCookiesAndRetryAsync(url);
var responses = await Task.WhenAll(downloadTasksQuery.ToArray());
for (var i = 0; i < searchStrings.Count(); i++)
2015-07-19 20:21:31 +00:00
{
var results = responses[i];
// Occasionally the cookies become invalid, login again if that happens
if (results.IsRedirect)
{
await ApplyConfiguration(null);
results = await RequestWithCookiesAndRetryAsync(request_urls[i]);
}
try
2015-07-19 20:21:31 +00:00
{
2020-02-28 22:32:43 +00:00
var parser = new HtmlParser();
var dom = parser.ParseDocument(results.ContentString);
2020-02-28 22:32:43 +00:00
var rows = dom.QuerySelectorAll("#torrent_table > tbody > tr.torrent");
foreach (var row in rows)
{
var release = new ReleaseInfo();
2015-07-19 20:21:31 +00:00
release.MinimumRatio = 1;
release.MinimumSeedTime = 172800; // 48 hours
2015-07-19 20:21:31 +00:00
2020-02-28 22:32:43 +00:00
var catStr = row.Children[0].FirstElementChild.GetAttribute("href").Split(new char[] { '[', ']' })[1];
release.Category = MapTrackerCatToNewznab(catStr);
2020-02-28 22:32:43 +00:00
var qLink = row.Children[1].QuerySelector("a");
var linkStr = qLink.GetAttribute("href");
release.Comments = new Uri(BaseUrl + "/" + linkStr);
release.Guid = release.Comments;
2015-07-19 20:21:31 +00:00
2020-02-28 22:32:43 +00:00
var qDownload = row.Children[1].QuerySelector("a[title='Download']");
release.Link = new Uri(BaseUrl + "/" + qDownload.GetAttribute("href"));
2015-07-19 20:21:31 +00:00
2020-02-28 22:32:43 +00:00
var dateStr = row.Children[3].TextContent.Trim().Replace(" and", "");
release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);
2015-07-19 20:21:31 +00:00
2020-02-28 22:32:43 +00:00
var sizeStr = row.Children[4].TextContent;
release.Size = ReleaseInfo.GetBytes(sizeStr);
2015-07-19 20:21:31 +00:00
2020-02-28 22:32:43 +00:00
release.Files = ParseUtil.CoerceInt(row.Children[2].TextContent.Trim());
release.Grabs = ParseUtil.CoerceInt(row.Children[6].TextContent.Trim());
release.Seeders = ParseUtil.CoerceInt(row.Children[7].TextContent.Trim());
release.Peers = ParseUtil.CoerceInt(row.Children[8].TextContent.Trim()) + release.Seeders;
2015-07-19 20:21:31 +00:00
2020-02-28 22:32:43 +00:00
var grabs = row.QuerySelector("td:nth-child(6)").TextContent;
release.Grabs = ParseUtil.CoerceInt(grabs);
2020-02-28 22:32:43 +00:00
if (row.QuerySelector("strong:contains(\"Freeleech!\")") != null)
release.DownloadVolumeFactor = 0;
else
release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 1;
2020-02-28 22:32:43 +00:00
var title = row.QuerySelector("td:nth-child(2)");
foreach (var element in title.QuerySelectorAll("span, strong, div, br"))
element.Remove();
2016-12-10 20:32:06 +00:00
2020-02-28 22:32:43 +00:00
release.Title = ParseUtil.NormalizeMultiSpaces(title.TextContent.Replace(" - ]", "]"));
if (catStr == "10") //change "Season #" to "S##" for TV shows
release.Title = Regex.Replace(release.Title, @"Season (\d+)",
m => string.Format("S{0:00}", int.Parse(m.Groups[1].Value)));
releases.Add(release);
}
}
catch (Exception ex)
{
OnParseError(results.ContentString, ex);
2015-07-19 20:21:31 +00:00
}
}
return releases;
2015-07-19 20:21:31 +00:00
}
}
}