From 351c399bfdafd6b90a4738c6762c32bcc974946c Mon Sep 17 00:00:00 2001 From: XYZJR <50780760+XYZJR@users.noreply.github.com> Date: Sun, 7 Feb 2021 15:04:29 +0100 Subject: [PATCH] Add new indexer TorrentParadise. resolves #4598 (#10997) --- README.md | 1 + .../Indexers/TorrentParadiseMl.cs | 162 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 src/Jackett.Common/Indexers/TorrentParadiseMl.cs diff --git a/README.md b/README.md index c39fad4f4..229234c0d 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ A third-party Golang SDK for Jackett is available from [webtor-io/go-jackett](ht * TOROS * Torrent Downloads (TD) * Torrent Oyun indir + * Torrent Paradise (ML) * torrent-pirat * Torrent4You * Torrent9 diff --git a/src/Jackett.Common/Indexers/TorrentParadiseMl.cs b/src/Jackett.Common/Indexers/TorrentParadiseMl.cs new file mode 100644 index 000000000..1d9ec3e2a --- /dev/null +++ b/src/Jackett.Common/Indexers/TorrentParadiseMl.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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; +using Newtonsoft.Json.Linq; +using NLog; + +namespace Jackett.Common.Indexers +{ + public class TorrentParadiseMl : BaseWebIndexer + { + private string ApiUrl => SiteLink + "api/"; + + public TorrentParadiseMl(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps, + ICacheService cs) + : base(id: "torrent-paradise-ml", + name: "Torrent Paradise (ML)", + description: "The most innovative torrent site", + link: "https://torrent-paradise.ml/", + caps: new TorznabCapabilities + { + TvSearchParams = new List + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep + }, + MovieSearchParams = new List + { + MovieSearchParam.Q + }, + MusicSearchParams = new List + { + MusicSearchParam.Q + }, + BookSearchParams = new List + { + BookSearchParam.Q + } + }, + configService: configService, + client: wc, + logger: l, + p: ps, + cacheService: cs, + configData: new ConfigurationData()) + { + Encoding = Encoding.UTF8; + Language = "en-us"; + Type = "public"; + + AddCategoryMapping(8000, TorznabCatType.Other); + } + + public override async Task ApplyConfiguration(JToken configJson) + { + LoadValuesFromJson(configJson); + + var query = new TorznabQuery { IsTest = true }; + var releases = await PerformQuery(query); + + await ConfigureIfOK(string.Empty, releases.Any(), + () => throw new Exception("Could not find releases from this URL")); + + return IndexerConfigurationStatus.Completed; + } + + protected override async Task> PerformQuery(TorznabQuery query) + { + var searchUrl = CreateSearchUrl(query); + if (string.IsNullOrWhiteSpace(searchUrl)) return new List(); + + var response = await RequestWithCookiesAndRetryAsync(searchUrl); + + try + { + var results = JsonConvert.DeserializeObject>(response.ContentString); + return results == null ? new List() : ConvertResultsIntoReleaseInfos(results); + } + catch (Exception ex) + { + throw new Exception("Error while parsing json: " + response.ContentString, ex); + } + } + + private string CreateSearchUrl(TorznabQuery query) + { + var searchTerm = query.GetQueryString(); + if (string.IsNullOrWhiteSpace(searchTerm)) + { + if (query.IsTest) + { + searchTerm = DateTime.Now.Year.ToString(); + } + else return null; + } + + var qc = new NameValueCollection + { + {"q", searchTerm} + }; + + return ApiUrl + "search?" + qc.GetQueryString(); + } + + private IEnumerable ConvertResultsIntoReleaseInfos(IEnumerable results) + { + foreach (var result in results) + { + yield return ConvertResultIntoReleaseInfo(result); + } + } + + private ReleaseInfo ConvertResultIntoReleaseInfo(TorrentParadiseResult result) + { + return new ReleaseInfo + { + Title = result.Text, + Size = result.Size, + Seeders = result.Seeders, + Peers = result.Seeders + result.Leechers, + InfoHash = result.Id, + PublishDate = DateTime.Now, + Details = new Uri(SiteLink), + DownloadVolumeFactor = 1, + UploadVolumeFactor = 1, + Category = new List { TorznabCatType.Other.ID } + }; + } + + private class TorrentParadiseResult + { + [JsonConstructor] + public TorrentParadiseResult(string id, string text, string len, string s, string l) + { + Id = id; + Text = text; + Size = ToLong(len); + Seeders = ToLong(s); + Leechers = ToLong(l); + } + + public string Id { get; } + + public string Text { get; } + + public long? Size { get; } + + public long? Seeders { get; } + + public long? Leechers { get; } + + private long? ToLong(string str) => Convert.ToInt64(str); + } + } +}