2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2016-09-04 08:25:33 +00:00
|
|
|
using System.Collections.Generic;
|
2020-05-03 23:35:52 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-09-04 08:25:33 +00:00
|
|
|
using System.Globalization;
|
2020-02-28 21:23:24 +00:00
|
|
|
using System.Linq;
|
2017-11-05 09:42:03 +00:00
|
|
|
using System.Net;
|
2016-09-04 08:25:33 +00:00
|
|
|
using System.Text;
|
2020-10-02 14:39:39 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2016-09-04 08:25:33 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-02-28 21:23:24 +00:00
|
|
|
using AngleSharp.Dom;
|
|
|
|
using AngleSharp.Html.Parser;
|
2018-03-10 08:05:56 +00:00
|
|
|
using Jackett.Common.Models;
|
2020-10-02 14:39:39 +00:00
|
|
|
using Jackett.Common.Models.IndexerConfig.Bespoke;
|
2018-03-10 08:05:56 +00:00
|
|
|
using Jackett.Common.Services.Interfaces;
|
|
|
|
using Jackett.Common.Utils.Clients;
|
2017-10-29 06:21:18 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
2016-09-04 08:25:33 +00:00
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Indexers
|
2016-09-04 08:25:33 +00:00
|
|
|
{
|
2020-05-03 23:35:52 +00:00
|
|
|
[ExcludeFromCodeCoverage]
|
2017-07-10 20:58:44 +00:00
|
|
|
public class BakaBT : BaseWebIndexer
|
2016-09-04 08:25:33 +00:00
|
|
|
{
|
2020-01-11 07:07:10 +00:00
|
|
|
private string SearchUrl => SiteLink + "browse.php?only=0&hentai=1&incomplete=1&lossless=1&hd=1&multiaudio=1&bonus=1&reorder=1&q=";
|
|
|
|
private string LoginUrl => SiteLink + "login.php";
|
2020-02-10 22:16:19 +00:00
|
|
|
private readonly string LogoutStr = "<a href=\"logout.php\">Logout</a>";
|
2020-10-02 14:39:39 +00:00
|
|
|
private bool AddRomajiTitle => configData.AddRomajiTitle.Value;
|
|
|
|
private bool AppendSeason => configData.AppendSeason.Value;
|
2016-09-04 08:25:33 +00:00
|
|
|
|
2020-10-02 14:39:39 +00:00
|
|
|
private readonly List<int> defaultCategories = new List<int> { TorznabCatType.TVAnime.ID };
|
2020-08-07 19:40:44 +00:00
|
|
|
|
2020-10-02 14:39:39 +00:00
|
|
|
private new ConfigurationDataBakaBT configData
|
2016-09-04 08:25:33 +00:00
|
|
|
{
|
2020-10-02 14:39:39 +00:00
|
|
|
get => (ConfigurationDataBakaBT)base.configData;
|
2020-02-25 16:08:03 +00:00
|
|
|
set => base.configData = value;
|
2016-09-04 08:25:33 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
public BakaBT(IIndexerConfigurationService configService, Utils.Clients.WebClient wc, Logger l, IProtectionService ps)
|
2020-05-11 19:59:28 +00:00
|
|
|
: base(id: "bakabt",
|
|
|
|
name: "BakaBT",
|
|
|
|
description: "Anime Comunity",
|
|
|
|
link: "https://bakabt.me/",
|
2020-10-18 20:47:36 +00:00
|
|
|
caps: new TorznabCapabilities
|
|
|
|
{
|
|
|
|
TvSearchParams = new List<TvSearchParam>
|
|
|
|
{
|
|
|
|
TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep
|
2020-10-20 00:38:27 +00:00
|
|
|
},
|
|
|
|
MusicSearchParams = new List<MusicSearchParam>
|
|
|
|
{
|
|
|
|
MusicSearchParam.Q
|
|
|
|
},
|
|
|
|
BookSearchParams = new List<BookSearchParam>
|
|
|
|
{
|
|
|
|
BookSearchParam.Q
|
2020-10-18 20:47:36 +00:00
|
|
|
}
|
|
|
|
},
|
2020-05-11 19:59:28 +00:00
|
|
|
configService: configService,
|
|
|
|
client: wc,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
2020-10-02 14:39:39 +00:00
|
|
|
configData: new ConfigurationDataBakaBT("To prevent 0-results-error, Enable the " +
|
2020-05-11 19:59:28 +00:00
|
|
|
"Show-Adult-Content option in your BakaBT account Settings."))
|
2016-09-04 08:25:33 +00:00
|
|
|
{
|
2016-12-09 17:20:58 +00:00
|
|
|
Encoding = Encoding.UTF8;
|
|
|
|
Language = "en-us";
|
2017-01-27 15:57:32 +00:00
|
|
|
Type = "private";
|
2020-10-18 17:26:22 +00:00
|
|
|
|
2020-08-07 19:40:44 +00:00
|
|
|
AddCategoryMapping(1, TorznabCatType.TVAnime, "Anime Series");
|
|
|
|
AddCategoryMapping(2, TorznabCatType.TVAnime, "OVA");
|
|
|
|
AddCategoryMapping(3, TorznabCatType.AudioOther, "Soundtrack");
|
|
|
|
AddCategoryMapping(4, TorznabCatType.BooksComics, "Manga");
|
|
|
|
AddCategoryMapping(5, TorznabCatType.TVAnime, "Anime Movie");
|
2020-10-28 19:00:48 +00:00
|
|
|
AddCategoryMapping(6, TorznabCatType.TVOther, "Live Action");
|
2020-08-07 19:40:44 +00:00
|
|
|
AddCategoryMapping(7, TorznabCatType.BooksOther, "Artbook");
|
|
|
|
AddCategoryMapping(8, TorznabCatType.AudioVideo, "Music Video");
|
2020-10-28 19:00:48 +00:00
|
|
|
AddCategoryMapping(9, TorznabCatType.BooksEBook, "Light Novel");
|
2016-09-04 08:25:33 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 05:31:38 +00:00
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
2016-09-04 08:25:33 +00:00
|
|
|
{
|
2017-01-02 20:39:28 +00:00
|
|
|
LoadValuesFromJson(configJson);
|
2020-01-11 07:07:10 +00:00
|
|
|
await DoLogin();
|
|
|
|
return IndexerConfigurationStatus.RequiresTesting;
|
|
|
|
}
|
2016-09-04 08:25:33 +00:00
|
|
|
|
2020-01-11 07:07:10 +00:00
|
|
|
private async Task DoLogin()
|
|
|
|
{
|
2020-10-19 21:19:10 +00:00
|
|
|
var loginForm = await webclient.GetResultAsync(new Utils.Clients.WebRequest
|
2017-10-29 06:21:18 +00:00
|
|
|
{
|
|
|
|
Url = LoginUrl,
|
|
|
|
Type = RequestType.GET
|
|
|
|
});
|
2016-09-04 08:25:33 +00:00
|
|
|
|
|
|
|
var pairs = new Dictionary<string, string> {
|
|
|
|
{ "username", configData.Username.Value },
|
|
|
|
{ "password", configData.Password.Value },
|
|
|
|
{ "returnto", "/index.php" }
|
|
|
|
};
|
|
|
|
|
2020-09-30 17:37:11 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var dom = parser.ParseDocument(loginForm.ContentString);
|
|
|
|
var loginKey = dom.QuerySelector("input[name=\"loginKey\"]");
|
2020-10-02 14:39:39 +00:00
|
|
|
if (loginKey != null)
|
2020-09-30 17:37:11 +00:00
|
|
|
pairs["loginKey"] = loginKey.GetAttribute("value");
|
2020-10-02 14:39:39 +00:00
|
|
|
|
2016-09-04 08:25:33 +00:00
|
|
|
var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginForm.Cookies, true, null, SiteLink);
|
2020-06-09 17:36:57 +00:00
|
|
|
var responseContent = response.ContentString;
|
2020-01-11 07:07:10 +00:00
|
|
|
await ConfigureIfOK(response.Cookies, responseContent.Contains(LogoutStr), () =>
|
|
|
|
{
|
2020-02-28 21:23:24 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var dom = parser.ParseDocument(responseContent);
|
|
|
|
var messageEl = dom.QuerySelectorAll(".error").First();
|
2020-01-11 07:07:10 +00:00
|
|
|
var errorMessage = messageEl.Text().Trim();
|
|
|
|
throw new ExceptionWithConfigData(errorMessage, configData);
|
|
|
|
});
|
2016-09-04 08:25:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 05:15:47 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
2016-09-04 08:25:33 +00:00
|
|
|
{
|
2020-10-02 14:39:39 +00:00
|
|
|
var searchString = query.SanitizedSearchTerm;
|
|
|
|
|
|
|
|
var match = Regex.Match(query.SanitizedSearchTerm, @".*(?=\s(?:[Ee]\d+|\d+)$)");
|
|
|
|
if (match.Success)
|
|
|
|
searchString = match.Value;
|
2016-09-04 08:25:33 +00:00
|
|
|
|
|
|
|
var releases = new List<ReleaseInfo>();
|
2017-11-05 09:42:03 +00:00
|
|
|
var episodeSearchUrl = SearchUrl + WebUtility.UrlEncode(searchString);
|
2020-06-11 15:09:27 +00:00
|
|
|
var response = await RequestWithCookiesAndRetryAsync(episodeSearchUrl);
|
2020-06-09 17:36:57 +00:00
|
|
|
if (!response.ContentString.Contains(LogoutStr))
|
2020-01-11 07:07:10 +00:00
|
|
|
{
|
|
|
|
//Cookie appears to expire after a period of time or logging in to the site via browser
|
|
|
|
await DoLogin();
|
2020-06-11 15:09:27 +00:00
|
|
|
response = await RequestWithCookiesAndRetryAsync(episodeSearchUrl);
|
2020-01-11 07:07:10 +00:00
|
|
|
}
|
2016-09-04 08:25:33 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-02-28 21:23:24 +00:00
|
|
|
var parser = new HtmlParser();
|
2020-06-09 17:36:57 +00:00
|
|
|
var dom = parser.ParseDocument(response.ContentString);
|
2020-02-28 21:23:24 +00:00
|
|
|
var rows = dom.QuerySelectorAll(".torrents tr.torrent, .torrents tr.torrent_alt");
|
2020-10-02 14:39:39 +00:00
|
|
|
ICollection<int> currentCategories = new List<int> { TorznabCatType.TVAnime.ID };
|
2016-09-04 08:25:33 +00:00
|
|
|
|
|
|
|
foreach (var row in rows)
|
|
|
|
{
|
2020-02-28 21:23:24 +00:00
|
|
|
var qTitleLink = row.QuerySelector("a.title, a.alt_title");
|
2020-03-01 19:05:44 +00:00
|
|
|
if (qTitleLink == null)
|
|
|
|
continue;
|
|
|
|
|
2020-02-28 21:23:24 +00:00
|
|
|
var title = qTitleLink.TextContent.Trim();
|
2016-09-04 08:25:33 +00:00
|
|
|
|
|
|
|
// Insert before the release info
|
|
|
|
var taidx = title.IndexOf('(');
|
|
|
|
var tbidx = title.IndexOf('[');
|
|
|
|
|
|
|
|
if (taidx == -1)
|
|
|
|
taidx = title.Length;
|
|
|
|
|
|
|
|
if (tbidx == -1)
|
|
|
|
tbidx = title.Length;
|
|
|
|
var titleSplit = Math.Min(taidx, tbidx);
|
|
|
|
var titleSeries = title.Substring(0, titleSplit);
|
|
|
|
var releaseInfo = title.Substring(titleSplit);
|
|
|
|
|
2020-08-07 19:40:44 +00:00
|
|
|
currentCategories = GetNextCategory(row, currentCategories);
|
|
|
|
|
2020-10-19 21:19:10 +00:00
|
|
|
var stringSeparator = new[] { " | " };
|
2020-10-02 14:39:39 +00:00
|
|
|
var titles = titleSeries.Split(stringSeparator, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if (titles.Count() > 1 && !AddRomajiTitle)
|
|
|
|
titles = titles.Skip(1).ToArray();
|
|
|
|
|
|
|
|
foreach (var name in titles)
|
2016-09-04 08:25:33 +00:00
|
|
|
{
|
|
|
|
var release = new ReleaseInfo();
|
|
|
|
|
|
|
|
release.Title = (name + releaseInfo).Trim();
|
|
|
|
// Ensure the season is defined as this tracker only deals with full seasons
|
2020-10-02 14:39:39 +00:00
|
|
|
if (release.Title.IndexOf("Season") == -1 && AppendSeason)
|
2016-09-04 08:25:33 +00:00
|
|
|
{
|
|
|
|
// Insert before the release info
|
|
|
|
var aidx = release.Title.IndexOf('(');
|
|
|
|
var bidx = release.Title.IndexOf('[');
|
|
|
|
|
|
|
|
if (aidx == -1)
|
|
|
|
aidx = release.Title.Length;
|
|
|
|
|
|
|
|
if (bidx == -1)
|
|
|
|
bidx = release.Title.Length;
|
|
|
|
|
|
|
|
var insertPoint = Math.Min(aidx, bidx);
|
2020-10-02 14:39:39 +00:00
|
|
|
release.Title = release.Title.Substring(0, insertPoint) + " Season 1 " + release.Title.Substring(insertPoint);
|
2016-09-04 08:25:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 19:40:44 +00:00
|
|
|
release.Category = currentCategories;
|
2020-03-08 13:50:38 +00:00
|
|
|
release.Description = row.QuerySelector("span.tags")?.TextContent;
|
2020-02-28 21:23:24 +00:00
|
|
|
release.Guid = new Uri(SiteLink + qTitleLink.GetAttribute("href"));
|
2016-09-04 08:25:33 +00:00
|
|
|
release.Comments = release.Guid;
|
|
|
|
|
2020-02-28 21:23:24 +00:00
|
|
|
release.Link = new Uri(SiteLink + row.QuerySelector(".peers a").GetAttribute("href"));
|
2018-12-28 17:19:27 +00:00
|
|
|
|
2020-02-28 21:23:24 +00:00
|
|
|
var grabs = row.QuerySelectorAll(".peers")[0].FirstChild.NodeValue.TrimEnd().TrimEnd('/').TrimEnd();
|
2018-12-28 17:19:27 +00:00
|
|
|
grabs = grabs.Replace("k", "000");
|
|
|
|
release.Grabs = int.Parse(grabs);
|
2020-02-28 21:23:24 +00:00
|
|
|
release.Seeders = int.Parse(row.QuerySelectorAll(".peers a")[0].TextContent);
|
|
|
|
release.Peers = release.Seeders + int.Parse(row.QuerySelectorAll(".peers a")[1].TextContent);
|
2016-09-04 08:25:33 +00:00
|
|
|
|
|
|
|
release.MinimumRatio = 1;
|
2020-01-11 18:07:19 +00:00
|
|
|
release.MinimumSeedTime = 172800; // 48 hours
|
2016-09-04 08:25:33 +00:00
|
|
|
|
2020-02-28 21:23:24 +00:00
|
|
|
var size = row.QuerySelector(".size").TextContent;
|
2016-09-04 08:25:33 +00:00
|
|
|
release.Size = ReleaseInfo.GetBytes(size);
|
|
|
|
|
|
|
|
//22 Jul 15
|
2020-02-28 21:23:24 +00:00
|
|
|
var dateStr = row.QuerySelector(".added").TextContent.Replace("'", string.Empty);
|
2016-09-04 08:25:33 +00:00
|
|
|
if (dateStr.Split(' ')[0].Length == 1)
|
|
|
|
dateStr = "0" + dateStr;
|
|
|
|
|
|
|
|
if (string.Equals(dateStr, "yesterday", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
release.PublishDate = DateTime.Now.AddDays(-1);
|
|
|
|
else if (string.Equals(dateStr, "today", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
release.PublishDate = DateTime.Now;
|
|
|
|
else
|
|
|
|
release.PublishDate = DateTime.ParseExact(dateStr, "dd MMM yy", CultureInfo.InvariantCulture);
|
|
|
|
|
2020-02-28 21:23:24 +00:00
|
|
|
release.DownloadVolumeFactor = row.QuerySelector("span.freeleech") != null ? 0 : 1;
|
2018-12-28 17:09:59 +00:00
|
|
|
release.UploadVolumeFactor = 1;
|
|
|
|
|
2016-09-04 08:25:33 +00:00
|
|
|
releases.Add(release);
|
|
|
|
}
|
2020-10-02 14:39:39 +00:00
|
|
|
|
2016-09-04 08:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2020-06-09 17:36:57 +00:00
|
|
|
OnParseError(response.ContentString, ex);
|
2016-09-04 08:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
|
2020-08-07 19:40:44 +00:00
|
|
|
private ICollection<int> GetNextCategory(IElement row, ICollection<int> currentCategories)
|
|
|
|
{
|
2020-10-19 21:19:10 +00:00
|
|
|
var nextCategoryName = GetCategoryName(row);
|
2020-08-07 19:40:44 +00:00
|
|
|
if (nextCategoryName != null)
|
|
|
|
{
|
|
|
|
currentCategories = MapTrackerCatDescToNewznab(nextCategoryName);
|
|
|
|
if (currentCategories.Count == 0)
|
|
|
|
return defaultCategories;
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentCategories;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string GetCategoryName(IElement row)
|
|
|
|
{
|
|
|
|
var categoryElement = row.QuerySelector("td.category span");
|
|
|
|
if (categoryElement == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var categoryName = categoryElement.GetAttribute("title");
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(categoryName))
|
|
|
|
{
|
|
|
|
return categoryName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-09-04 08:25:33 +00:00
|
|
|
public override async Task<byte[]> Download(Uri link)
|
|
|
|
{
|
2020-09-21 16:39:47 +00:00
|
|
|
var downloadPage = await RequestWithCookiesAsync(link.ToString());
|
2020-02-28 21:23:24 +00:00
|
|
|
var parser = new HtmlParser();
|
2020-06-09 17:36:57 +00:00
|
|
|
var dom = parser.ParseDocument(downloadPage.ContentString);
|
2020-02-28 21:23:24 +00:00
|
|
|
var downloadLink = dom.QuerySelectorAll(".download_link").First().GetAttribute("href");
|
2016-09-04 08:25:33 +00:00
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(downloadLink))
|
|
|
|
throw new Exception("Unable to find download link.");
|
|
|
|
|
2020-09-21 16:39:47 +00:00
|
|
|
var response = await RequestWithCookiesAsync(SiteLink + downloadLink);
|
2020-03-14 23:58:50 +00:00
|
|
|
return response.ContentBytes;
|
2016-09-04 08:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
}
|