From ad77068a7b5ece2291c125fb7ed756757618878d Mon Sep 17 00:00:00 2001 From: kaso17 Date: Fri, 22 Feb 2019 18:28:42 +0100 Subject: [PATCH] RARBG: make torrent download link optional --- src/Jackett.Common/Indexers/Rarbg.cs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Jackett.Common/Indexers/Rarbg.cs b/src/Jackett.Common/Indexers/Rarbg.cs index c41247256..c1f85b674 100644 --- a/src/Jackett.Common/Indexers/Rarbg.cs +++ b/src/Jackett.Common/Indexers/Rarbg.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; +using Jackett.Common.Helpers; using Jackett.Common.Models; using Jackett.Common.Models.IndexerConfig; using Jackett.Common.Services.Interfaces; @@ -37,6 +38,7 @@ namespace Jackett.Common.Indexers private DateTime lastTokenFetch; private string token; private string app_id; + private bool provideTorrentLink = false; private readonly TimeSpan TOKEN_DURATION = TimeSpan.FromMinutes(10); @@ -57,6 +59,10 @@ namespace Jackett.Common.Indexers Language = "en-us"; Type = "public"; + var provideTorrentLinkItem = new ConfigurationData.BoolItem { Value = false }; + provideTorrentLinkItem.Name = "Generate torrent download link additionally to magnet (not recommended due to DDoS protection)."; + configData.AddDynamic("providetorrentlink", provideTorrentLinkItem); + TorznabCaps.SupportsImdbSearch = true; webclient.requestDelay = 2.1; // The api has a 1req/2s limit. @@ -89,6 +95,17 @@ namespace Jackett.Common.Indexers app_id = "jackett_v" + EnvironmentUtil.JackettVersion; } + public override void LoadValuesFromJson(JToken jsonConfig, bool useProtectionService = false) + { + base.LoadValuesFromJson(jsonConfig, useProtectionService); + + var provideTorrentLinkItem = (ConfigurationData.BoolItem)configData.GetDynamic("providetorrentlink"); + if (provideTorrentLinkItem != null) + { + provideTorrentLink = provideTorrentLinkItem.Value; + } + } + private async Task CheckToken() { if (!HasValidToken) @@ -109,7 +126,7 @@ namespace Jackett.Common.Indexers public override async Task ApplyConfiguration(JToken configJson) { - configData.LoadValuesFromJson(configJson); + LoadValuesFromJson(configJson); var releases = await PerformQuery(new TorznabQuery()); await ConfigureIfOK(string.Empty, releases.Count() > 0, () => @@ -210,14 +227,15 @@ namespace Jackett.Common.Indexers foreach (var item in jsonContent.Value("torrent_results")) { var release = new ReleaseInfo(); - release.Title = item.Value("title"); + release.Title = WebUtilityHelpers.UrlDecode(item.Value("title"), Encoding); release.Category = MapTrackerCatDescToNewznab(item.Value("category")); release.MagnetUri = new Uri(item.Value("download")); release.InfoHash = release.MagnetUri.ToString().Split(':')[3].Split('&')[0]; release.Comments = new Uri(item.Value("info_page")); - release.Link = release.Comments; // in case of a torrent download we grab the link from the details page in Download() + if (provideTorrentLink) + release.Link = release.Comments; // in case of a torrent download we grab the link from the details page in Download() release.Guid = release.MagnetUri; var episode_info = item.Value("episode_info");