mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 18:42:42 +01:00
Use username, password and passkey for passthepopcorn
This commit is contained in:
parent
4c5900373d
commit
6af6da16b4
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using RestSharp;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.PassThePopcorn
|
||||
{
|
||||
@ -54,14 +54,42 @@ public virtual IndexerPageableRequestChain GetSearchRequests(SeasonSearchCriteri
|
||||
|
||||
private IEnumerable<IndexerRequest> GetRequest(string searchParameters)
|
||||
{
|
||||
var request = new IndexerRequest(string.Format("{0}/torrents.php?json=noredirect&searchstr={1}", Settings.BaseUrl.Trim().TrimEnd('/'), searchParameters), HttpAccept.Json);
|
||||
var request =
|
||||
new IndexerRequest(
|
||||
$"{Settings.BaseUrl.Trim().TrimEnd('/')}/torrents.php?json=noredirect&searchstr={searchParameters}",
|
||||
HttpAccept.Json);
|
||||
|
||||
foreach (var cookie in HttpHeader.ParseCookies(Settings.Cookie))
|
||||
var cookies = GetPTPCookies();
|
||||
foreach (var cookie in cookies)
|
||||
{
|
||||
request.HttpRequest.Cookies[cookie.Key] = cookie.Value;
|
||||
request.HttpRequest.Cookies[cookie.Name] = cookie.Value;
|
||||
}
|
||||
|
||||
yield return request;
|
||||
}
|
||||
|
||||
private IList<RestResponseCookie> GetPTPCookies()
|
||||
{
|
||||
var client = new RestClient(Settings.BaseUrl.Trim().TrimEnd('/'));
|
||||
var request = new RestRequest("/ajax.php?action=login", Method.POST);
|
||||
request.AddParameter("username", Settings.Username);
|
||||
request.AddParameter("password", Settings.Password);
|
||||
request.AddParameter("passkey", Settings.Passkey);
|
||||
request.AddParameter("keeplogged", "1");
|
||||
request.AddParameter("login", "Log In!");
|
||||
request.AddHeader("Content-Type", "multipart/form-data");
|
||||
|
||||
IRestResponse response = client.Execute(request);
|
||||
var content = response.Content;
|
||||
|
||||
var jsonResponse = JObject.Parse(content);
|
||||
if (content != null && (string)jsonResponse["Result"] != "Error")
|
||||
{
|
||||
return response.Cookies;
|
||||
}
|
||||
|
||||
throw new Exception("Error connecting to PTP invalid username, password, or passkey");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,9 @@ public class PassThePopcornSettingsValidator : AbstractValidator<PassThePopcornS
|
||||
public PassThePopcornSettingsValidator()
|
||||
{
|
||||
RuleFor(c => c.BaseUrl).ValidRootUrl();
|
||||
RuleFor(c => c.Cookie).NotEmpty();
|
||||
|
||||
RuleFor(c => c.Cookie)
|
||||
.Matches(@"__cfduid=[0-9a-f]{43}", RegexOptions.IgnoreCase)
|
||||
.WithMessage("Wrong pattern")
|
||||
.AsWarning();
|
||||
RuleFor(c => c.Username).NotEmpty();
|
||||
RuleFor(c => c.Password).NotEmpty();
|
||||
RuleFor(c => c.Passkey).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,22 +26,28 @@ public PassThePopcornSettings()
|
||||
BaseUrl = "https://passthepopcorn.me";
|
||||
}
|
||||
|
||||
[FieldDefinition(0, Label = "API URL", Advanced = true, HelpText = "Do not change this unless you know what you're doing. Since your cookie will be sent to that host.")]
|
||||
[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 = "Cookie", HelpText = "PassThePopcorn uses a login cookie needed to access the API, you'll have to retrieve it via a browser.")]
|
||||
public string Cookie { get; set; }
|
||||
[FieldDefinition(1, Label = "Username", HelpText = "PTP Username")]
|
||||
public string Username { get; set; }
|
||||
|
||||
[FieldDefinition(2, Type = FieldType.Checkbox, Label = "Prefer Golden", HelpText = "Favors Golden Popcorn-releases over all other releases.")]
|
||||
[FieldDefinition(2, Label = "Password", HelpText = "PTP Password")]
|
||||
public string Password { get; set; }
|
||||
|
||||
[FieldDefinition(3, Label = "Passkey", Type = FieldType.Password, HelpText = "PTP Passkey")]
|
||||
public string Passkey { get; set; }
|
||||
|
||||
[FieldDefinition(4, Label = "Prefer Golden", Type = FieldType.Checkbox , HelpText = "Favors Golden Popcorn-releases over all other releases.")]
|
||||
public bool Golden { get; set; }
|
||||
|
||||
[FieldDefinition(3, Type = FieldType.Checkbox, Label = "Prefer Scene", HelpText = "Favors scene-releases over non-scene releases.")]
|
||||
[FieldDefinition(5, Label = "Prefer Scene", Type = FieldType.Checkbox, HelpText = "Favors scene-releases over non-scene releases.")]
|
||||
public bool Scene { get; set; }
|
||||
|
||||
[FieldDefinition(4, Type = FieldType.Checkbox, Label = "Require Approved", HelpText = "Require staff-approval for releases to be accepted.")]
|
||||
[FieldDefinition(6, Label = "Require Approved", Type = FieldType.Checkbox, HelpText = "Require staff-approval for releases to be accepted.")]
|
||||
public bool Approved { get; set; }
|
||||
|
||||
[FieldDefinition(5, Type = FieldType.Checkbox, Label = "Require Golden", HelpText = "Require Golden Popcorn-releases for releases to be accepted.")]
|
||||
[FieldDefinition(7, Label = "Require Golden", Type = FieldType.Checkbox, HelpText = "Require Golden Popcorn-releases for releases to be accepted.")]
|
||||
public bool RequireGolden { get; set; }
|
||||
|
||||
public NzbDroneValidationResult Validate()
|
||||
|
Loading…
Reference in New Issue
Block a user