2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2015-07-19 20:21:31 +00:00
|
|
|
using System.Collections.Generic;
|
2017-10-29 06:21:18 +00:00
|
|
|
using System.Collections.Specialized;
|
2020-05-03 23:35:52 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2015-07-19 20:21:31 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2017-08-10 06:19:27 +00:00
|
|
|
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;
|
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-10-29 06:21:18 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Indexers
|
2015-07-19 20:21:31 +00:00
|
|
|
{
|
2017-10-29 06:21:18 +00:00
|
|
|
// To comply with the rules for this tracker, only the acronym is used and no publicly displayed URLs to the site.
|
2020-05-03 23:35:52 +00:00
|
|
|
[ExcludeFromCodeCoverage]
|
2017-07-10 20:58:44 +00:00
|
|
|
public class BB : BaseWebIndexer
|
2015-07-19 20:21:31 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +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
|
|
|
|
2017-10-29 06:21:18 +00:00
|
|
|
private new ConfigurationDataBasicLogin configData
|
2015-08-03 21:38:45 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
get => (ConfigurationDataBasicLogin)base.configData;
|
|
|
|
set => base.configData = value;
|
2015-08-03 21:38:45 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
public BB(IIndexerConfigurationService configService, WebClient w, Logger l, IProtectionService ps)
|
2020-05-11 19:59:28 +00:00
|
|
|
: 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
|
|
|
{
|
2017-11-05 09:42:03 +00:00
|
|
|
Encoding = Encoding.UTF8;
|
2016-12-09 17:20:58 +00:00
|
|
|
Language = "en-us";
|
2017-01-27 15:57:32 +00:00
|
|
|
Type = "private";
|
2016-12-06 13:56:47 +00:00
|
|
|
|
2015-08-11 01:36:42 +00:00
|
|
|
AddCategoryMapping(1, TorznabCatType.Audio);
|
2017-08-10 06:19:27 +00:00
|
|
|
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);
|
2020-09-21 06:20:28 +00:00
|
|
|
AddCategoryMapping(5, TorznabCatType.Other);
|
|
|
|
AddCategoryMapping(6, TorznabCatType.BooksMagazines);
|
2016-11-05 17:51:21 +00:00
|
|
|
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);
|
2015-08-11 02:14:00 +00:00
|
|
|
AddCategoryMapping(10, TorznabCatType.TV);
|
2015-08-11 01:36:42 +00:00
|
|
|
AddCategoryMapping(11, TorznabCatType.PCGames);
|
2020-09-21 06:20:28 +00:00
|
|
|
AddCategoryMapping(12, TorznabCatType.Console);
|
|
|
|
AddCategoryMapping(13, TorznabCatType.Other);
|
|
|
|
AddCategoryMapping(14, TorznabCatType.Other);
|
2015-07-19 20:21:31 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 05:31:38 +00:00
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
2015-07-19 20:21:31 +00:00
|
|
|
{
|
2017-01-02 20:39:28 +00:00
|
|
|
LoadValuesFromJson(configJson);
|
2015-07-19 20:21:31 +00:00
|
|
|
var pairs = new Dictionary<string, string> {
|
2015-08-03 21:38:45 +00:00
|
|
|
{ "username", configData.Username.Value },
|
|
|
|
{ "password", configData.Password.Value },
|
2015-07-19 20:21:31 +00:00
|
|
|
{ "keeplogged", "1" },
|
|
|
|
{ "login", "Log In!" }
|
2015-07-27 00:03:51 +00:00
|
|
|
};
|
2015-07-19 20:21:31 +00:00
|
|
|
|
2015-07-27 00:03:51 +00:00
|
|
|
var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink);
|
2020-09-21 06:04:26 +00:00
|
|
|
await ConfigureIfOK(response.Cookies, response.Content != null && response.Content.Contains("logout.php"), () =>
|
2015-07-19 20:21:31 +00:00
|
|
|
{
|
2020-02-28 22:32:43 +00:00
|
|
|
var parser = new HtmlParser();
|
2020-09-21 06:04:26 +00:00
|
|
|
var dom = parser.ParseDocument(response.Content);
|
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);
|
2015-08-03 21:38:45 +00:00
|
|
|
throw new ExceptionWithConfigData(message, configData);
|
2015-07-27 00:03:51 +00:00
|
|
|
});
|
2015-08-22 20:57:13 +00:00
|
|
|
|
|
|
|
return IndexerConfigurationStatus.RequiresTesting;
|
2015-07-19 20:21:31 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 05:15:47 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
2015-07-19 20:21:31 +00:00
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var releases = new List<ReleaseInfo>();
|
|
|
|
var searchStrings = new List<string>(new string[] { query.GetQueryString() });
|
2017-10-29 06:21:18 +00:00
|
|
|
|
2017-08-10 06:19:27 +00:00
|
|
|
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());
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var categories = MapTorznabCapsToTrackers(query);
|
|
|
|
var request_urls = new List<string>();
|
2017-10-29 06:21:18 +00:00
|
|
|
|
2017-08-10 06:19:27 +00:00
|
|
|
foreach (var searchString in searchStrings)
|
2015-08-11 01:36:42 +00:00
|
|
|
{
|
2017-08-10 06:19:27 +00:00
|
|
|
var queryCollection = new NameValueCollection();
|
|
|
|
queryCollection.Add("action", "basic");
|
2015-08-11 01:36:42 +00:00
|
|
|
|
2017-08-10 06:19:27 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(searchString))
|
|
|
|
{
|
|
|
|
queryCollection.Add("searchstr", searchString);
|
|
|
|
}
|
2015-08-11 01:36:42 +00:00
|
|
|
|
2017-08-10 06:19:27 +00:00
|
|
|
foreach (var cat in categories)
|
|
|
|
{
|
|
|
|
queryCollection.Add("filter_cat[" + cat + "]", "1");
|
|
|
|
}
|
2015-07-27 00:03:51 +00:00
|
|
|
|
2017-08-10 06:19:27 +00:00
|
|
|
request_urls.Add(SearchUrl + queryCollection.GetQueryString());
|
2016-11-15 16:50:22 +00:00
|
|
|
}
|
2020-09-21 06:02:53 +00:00
|
|
|
var downloadTasksQuery =
|
|
|
|
from url in request_urls select RequestStringWithCookiesAndRetry(url);
|
2017-08-10 06:19:27 +00:00
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var responses = await Task.WhenAll(downloadTasksQuery.ToArray());
|
2016-11-15 16:50:22 +00:00
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
for (var i = 0; i < searchStrings.Count(); i++)
|
2015-07-19 20:21:31 +00:00
|
|
|
{
|
2017-08-10 06:19:27 +00:00
|
|
|
var results = responses[i];
|
|
|
|
// Occasionally the cookies become invalid, login again if that happens
|
|
|
|
if (results.IsRedirect)
|
|
|
|
{
|
|
|
|
await ApplyConfiguration(null);
|
2020-09-21 06:02:53 +00:00
|
|
|
results = await RequestStringWithCookiesAndRetry(request_urls[i]);
|
2017-08-10 06:19:27 +00:00
|
|
|
}
|
|
|
|
try
|
2015-07-19 20:21:31 +00:00
|
|
|
{
|
2020-02-28 22:32:43 +00:00
|
|
|
var parser = new HtmlParser();
|
2020-09-21 06:04:26 +00:00
|
|
|
var dom = parser.ParseDocument(results.Content);
|
2020-02-28 22:32:43 +00:00
|
|
|
var rows = dom.QuerySelectorAll("#torrent_table > tbody > tr.torrent");
|
2017-08-10 06:19:27 +00:00
|
|
|
foreach (var row in rows)
|
|
|
|
{
|
|
|
|
var release = new ReleaseInfo();
|
2015-07-19 20:21:31 +00:00
|
|
|
|
2017-08-10 06:19:27 +00:00
|
|
|
release.MinimumRatio = 1;
|
2020-01-11 18:07:19 +00:00
|
|
|
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];
|
2017-08-10 06:19:27 +00:00
|
|
|
release.Category = MapTrackerCatToNewznab(catStr);
|
2015-08-11 02:14:00 +00:00
|
|
|
|
2020-09-21 06:20:28 +00:00
|
|
|
var qDetails = row.Children[1].QuerySelector("a[title='View Torrent']");
|
|
|
|
release.Comments = new Uri(BaseUrl + "/" + qDetails.GetAttribute("href"));
|
2017-08-10 06:19:27 +00:00
|
|
|
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", "");
|
2017-08-10 06:19:27 +00:00
|
|
|
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;
|
2017-08-10 06:19:27 +00:00
|
|
|
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.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;
|
2017-08-10 06:19:27 +00:00
|
|
|
release.Grabs = ParseUtil.CoerceInt(grabs);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-02-28 22:32:43 +00:00
|
|
|
if (row.QuerySelector("strong:contains(\"Freeleech!\")") != null)
|
2017-08-10 06:19:27 +00:00
|
|
|
release.DownloadVolumeFactor = 0;
|
|
|
|
else
|
|
|
|
release.DownloadVolumeFactor = 1;
|
2016-11-15 16:50:22 +00:00
|
|
|
|
2017-08-10 06:19:27 +00:00
|
|
|
release.UploadVolumeFactor = 1;
|
2016-11-15 16:50:22 +00:00
|
|
|
|
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(" - ]", "]"));
|
2017-08-10 06:19:27 +00:00
|
|
|
|
|
|
|
if (catStr == "10") //change "Season #" to "S##" for TV shows
|
|
|
|
release.Title = Regex.Replace(release.Title, @"Season (\d+)",
|
2020-02-10 22:16:19 +00:00
|
|
|
m => string.Format("S{0:00}", int.Parse(m.Groups[1].Value)));
|
2017-10-29 06:21:18 +00:00
|
|
|
|
2017-08-10 06:19:27 +00:00
|
|
|
releases.Add(release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2020-09-21 06:04:26 +00:00
|
|
|
OnParseError(results.Content, ex);
|
2015-07-19 20:21:31 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-28 23:10:04 +00:00
|
|
|
return releases;
|
2015-07-19 20:21:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|