Skip to content

Commit

Permalink
IPTorrents fixes for Cloudflare (#12939)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-miller-831985 committed Feb 11, 2022
1 parent 49a0c2d commit 268a334
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Jackett.Common/Indexers/IPTorrents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class IPTorrents : BaseWebIndexer
"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)
Expand Down Expand Up @@ -81,7 +81,7 @@ public class IPTorrents : BaseWebIndexer
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";
Expand Down Expand Up @@ -177,6 +177,7 @@ public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken
LoadValuesFromJson(configJson);

CookieHeader = configData.Cookie.Value;

try
{
var results = await PerformQuery(new TorznabQuery());
Expand All @@ -190,7 +191,7 @@ public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken
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);
}
}

Expand All @@ -200,6 +201,15 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer

var qc = new NameValueCollection();


Dictionary<string, string> headers = null;

if (!string.IsNullOrEmpty(configData.UserAgent.Value))
{
headers = new Dictionary<string, string>();
headers.Add("User-Agent", configData.UserAgent.Value);
}

if (query.IsImdbQuery)
qc.Add("q", query.ImdbID);
else if (!string.IsNullOrWhiteSpace(query.GetQueryString()))
Expand All @@ -214,7 +224,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
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"))
Expand Down
Original file line number Diff line number Diff line change
@@ -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. <a href=\"https://github.com/Jackett/Jackett/wiki/Finding-cookies\" target=\"_blank\">See here</a> on how get the cookies." +
"<br>Example cookie header (usually longer than this):<br><code>PHPSESSID=8rk27odm; ipsconnect_63ad9c=1; more_stuff=etc;</code>");
UserAgent = new StringConfigurationItem("User-Agent");
UserAgentInstructions = new DisplayInfoConfigurationItem("User Agent Instructions",
"<ol><li>From the same place you fetched the cookie,<li>Find <b>'user-agent:'</b> in the <b>Request Headers</b> section<li><b>Select</b>" +
"and <b>Copy</b> the whole user-agent string <i>(everything after 'user-agent: ')</i> and <b>Paste</b> here.</ol>");
Instructions = new DisplayInfoConfigurationItem("", instructionMessageOptional);
}
}
}

0 comments on commit 268a334

Please sign in to comment.