diff --git a/src/NzbDrone.Core/HealthCheck/Checks/PTPOldSettingsCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/PTPOldSettingsCheck.cs new file mode 100644 index 000000000..d908f32ae --- /dev/null +++ b/src/NzbDrone.Core/HealthCheck/Checks/PTPOldSettingsCheck.cs @@ -0,0 +1,32 @@ +using System.Linq; +using NzbDrone.Common.Extensions; +using NzbDrone.Core.Indexers; +using NzbDrone.Core.Indexers.PassThePopcorn; + +namespace NzbDrone.Core.HealthCheck.Checks +{ + public class PTPOldSettingsCheck : HealthCheckBase + { + private readonly IIndexerFactory _indexerFactory; + + public PTPOldSettingsCheck(IIndexerFactory indexerFactory) + { + _indexerFactory = indexerFactory; + } + + public override HealthCheck Check() + { + var ptpIndexers = _indexerFactory.All().Where(i => i.Settings.GetType() == typeof(PassThePopcornSettings)); + + var ptpIndexerOldSettings = ptpIndexers + .Where(i => (i.Settings as PassThePopcornSettings).APIUser.IsNullOrWhiteSpace()).Select(i => i.Name); + + if (ptpIndexerOldSettings.Count() > 0) + { + return new HealthCheck(GetType(), HealthCheckResult.Warning, $"The following PassThePopcorn indexers have deprecated settings and should be updated: {string.Join(",", ptpIndexerOldSettings)}"); + } + + return new HealthCheck(GetType()); + } + } +} diff --git a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornRequestGenerator.cs b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornRequestGenerator.cs index e2099dbc5..eb966252d 100644 --- a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornRequestGenerator.cs @@ -4,6 +4,7 @@ using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Common.Cache; using NLog; +using NzbDrone.Common.Extensions; using NzbDrone.Common.Serializer; namespace NzbDrone.Core.Indexers.PassThePopcorn @@ -39,21 +40,34 @@ public IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchC private IEnumerable GetRequest(string searchParameters) { - Cookies = GetCookies(); - - Authenticate(); - var request = new IndexerRequest( $"{Settings.BaseUrl.Trim().TrimEnd('/')}/torrents.php?action=advanced&json=noredirect&searchstr={searchParameters}", HttpAccept.Json); - - foreach (var cookie in Cookies) + + if (Settings.APIKey.IsNullOrWhiteSpace()) { - request.HttpRequest.Cookies[cookie.Key] = cookie.Value; + Cookies = GetCookies(); + + Authenticate(); + + Logger.Warn("You are using the old method of logging into PassThePopcorn. Please switch to the new method using APIUser & APIKey."); + } + else + { + request.HttpRequest.Headers["ApiUser"] = Settings.APIUser; + request.HttpRequest.Headers["ApiKey"] = Settings.APIKey; } - CookiesUpdater(Cookies, DateTime.Now + TimeSpan.FromDays(30)); + if (Settings.APIKey.IsNullOrWhiteSpace()) + { + foreach (var cookie in Cookies) + { + request.HttpRequest.Cookies[cookie.Key] = cookie.Value; + } + + CookiesUpdater(Cookies, DateTime.Now + TimeSpan.FromDays(30)); + } yield return request; } diff --git a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornSettings.cs b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornSettings.cs index 3e998299f..04501f809 100644 --- a/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornSettings.cs +++ b/src/NzbDrone.Core/Indexers/PassThePopcorn/PassThePopcornSettings.cs @@ -14,9 +14,11 @@ public class PassThePopcornSettingsValidator : AbstractValidator c.BaseUrl).ValidRootUrl(); - RuleFor(c => c.Username).NotEmpty(); - RuleFor(c => c.Password).NotEmpty(); - RuleFor(c => c.Passkey).NotEmpty(); + RuleFor(c => c.Username).Empty(); + RuleFor(c => c.Password).Empty(); + RuleFor(c => c.Passkey).Empty(); + RuleFor(c => c.APIUser).NotEmpty(); + RuleFor(c => c.APIKey).NotEmpty(); } } @@ -33,22 +35,28 @@ public PassThePopcornSettings() [FieldDefinition(0, Label = "URL", Advanced = true, HelpText = "Do not change this unless you know what you're doing. Since your cookie will be sent to that host.")] public string BaseUrl { get; set; } - [FieldDefinition(1, Label = "Username", HelpText = "PTP Username")] + [FieldDefinition(1, Label = "APIUser", HelpText = "These settings are found in your PassThePopcorn security settings (Edit Profile > Security).")] + public string APIUser { get; set; } + + [FieldDefinition(2, Label = "APIKey", Type = FieldType.Password)] + public string APIKey { get; set; } + + [FieldDefinition(3, Label = "DEPRECATED: User", HelpText = "Please use APIKey & APIUser instead. PTP Username")] public string Username { get; set; } - [FieldDefinition(2, Label = "Password", Type = FieldType.Password, HelpText = "PTP Password")] + [FieldDefinition(4, Label = "DEPRECATED: Pass", Type = FieldType.Password, HelpText = "Please use APIKey & APIUser instead. PTP Password")] public string Password { get; set; } - [FieldDefinition(3, Label = "Passkey", HelpText = "PTP Passkey")] + [FieldDefinition(5, Label = "DEPRECATED: Passkey", HelpText = "Please use APIKey & APIUser instead. PTP Passkey")] public string Passkey { get; set; } - [FieldDefinition(4, Type = FieldType.Tag, SelectOptions = typeof(Language), Label = "Multi Languages", HelpText = "What languages are normally in a multi release on this indexer?", Advanced = true)] + [FieldDefinition(6, Type = FieldType.Tag, SelectOptions = typeof(Language), Label = "Multi Languages", HelpText = "What languages are normally in a multi release on this indexer?", Advanced = true)] public IEnumerable MultiLanguages { get; set; } - [FieldDefinition(5, Type = FieldType.Textbox, Label = "Minimum Seeders", HelpText = "Minimum number of seeders required.", Advanced = true)] + [FieldDefinition(7, Type = FieldType.Textbox, Label = "Minimum Seeders", HelpText = "Minimum number of seeders required.", Advanced = true)] public int MinimumSeeders { get; set; } - [FieldDefinition(6, Type = FieldType.Tag, SelectOptions = typeof(IndexerFlags), Label = "Required Flags", HelpText = "What indexer flags are required?", HelpLink = "https://github.com/Radarr/Radarr/wiki/Indexer-Flags#1-required-flags", Advanced = true)] + [FieldDefinition(8, Type = FieldType.Tag, SelectOptions = typeof(IndexerFlags), Label = "Required Flags", HelpText = "What indexer flags are required?", HelpLink = "https://github.com/Radarr/Radarr/wiki/Indexer-Flags#1-required-flags", Advanced = true)] public IEnumerable RequiredFlags { get; set; } public NzbDroneValidationResult Validate() diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 691004d60..b691b348d 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -151,6 +151,7 @@ + @@ -1326,4 +1327,4 @@ --> - + \ No newline at end of file