From 268a33464327aca0834391cb2131d6577c376bd9 Mon Sep 17 00:00:00 2001 From: john-miller-831985 <99450410+john-miller-831985@users.noreply.github.com> Date: Fri, 11 Feb 2022 15:59:17 -0600 Subject: [PATCH] IPTorrents fixes for Cloudflare (#12939) --- src/Jackett.Common/Indexers/IPTorrents.cs | 18 ++++++++++---- .../ConfigurationDataCookieUA.cs | 24 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/Jackett.Common/Models/IndexerConfig/ConfigurationDataCookieUA.cs diff --git a/src/Jackett.Common/Indexers/IPTorrents.cs b/src/Jackett.Common/Indexers/IPTorrents.cs index 0455efdbb..0d7fdd890 100644 --- a/src/Jackett.Common/Indexers/IPTorrents.cs +++ b/src/Jackett.Common/Indexers/IPTorrents.cs @@ -49,7 +49,7 @@ namespace Jackett.Common.Indexers "https://iptorrents.eu/" }; - private new ConfigurationDataCookie configData => (ConfigurationDataCookie)base.configData; + private new ConfigurationDataCookieUA configData => (ConfigurationDataCookieUA)base.configData; public IPTorrents(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps, ICacheService cs) @@ -81,7 +81,7 @@ namespace Jackett.Common.Indexers logger: l, p: ps, cacheService: cs, - configData: new ConfigurationDataCookie("For best results, change the 'Torrents per page' option to 100 and check the 'Torrents - Show files count' option in the website Settings.")) + configData: new ConfigurationDataCookieUA("For best results, change the 'Torrents per page' option to 100 and check the 'Torrents - Show files count' option in the website Settings.")) { Encoding = Encoding.UTF8; Language = "en-US"; @@ -177,6 +177,7 @@ namespace Jackett.Common.Indexers LoadValuesFromJson(configJson); CookieHeader = configData.Cookie.Value; + try { var results = await PerformQuery(new TorznabQuery()); @@ -190,7 +191,7 @@ namespace Jackett.Common.Indexers catch (Exception e) { IsConfigured = false; - throw new Exception("Your cookie did not work: " + e.Message); + throw new Exception("Your cookie did not work, make sure the user agent matches your computer: " + e.Message); } } @@ -200,6 +201,15 @@ namespace Jackett.Common.Indexers var qc = new NameValueCollection(); + + Dictionary headers = null; + + if (!string.IsNullOrEmpty(configData.UserAgent.Value)) + { + headers = new Dictionary(); + headers.Add("User-Agent", configData.UserAgent.Value); + } + if (query.IsImdbQuery) qc.Add("q", query.ImdbID); else if (!string.IsNullOrWhiteSpace(query.GetQueryString())) @@ -214,7 +224,7 @@ namespace Jackett.Common.Indexers qc.Add("o", ((SingleSelectConfigurationItem)configData.GetDynamic("sort")).Value); var searchUrl = SearchUrl + "?" + qc.GetQueryString(); - var response = await RequestWithCookiesAndRetryAsync(searchUrl, referer: SearchUrl); + var response = await RequestWithCookiesAndRetryAsync(searchUrl, referer: SearchUrl, headers: headers); var results = response.ContentString; if (results == null || !results.Contains("/lout.php")) diff --git a/src/Jackett.Common/Models/IndexerConfig/ConfigurationDataCookieUA.cs b/src/Jackett.Common/Models/IndexerConfig/ConfigurationDataCookieUA.cs new file mode 100644 index 000000000..3d5a24909 --- /dev/null +++ b/src/Jackett.Common/Models/IndexerConfig/ConfigurationDataCookieUA.cs @@ -0,0 +1,24 @@ +namespace Jackett.Common.Models.IndexerConfig +{ + public class ConfigurationDataCookieUA : ConfigurationData + { + public StringConfigurationItem Cookie { get; private set; } + public DisplayInfoConfigurationItem CookieInstructions { get; private set; } + public StringConfigurationItem UserAgent { get; private set; } + public DisplayInfoConfigurationItem UserAgentInstructions { get; private set; } + public DisplayInfoConfigurationItem Instructions { get; private set; } + + public ConfigurationDataCookieUA(string instructionMessageOptional = null) + { + Cookie = new StringConfigurationItem("Cookie"); + CookieInstructions = new DisplayInfoConfigurationItem("Cookie Instructions", + "Please enter the cookie for the site manually. See here on how get the cookies." + + "
Example cookie header (usually longer than this):
PHPSESSID=8rk27odm; ipsconnect_63ad9c=1; more_stuff=etc;"); + UserAgent = new StringConfigurationItem("User-Agent"); + UserAgentInstructions = new DisplayInfoConfigurationItem("User Agent Instructions", + "
  1. From the same place you fetched the cookie,
  2. Find 'user-agent:' in the Request Headers section
  3. Select" + + "and Copy the whole user-agent string (everything after 'user-agent: ') and Paste here.
"); + Instructions = new DisplayInfoConfigurationItem("", instructionMessageOptional); + } + } +}