diff --git a/src/Jackett/Content/logos/transmithenet.png b/src/Jackett/Content/logos/transmithenet.png new file mode 100644 index 0000000000000000000000000000000000000000..69f11cb56686569c553a5f9939518822202c7392 Binary files /dev/null and b/src/Jackett/Content/logos/transmithenet.png differ diff --git a/src/Jackett/Indexers/TransmitheNet.cs b/src/Jackett/Indexers/TransmitheNet.cs new file mode 100644 index 0000000000000000000000000000000000000000..e3b0f84c66a2126ce6fc7bd354a42292c18f4d1f --- /dev/null +++ b/src/Jackett/Indexers/TransmitheNet.cs @@ -0,0 +1,133 @@ +using Jackett.Models; +using Jackett.Services; +using Jackett.Utils; +using Jackett.Utils.Clients; +using Newtonsoft.Json.Linq; +using NLog; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Threading.Tasks; +using System.Web; +using Jackett.Models.IndexerConfig; +using AngleSharp.Parser.Html; +using System.Text.RegularExpressions; + +namespace Jackett.Indexers +{ + public class TransmitheNet : BaseIndexer, IIndexer + { + private string LoginUrl { get { return SiteLink + "login.php"; } } + private string SearchUrl { get { return SiteLink + "torrents.php"; } } + + new ConfigurationDataBasicLogin configData + { + get { return (ConfigurationDataBasicLogin)base.configData; } + set { base.configData = value; } + } + + public TransmitheNet(IIndexerManagerService i, Logger l, IWebClient c, IProtectionService ps) + : base(name: "TransmitTheNet", + description: " At Transmithe.net we will change the way you think about TV", + link: "https://transmithe.net/", + caps: TorznabUtil.CreateDefaultTorznabTVCaps(), + manager: i, + client: c, + logger: l, + p: ps, + configData: new ConfigurationDataBasicLogin("For best results, change the 'Torrents per page' setting to 100 in your profile on the TTN webpage.")) + { + } + + public async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson) + { + configData.LoadValuesFromJson(configJson); + var pairs = new Dictionary<string, string> { + { "username", configData.Username.Value }, + { "password", configData.Password.Value }, + { "keeplogged", "on" }, + { "login", "Login" } + }; + + CookieHeader = string.Empty; + var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, CookieHeader, true, null, LoginUrl); + + await ConfigureIfOK(response.Cookies, response.Content != null && response.Content.Contains("logout.php"), () => + { + var parser = new HtmlParser(); + var document = parser.Parse(response.Content); + var messageEl = document.QuerySelector("form > span[class='warning']"); + var errorMessage = messageEl.TextContent.Trim(); + throw new ExceptionWithConfigData(errorMessage, configData); + }); + return IndexerConfigurationStatus.RequiresTesting; + } + + public async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) + { + string Url; + if (string.IsNullOrEmpty(query.GetQueryString())) + Url = SearchUrl; + else + { + Url = $"{SearchUrl}?searchtext={HttpUtility.UrlEncode(query.GetQueryString())}"; + } + + var response = await RequestStringWithCookiesAndRetry(Url); + List<ReleaseInfo> releases = ParseResponse(response.Content); + + return releases; + } + + public List<ReleaseInfo> ParseResponse(string htmlResponse) + { + List<ReleaseInfo> releases = new List<ReleaseInfo>(); + + try + { + var parser = new HtmlParser(); + var document = parser.Parse(htmlResponse); + var rows = document.QuerySelectorAll(".torrent_table > tbody > tr:not(:First-child)"); + + foreach (var row in rows) + { + var release = new ReleaseInfo(); + + string title = row.QuerySelector("a[data-src]").GetAttribute("data-src"); + if (string.IsNullOrEmpty(title) || title == "0") + { + title = row.QuerySelector("a[data-src]").TextContent; + title = Regex.Replace(title, @"[\[\]\/]", ""); + } + else + { + title = title.Remove(title.LastIndexOf(".")); + } + + release.Title = title; + release.Description = release.Title; + release.Guid = new Uri(SiteLink + row.QuerySelector("a[data-src]").GetAttribute("href")); + release.Comments = release.Guid; + release.Link = new Uri(SiteLink + row.QuerySelector("a[href*='action=download']").GetAttribute("href")); + release.Category = TvCategoryParser.ParseTvShowQuality(release.Title); + + var timeAnchor = row.QuerySelector("span[class='time']"); + release.PublishDate = DateTime.ParseExact(timeAnchor.GetAttribute("title"), "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal); + release.Seeders = ParseUtil.CoerceInt(timeAnchor.ParentElement.NextElementSibling.NextElementSibling.TextContent.Trim()); + release.Peers = ParseUtil.CoerceInt(timeAnchor.ParentElement.NextElementSibling.NextElementSibling.NextElementSibling.TextContent.Trim()) + release.Seeders; + release.Size = ReleaseInfo.GetBytes(timeAnchor.ParentElement.PreviousElementSibling.TextContent); + release.MinimumRatio = 1; + release.MinimumSeedTime = 172800; + + releases.Add(release); + } + } + catch (Exception ex) + { + OnParseError(htmlResponse, ex); + } + + return releases; + } + } +} diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj index d771ae8137525d066fa82f6b4b8919e101a10a6f..99bea18e095e34adb9f1f5f4620df91d9f6f9f45 100644 --- a/src/Jackett/Jackett.csproj +++ b/src/Jackett/Jackett.csproj @@ -214,6 +214,7 @@ <Compile Include="Indexers\FileList.cs" /> <Compile Include="Indexers\Abstract\AvistazTracker.cs" /> <Compile Include="Indexers\FrenchADN.cs" /> + <Compile Include="Indexers\TransmitheNet.cs" /> <Compile Include="Indexers\WiHD.cs" /> <Compile Include="Indexers\XSpeeds.cs" /> <Compile Include="Models\GitHub\Asset.cs" /> @@ -576,6 +577,9 @@ <Content Include="Content\logos\torrentleech.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Content Include="Content\logos\transmithenet.png"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> <Content Include="Content\logos\tvchaosuk.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content>