Jackett/src/Jackett.Common/Indexers/BJShare.cs

337 lines
16 KiB
C#
Raw Normal View History

using System;
2016-10-29 20:14:38 +00:00
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AngleSharp.Dom;
using AngleSharp.Parser.Html;
using Jackett.Models;
using Jackett.Models.IndexerConfig;
Feature/netcore preparation (#2035) * Move to use package reference for restoring nuget packages. * Return a task result for this async method. * Update to a supported version of the .NET Framework. This also has the side effect of allowing us to automatically generate our binding redirects on build. * Set the solution to target VS2017 * Update test solution csproj file to support being built through MSBuild 15 * Move to use package reference for restoring nuget packages. * Return a task result for this async method. * Update to a supported version of the .NET Framework. This also has the side effect of allowing us to automatically generate our binding redirects on build. * Set the solution to target VS2017 * Update test solution csproj file to support being built through MSBuild 15 * DateTimeRoutines does not have Nuget packages that support .NET Standard (and therefore .NET Core). We will have to include them for now until we can get rid of this dependency. * Move the interfaces into their own files. This will be useful when we share them between the .NET Core and .NET Framework WebAPI * Stage services that need to point to the new interface namespace. * Update CurlSharp to fix memory leak issue and support better runtime compatibility with OSX and Linux * Start spliting some interfaces into their own files - this will help by allowing us to split them out in the future into a seperate project so the actual implementations can stay within their respective architectures when required
2017-10-29 10:19:09 +00:00
using Jackett.Services.Interfaces;
using Jackett.Utils;
using Jackett.Utils.Clients;
using Newtonsoft.Json.Linq;
using NLog;
2016-10-29 20:14:38 +00:00
namespace Jackett.Indexers
{
public class BJShare : BaseWebIndexer
2016-10-29 20:14:38 +00:00
{
private string LoginUrl { get { return SiteLink + "login.php"; } }
private string BrowseUrl { get { return SiteLink + "torrents.php"; } }
private string TodayUrl { get { return SiteLink + "torrents.php?action=today"; } }
2016-10-29 20:14:38 +00:00
private new ConfigurationDataBasicLoginWithRSSAndDisplay configData
2016-10-29 20:14:38 +00:00
{
get { return (ConfigurationDataBasicLoginWithRSSAndDisplay)base.configData; }
set { base.configData = value; }
}
public BJShare(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
2016-10-29 20:14:38 +00:00
: base(name: "BJ-Share",
description: "A brazilian tracker.",
link: "https://bj-share.me/",
caps: TorznabUtil.CreateDefaultTorznabTVCaps(),
configService: configService,
2016-10-29 20:14:38 +00:00
client: wc,
logger: l,
p: ps,
configData: new ConfigurationDataBasicLoginWithRSSAndDisplay())
{
Encoding = Encoding.UTF8;
2016-12-09 17:20:58 +00:00
Language = "pt-br";
Type = "private";
2016-10-29 20:14:38 +00:00
AddCategoryMapping(14, TorznabCatType.TVAnime); // Anime
AddCategoryMapping(3, TorznabCatType.PC0day); // Aplicativos
AddCategoryMapping(8, TorznabCatType.Other); // Apostilas/Tutoriais
AddCategoryMapping(19, TorznabCatType.AudioAudiobook); // Audiobook
AddCategoryMapping(16, TorznabCatType.TVOTHER); // Desenho Animado
AddCategoryMapping(18, TorznabCatType.TVDocumentary); // Documentários
AddCategoryMapping(10, TorznabCatType.Books); // E-Books
AddCategoryMapping(20, TorznabCatType.TVSport); // Esportes
AddCategoryMapping(1, TorznabCatType.Movies); // Filmes
AddCategoryMapping(12, TorznabCatType.MoviesOther); // Histórias em Quadrinhos
AddCategoryMapping(5, TorznabCatType.Audio); // Músicas
AddCategoryMapping(7, TorznabCatType.Other); // Outros
AddCategoryMapping(9, TorznabCatType.BooksMagazines); // Revistas
AddCategoryMapping(2, TorznabCatType.TV); // Seriados
AddCategoryMapping(17, TorznabCatType.TV); // Shows
AddCategoryMapping(13, TorznabCatType.TV); // Stand Up Comedy
AddCategoryMapping(11, TorznabCatType.Other); // Video-Aula
AddCategoryMapping(6, TorznabCatType.TV); // Vídeos de TV
AddCategoryMapping(4, TorznabCatType.Other); // Jogos
AddCategoryMapping(199, TorznabCatType.XXX); // Filmes Adultos
AddCategoryMapping(200, TorznabCatType.XXX); // Jogos Adultos
2016-10-29 20:14:38 +00:00
AddCategoryMapping(201, TorznabCatType.XXXImageset); // Fotos Adultas
}
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
2016-10-29 20:14:38 +00:00
{
LoadValuesFromJson(configJson);
2016-10-29 20:14:38 +00:00
var pairs = new Dictionary<string, string>
{
{ "username", configData.Username.Value },
{ "password", configData.Password.Value },
{ "keeplogged", "1" }
};
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, LoginUrl, true);
await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("logout.php"), () =>
{
var errorMessage = result.Content;
throw new ExceptionWithConfigData(errorMessage, configData);
2016-10-29 20:14:38 +00:00
});
return IndexerConfigurationStatus.RequiresTesting;
}
private string StripSearchString(string term)
{
// Search does not support searching with episode numbers so strip it if we have one
// Ww AND filter the result later to archive the proper result
term = Regex.Replace(term, @"[S|E]\d\d", string.Empty);
return term.Trim();
2016-11-01 08:22:52 +00:00
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
2016-10-29 20:14:38 +00:00
{
var releases = new List<ReleaseInfo>();
var searchString = query.GetQueryString();
// if the search string is empty use the "last 24h torrents" view
if (string.IsNullOrWhiteSpace(searchString))
{
2016-10-29 20:14:38 +00:00
var results = await RequestStringWithCookies(TodayUrl);
try
{
string RowsSelector = "table.torrent_table > tbody > tr:not(tr.colhead)";
var SearchResultParser = new HtmlParser();
2016-10-29 20:14:38 +00:00
var SearchResultDocument = SearchResultParser.Parse(results.Content);
var Rows = SearchResultDocument.QuerySelectorAll(RowsSelector);
foreach (var Row in Rows)
2016-10-29 20:14:38 +00:00
{
try
2016-10-29 20:14:38 +00:00
{
var release = new ReleaseInfo();
release.MinimumRatio = 1;
2016-10-29 20:14:38 +00:00
release.MinimumSeedTime = 0;
var qDetailsLink = Row.QuerySelector("a.BJinfoBox");
var qTitle = qDetailsLink.QuerySelector("font");
release.Title = qTitle.TextContent;
var qBJinfoBox = qDetailsLink.QuerySelector("span");
var qCatLink = Row.QuerySelector("a[href^=\"/torrents.php?filter_cat\"]");
var qDLLink = Row.QuerySelector("a[href^=\"torrents.php?action=download\"]");
var qSeeders = Row.QuerySelector("td:nth-child(4)");
var qLeechers = Row.QuerySelector("td:nth-child(5)");
var qFreeLeech = Row.QuerySelector("font[color=\"green\"]:contains(Free)");
release.Description = "";
foreach (var Child in qBJinfoBox.ChildNodes)
{
var type = Child.NodeType;
if (type != NodeType.Text)
continue;
var line = Child.TextContent;
if (line.StartsWith("Tamanho:"))
{
string Size = line.Substring("Tamanho: ".Length); ;
release.Size = ReleaseInfo.GetBytes(Size);
}
else if (line.StartsWith("Lançado em: "))
{
string PublishDateStr = line.Substring("Lançado em: ".Length).Replace("às ", "");
PublishDateStr += " +0";
var PublishDate = DateTime.SpecifyKind(DateTime.ParseExact(PublishDateStr, "dd/MM/yyyy HH:mm z", CultureInfo.InvariantCulture), DateTimeKind.Unspecified);
release.PublishDate = PublishDate.ToLocalTime();
}
else
{
release.Description += line + "\n";
}
}
var catStr = qCatLink.GetAttribute("href").Split('=')[1];
release.Category = MapTrackerCatToNewznab(catStr);
release.Link = new Uri(SiteLink + qDLLink.GetAttribute("href"));
release.Comments = new Uri(SiteLink + qDetailsLink.GetAttribute("href"));
release.Guid = release.Link;
release.Seeders = ParseUtil.CoerceInt(qSeeders.TextContent);
release.Peers = ParseUtil.CoerceInt(qLeechers.TextContent) + release.Seeders;
if (qFreeLeech != null)
release.DownloadVolumeFactor = 0;
2016-10-29 20:14:38 +00:00
else
release.DownloadVolumeFactor = 1;
2016-10-29 20:14:38 +00:00
release.UploadVolumeFactor = 1;
releases.Add(release);
2016-10-29 20:14:38 +00:00
}
catch (Exception ex)
{
logger.Error(string.Format("{0}: Error while parsing row '{1}': {2}", ID, Row.OuterHtml, ex.Message));
}
}
2016-10-29 20:14:38 +00:00
}
catch (Exception ex)
{
OnParseError(results.Content, ex);
}
2016-10-29 20:14:38 +00:00
}
else // use search
2016-10-29 20:14:38 +00:00
{
var searchUrl = BrowseUrl;
var queryCollection = new NameValueCollection();
queryCollection.Add("searchstr", StripSearchString(searchString));
queryCollection.Add("order_by", "time");
queryCollection.Add("order_way", "desc");
queryCollection.Add("group_results", "1");
queryCollection.Add("action", "basic");
queryCollection.Add("searchsubmit", "1");
foreach (var cat in MapTorznabCapsToTrackers(query))
{
queryCollection.Add("filter_cat[" + cat + "]", "1");
}
searchUrl += "?" + queryCollection.GetQueryString();
2016-10-29 20:14:38 +00:00
var results = await RequestStringWithCookies(searchUrl);
try
{
string RowsSelector = "table.torrent_table > tbody > tr:not(tr.colhead)";
var SearchResultParser = new HtmlParser();
2016-10-29 20:14:38 +00:00
var SearchResultDocument = SearchResultParser.Parse(results.Content);
var Rows = SearchResultDocument.QuerySelectorAll(RowsSelector);
ICollection<int> GroupCategory = null;
string GroupTitle = null;
string GroupYearStr = null;
Nullable<DateTime> GroupPublishDate = null;
foreach (var Row in Rows)
2016-10-29 20:14:38 +00:00
{
try
{
var qDetailsLink = Row.QuerySelector("a[href^=\"torrents.php?id=\"]");
string Title = qDetailsLink.TextContent;
ICollection<int> Category = null;
string YearStr = null;
Nullable<DateTime> YearPublishDate = null;
if (Row.ClassList.Contains("group") || Row.ClassList.Contains("torrent")) // group/ungrouped headers
{
var qCatLink = Row.QuerySelector("a[href^=\"/torrents.php?filter_cat\"]");
string CategoryStr = qCatLink.GetAttribute("href").Split('=')[1].Split('&')[0];
Category = MapTrackerCatToNewznab(CategoryStr);
YearStr = qDetailsLink.NextSibling.TextContent.Trim().TrimStart('[').TrimEnd(']');
YearPublishDate = DateTime.SpecifyKind(DateTime.ParseExact(YearStr, "yyyy", CultureInfo.InvariantCulture), DateTimeKind.Unspecified);
if (Row.ClassList.Contains("group")) // group headers
{
GroupCategory = Category;
GroupTitle = Title;
GroupYearStr = YearStr;
GroupPublishDate = YearPublishDate;
continue;
}
}
2016-10-29 20:14:38 +00:00
var release = new ReleaseInfo();
release.MinimumRatio = 1;
release.MinimumSeedTime = 0;
var qDLLink = Row.QuerySelector("a[href^=\"torrents.php?action=download\"]");
var qSize = Row.QuerySelector("td:nth-last-child(4)");
2017-11-08 16:33:40 +00:00
var qGrabs = Row.QuerySelector("td:nth-last-child(3)");
var qSeeders = Row.QuerySelector("td:nth-last-child(2)");
var qLeechers = Row.QuerySelector("td:nth-last-child(1)");
var qFreeLeech = Row.QuerySelector("strong[title=\"Free\"]");
if (Row.ClassList.Contains("group_torrent")) // torrents belonging to a group
{
release.Description = qDetailsLink.TextContent;
release.Title = GroupTitle + " " + GroupYearStr;
release.PublishDate = GroupPublishDate.Value;
release.Category = GroupCategory;
}
else if (Row.ClassList.Contains("torrent")) // standalone/un grouped torrents
{
var qDescription = Row.QuerySelector("div.torrent_info");
release.Description = qDescription.TextContent;
release.Title = Title + " " + YearStr;
release.PublishDate = YearPublishDate.Value;
release.Category = Category;
}
release.Description = release.Description.Replace(" / Free", ""); // Remove Free Tag
2017-04-20 08:22:45 +00:00
release.Description = release.Description.Replace("Full HD", "1080p");
2017-07-11 19:58:01 +00:00
release.Description = release.Description.Replace("/ HD / ", "/ 720p /");
2017-07-10 19:19:22 +00:00
release.Description = release.Description.Replace(" / HD]", " / 720p]");
2017-04-20 08:22:45 +00:00
release.Description = release.Description.Replace("4K", "2160p");
int nBarra = release.Title.IndexOf("[");
if (nBarra != -1)
{
release.Title = release.Title.Substring(nBarra + 1);
release.Title = release.Title.Replace("]", "");
}
release.Title += " " + release.Description; // add year and Description to the release Title to add some meaning to it
// check for previously stripped search terms
if (!query.MatchQueryStringAND(release.Title))
continue;
var Size = qSize.TextContent;
release.Size = ReleaseInfo.GetBytes(Size);
release.Link = new Uri(SiteLink + qDLLink.GetAttribute("href"));
release.Comments = new Uri(SiteLink + qDetailsLink.GetAttribute("href"));
release.Guid = release.Link;
2017-11-08 16:33:40 +00:00
release.Grabs = ParseUtil.CoerceLong(qGrabs.TextContent);
release.Seeders = ParseUtil.CoerceInt(qSeeders.TextContent);
release.Peers = ParseUtil.CoerceInt(qLeechers.TextContent) + release.Seeders;
if (qFreeLeech != null)
release.DownloadVolumeFactor = 0;
2016-10-29 20:14:38 +00:00
else
release.DownloadVolumeFactor = 1;
2016-10-29 20:14:38 +00:00
release.UploadVolumeFactor = 1;
releases.Add(release);
2016-10-29 20:14:38 +00:00
}
catch (Exception ex)
{
logger.Error(string.Format("{0}: Error while parsing row '{1}': {2}", ID, Row.OuterHtml, ex.Message));
}
}
2016-10-29 20:14:38 +00:00
}
catch (Exception ex)
{
OnParseError(results.Content, ex);
}
2016-10-29 20:14:38 +00:00
}
return releases;
}
}
}