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

200 lines
8.9 KiB
C#
Raw Normal View History

using System;
2015-07-19 20:21:31 +00:00
using System.Collections.Generic;
using System.Collections.Specialized;
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;
using CsQuery;
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.
2015-07-19 20:21:31 +00:00
public class BB : BaseWebIndexer
2015-07-19 20:21:31 +00:00
{
private string BaseUrl { get { return StringUtil.FromBase64("aHR0cHM6Ly9iYWNvbmJpdHMub3JnLw=="); } }
2015-08-02 18:44:36 +00:00
private Uri BaseUri { get { return new Uri(BaseUrl); } }
private string LoginUrl { get { return BaseUri + "login.php"; } }
2015-08-11 01:36:42 +00:00
private string SearchUrl { get { return 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 { return (ConfigurationDataBasicLogin)base.configData; }
set { base.configData = value; }
}
public BB(IIndexerConfigurationService configService, WebClient w, Logger l, IProtectionService ps)
: base(name: "bB",
description: "BaconBits (bB) is a Private Torrent Tracker for 0DAY / GENERAL",
link: StringUtil.FromBase64("aHR0cHM6Ly9iYWNvbmJpdHMub3JnLw=="),
2015-08-23 00:02:41 +00:00
caps: new TorznabCapabilities(),
configService: configService,
client: w,
logger: l,
2015-08-07 19:09:13 +00:00
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.Content != null && response.Content.Contains("logout.php"), () =>
2015-07-19 20:21:31 +00:00
{
CQ dom = response.Content;
2015-07-19 20:21:31 +00:00
var messageEl = dom["#loginform"];
var messages = new List<string>();
for (var i = 0; i < 13; i++)
{
var child = messageEl[0].ChildNodes[i];
messages.Add(child.Cq().Text().Trim());
}
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
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
List<string> 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());
List<string> categories = MapTorznabCapsToTrackers(query);
List<string> 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());
}
IEnumerable<Task<WebClientStringResult>> downloadTasksQuery =
from url in request_urls select RequestStringWithCookiesAndRetry(url);
WebClientStringResult[] responses = await Task.WhenAll(downloadTasksQuery.ToArray());
for (int 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 RequestStringWithCookiesAndRetry(request_urls[i]);
}
try
2015-07-19 20:21:31 +00:00
{
CQ dom = results.Content;
var rows = dom["#torrent_table > tbody > tr.torrent"];
foreach (var row in rows)
{
CQ qRow = row.Cq();
var release = new ReleaseInfo();
2015-07-19 20:21:31 +00:00
release.MinimumRatio = 1;
release.MinimumSeedTime = 172800;
2015-07-19 20:21:31 +00:00
var catStr = row.ChildElements.ElementAt(0).FirstElementChild.GetAttribute("href").Split(new char[] { '[', ']' })[1];
release.Category = MapTrackerCatToNewznab(catStr);
var qLink = row.ChildElements.ElementAt(1).Cq().Children("a")[0].Cq();
var linkStr = qLink.Attr("href");
release.Comments = new Uri(BaseUrl + "/" + linkStr);
release.Guid = release.Comments;
2015-07-19 20:21:31 +00:00
var qDownload = row.ChildElements.ElementAt(1).Cq().Find("a[title='Download']")[0].Cq();
release.Link = new Uri(BaseUrl + "/" + qDownload.Attr("href"));
2015-07-19 20:21:31 +00:00
var dateStr = row.ChildElements.ElementAt(3).Cq().Text().Trim().Replace(" and", "");
release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);
2015-07-19 20:21:31 +00:00
var sizeStr = row.ChildElements.ElementAt(4).Cq().Text();
release.Size = ReleaseInfo.GetBytes(sizeStr);
2015-07-19 20:21:31 +00:00
release.Files = ParseUtil.CoerceInt(row.ChildElements.ElementAt(2).Cq().Text().Trim());
release.Grabs = ParseUtil.CoerceInt(row.ChildElements.ElementAt(6).Cq().Text().Trim());
release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(7).Cq().Text().Trim());
release.Peers = ParseUtil.CoerceInt(row.ChildElements.ElementAt(8).Cq().Text().Trim()) + release.Seeders;
2015-07-19 20:21:31 +00:00
var grabs = qRow.Find("td:nth-child(6)").Text();
release.Grabs = ParseUtil.CoerceInt(grabs);
if (qRow.Find("strong:contains(\"Freeleech!\")").Length >= 1)
release.DownloadVolumeFactor = 0;
else
release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 1;
var title = qRow.Find("td:nth-child(2)");
title.Find("span, strong, div, br").Remove();
2016-12-10 20:32:06 +00:00
release.Title = ParseUtil.NormalizeMultiSpaces(title.Text().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}", Int32.Parse(m.Groups[1].Value)));
releases.Add(release);
}
}
catch (Exception ex)
{
OnParseError(results.Content, ex);
2015-07-19 20:21:31 +00:00
}
}
return releases;
2015-07-19 20:21:31 +00:00
}
}
}