2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2017-10-29 06:21:18 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2018-03-14 14:42:47 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2017-10-29 06:21:18 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-02-28 21:22:13 +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;
|
2016-10-30 15:24:49 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Indexers
|
2016-10-30 15:24:49 +00:00
|
|
|
{
|
2017-07-10 20:58:44 +00:00
|
|
|
public class AnimeTorrents : BaseWebIndexer
|
2016-10-30 15:24:49 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
private string LoginUrl => SiteLink + "login.php";
|
|
|
|
private string SearchUrl => SiteLink + "ajax/torrents_data.php";
|
|
|
|
private string SearchUrlReferer => SiteLink + "torrents.php?cat=0&searchin=filename&search=";
|
2016-10-30 15:24:49 +00:00
|
|
|
|
2017-10-29 06:21:18 +00:00
|
|
|
private new ConfigurationDataBasicLogin configData
|
2016-10-30 15:24:49 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
get => (ConfigurationDataBasicLogin)base.configData;
|
|
|
|
set => base.configData = value;
|
2016-10-30 15:24:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
public AnimeTorrents(IIndexerConfigurationService configService, WebClient c, Logger l, IProtectionService ps)
|
2016-10-30 15:24:49 +00:00
|
|
|
: base(name: "AnimeTorrents",
|
|
|
|
description: "Definitive source for anime and manga",
|
2017-05-14 17:43:10 +00:00
|
|
|
link: "https://animetorrents.me/",
|
2016-10-30 15:24:49 +00:00
|
|
|
caps: new TorznabCapabilities(),
|
2017-07-10 20:58:44 +00:00
|
|
|
configService: configService,
|
2017-07-13 05:19:04 +00:00
|
|
|
client: c,
|
2016-10-30 15:24:49 +00:00
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationDataBasicLogin())
|
|
|
|
{
|
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
|
|
|
|
2016-10-30 15:24:49 +00:00
|
|
|
AddCategoryMapping(1, TorznabCatType.MoviesSD); // Anime Movie
|
|
|
|
AddCategoryMapping(6, TorznabCatType.MoviesHD); // Anime Movie HD
|
|
|
|
AddCategoryMapping(2, TorznabCatType.TVAnime); // Anime Series
|
|
|
|
AddCategoryMapping(7, TorznabCatType.TVAnime); // Anime Series HD
|
|
|
|
AddCategoryMapping(5, TorznabCatType.XXXDVD); // Hentai (censored)
|
|
|
|
AddCategoryMapping(9, TorznabCatType.XXXDVD); // Hentai (censored) HD
|
|
|
|
AddCategoryMapping(4, TorznabCatType.XXXDVD); // Hentai (un-censored)
|
|
|
|
AddCategoryMapping(8, TorznabCatType.XXXDVD); // Hentai (un-censored) HD
|
|
|
|
AddCategoryMapping(13, TorznabCatType.BooksForeign); // Light Novel
|
|
|
|
AddCategoryMapping(3, TorznabCatType.BooksComics); // Manga
|
|
|
|
AddCategoryMapping(10, TorznabCatType.BooksComics); // Manga 18+
|
|
|
|
AddCategoryMapping(11, TorznabCatType.TVAnime); // OVA
|
|
|
|
AddCategoryMapping(12, TorznabCatType.TVAnime); // OVA HD
|
|
|
|
AddCategoryMapping(14, TorznabCatType.BooksComics); // Doujin Anime
|
|
|
|
AddCategoryMapping(15, TorznabCatType.XXXDVD); // Doujin Anime 18+
|
|
|
|
AddCategoryMapping(16, TorznabCatType.AudioForeign); // Doujin Music
|
|
|
|
AddCategoryMapping(17, TorznabCatType.BooksComics); // Doujinshi
|
|
|
|
AddCategoryMapping(18, TorznabCatType.BooksComics); // Doujinshi 18+
|
|
|
|
AddCategoryMapping(19, TorznabCatType.Audio); // OST
|
|
|
|
}
|
|
|
|
|
2017-06-28 05:31:38 +00:00
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
2016-10-30 15:24:49 +00:00
|
|
|
{
|
2017-01-02 20:39:28 +00:00
|
|
|
LoadValuesFromJson(configJson);
|
2016-10-30 15:24:49 +00:00
|
|
|
var pairs = new Dictionary<string, string> {
|
|
|
|
{ "username", configData.Username.Value },
|
|
|
|
{ "password", configData.Password.Value },
|
|
|
|
{ "form", "login" },
|
|
|
|
{ "rememberme[]", "1" }
|
|
|
|
};
|
|
|
|
|
2017-05-14 17:43:10 +00:00
|
|
|
var loginPage = await RequestStringWithCookiesAndRetry(LoginUrl, "", LoginUrl);
|
2016-10-30 15:24:49 +00:00
|
|
|
|
|
|
|
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginPage.Cookies, true);
|
|
|
|
await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("logout.php"), () =>
|
|
|
|
{
|
2020-02-28 21:22:13 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var dom = parser.ParseDocument(result.Content);
|
|
|
|
var errorMessage = dom.QuerySelector(".ui-state-error").Text().Trim();
|
2016-10-30 15:24:49 +00:00
|
|
|
throw new ExceptionWithConfigData(errorMessage, configData);
|
|
|
|
});
|
|
|
|
|
|
|
|
return IndexerConfigurationStatus.RequiresTesting;
|
|
|
|
}
|
|
|
|
|
2017-07-03 05:15:47 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
2016-10-30 15:24:49 +00:00
|
|
|
{
|
|
|
|
var releases = new List<ReleaseInfo>();
|
|
|
|
var searchString = query.GetQueryString();
|
2018-03-14 14:42:47 +00:00
|
|
|
|
|
|
|
// replace any space, special char, etc. with % (wildcard)
|
2020-02-10 22:16:19 +00:00
|
|
|
var ReplaceRegex = new Regex("[^a-zA-Z0-9]+");
|
2018-03-14 14:42:47 +00:00
|
|
|
searchString = ReplaceRegex.Replace(searchString, "%");
|
2016-10-30 15:24:49 +00:00
|
|
|
var searchUrl = SearchUrl;
|
2020-03-26 22:15:28 +00:00
|
|
|
var queryCollection = new NameValueCollection
|
|
|
|
{
|
|
|
|
{"total", "146"}, // Not sure what this is about but its required!
|
|
|
|
{"cat", MapTorznabCapsToTrackers(query).FirstIfSingleOrDefault("0")},
|
|
|
|
{"page", "1"},
|
|
|
|
{"searchin", "filename"},
|
|
|
|
{"search", searchString}
|
|
|
|
};
|
2016-10-30 15:24:49 +00:00
|
|
|
searchUrl += "?" + queryCollection.GetQueryString();
|
|
|
|
|
|
|
|
var extraHeaders = new Dictionary<string, string>()
|
|
|
|
{
|
|
|
|
{ "X-Requested-With", "XMLHttpRequest" }
|
|
|
|
};
|
|
|
|
|
|
|
|
var response = await RequestStringWithCookiesAndRetry(searchUrl, null, SearchUrlReferer, extraHeaders);
|
|
|
|
|
|
|
|
var results = response.Content;
|
|
|
|
try
|
|
|
|
{
|
2020-02-28 21:22:13 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var dom = parser.ParseDocument(results);
|
2016-10-30 15:24:49 +00:00
|
|
|
|
2020-02-28 21:22:13 +00:00
|
|
|
var rows = dom.QuerySelectorAll("tr");
|
2016-10-30 15:24:49 +00:00
|
|
|
foreach (var row in rows.Skip(1))
|
|
|
|
{
|
|
|
|
var release = new ReleaseInfo();
|
2020-02-28 21:22:13 +00:00
|
|
|
var qTitleLink = row.QuerySelector("td:nth-of-type(2) a:nth-of-type(1)");
|
|
|
|
release.Title = qTitleLink.TextContent.Trim();
|
2016-10-30 15:24:49 +00:00
|
|
|
|
|
|
|
// If we search an get no results, we still get a table just with no info.
|
|
|
|
if (string.IsNullOrWhiteSpace(release.Title))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-28 21:22:13 +00:00
|
|
|
release.Guid = new Uri(qTitleLink.GetAttribute("href"));
|
2016-10-30 15:24:49 +00:00
|
|
|
release.Comments = release.Guid;
|
|
|
|
|
2020-02-28 21:22:13 +00:00
|
|
|
var dateString = row.QuerySelector("td:nth-of-type(5)").TextContent;
|
2016-10-30 15:24:49 +00:00
|
|
|
release.PublishDate = DateTime.ParseExact(dateString, "dd MMM yy", CultureInfo.InvariantCulture);
|
|
|
|
|
2020-02-28 21:22:13 +00:00
|
|
|
var qLink = row.QuerySelector("td:nth-of-type(3) a");
|
|
|
|
if (qLink != null) // newbie users don't see DL links
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-02-28 21:22:13 +00:00
|
|
|
release.Link = new Uri(qLink.GetAttribute("href"));
|
2016-10-30 16:52:41 +00:00
|
|
|
}
|
2017-04-15 08:45:10 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// use comments link as placeholder
|
|
|
|
// null causes errors during export to torznab
|
|
|
|
// skipping the release prevents newbie users from adding the tracker (empty result)
|
|
|
|
release.Link = release.Comments;
|
2016-11-05 18:33:44 +00:00
|
|
|
}
|
2016-10-30 15:24:49 +00:00
|
|
|
|
2020-02-28 21:22:13 +00:00
|
|
|
var sizeStr = row.QuerySelector("td:nth-of-type(6)").TextContent;
|
2016-10-30 15:24:49 +00:00
|
|
|
release.Size = ReleaseInfo.GetBytes(sizeStr);
|
|
|
|
|
2020-02-28 21:22:13 +00:00
|
|
|
var connections = row.QuerySelector("td:nth-of-type(8)").TextContent.Trim().Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
2016-10-30 15:24:49 +00:00
|
|
|
|
|
|
|
release.Seeders = ParseUtil.CoerceInt(connections[0].Trim());
|
|
|
|
release.Peers = ParseUtil.CoerceInt(connections[1].Trim()) + release.Seeders;
|
2016-10-30 19:24:28 +00:00
|
|
|
release.Grabs = ParseUtil.CoerceLong(connections[2].Trim());
|
2016-10-30 15:24:49 +00:00
|
|
|
|
2020-02-28 21:22:13 +00:00
|
|
|
var rCat = row.QuerySelector("td:nth-of-type(1) a").GetAttribute("href");
|
2016-10-30 15:24:49 +00:00
|
|
|
var rCatIdx = rCat.IndexOf("cat=");
|
|
|
|
if (rCatIdx > -1)
|
|
|
|
{
|
|
|
|
rCat = rCat.Substring(rCatIdx + 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
release.Category = MapTrackerCatToNewznab(rCat);
|
|
|
|
|
2020-02-28 21:22:13 +00:00
|
|
|
if (row.QuerySelector("img[alt=\"Gold Torrent\"]") != null)
|
2017-04-15 08:45:10 +00:00
|
|
|
release.DownloadVolumeFactor = 0;
|
2020-02-28 21:22:13 +00:00
|
|
|
else if (row.QuerySelector("img[alt=\"Silver Torrent\"]") != null)
|
2017-04-15 08:45:10 +00:00
|
|
|
release.DownloadVolumeFactor = 0.5;
|
2016-10-30 19:24:28 +00:00
|
|
|
else
|
|
|
|
release.DownloadVolumeFactor = 1;
|
|
|
|
|
2020-02-28 21:22:13 +00:00
|
|
|
var ULFactorImg = row.QuerySelector("img[alt*=\"x Multiplier Torrent\"]");
|
|
|
|
if (ULFactorImg != null)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-02-28 21:22:13 +00:00
|
|
|
release.UploadVolumeFactor = ParseUtil.CoerceDouble(ULFactorImg.GetAttribute("alt").Split('x')[0]);
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
release.UploadVolumeFactor = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
qTitleLink.Remove();
|
2020-02-28 21:22:13 +00:00
|
|
|
release.Description = row.QuerySelector("td:nth-of-type(2)").TextContent;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2016-10-30 15:24:49 +00:00
|
|
|
releases.Add(release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
OnParseError(results, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|