private IEnumerable <IndexerRequest> GetRequest(string searchParameters) { Authenticate(); var filter = ""; if (searchParameters == null) { if (Settings.RequireGolden) { filter = "&scene=2"; } } var request = new IndexerRequest( $"{Settings.BaseUrl.Trim().TrimEnd('/')}/torrents.php?action=advanced&json=noredirect&searchstr={searchParameters}{filter}", HttpAccept.Json); var cookies = AuthCookieCache.Find(Settings.BaseUrl.Trim().TrimEnd('/')); foreach (var cookie in cookies) { request.HttpRequest.Cookies[cookie.Key] = cookie.Value; } yield return(request); }
private void Authenticate() { var requestBuilder = new HttpRequestBuilder($"{Settings.BaseUrl.Trim().TrimEnd('/')}") { LogResponseContent = true }; requestBuilder.Method = HttpMethod.POST; requestBuilder.Resource("ajax.php?action=login"); requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); var authKey = Settings.BaseUrl.Trim().TrimEnd('/'); var cookies = AuthCookieCache.Find(authKey); if (cookies == null) { AuthCookieCache.Remove(authKey); var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) .AddFormParameter("password", Settings.Password) .AddFormParameter("passkey", Settings.Passkey) .AddFormParameter("keeplogged", "1") .AddFormParameter("login", "Log In!") .SetHeader("Content-Type", "multipart/form-data") .Accept(HttpAccept.Json) .Build(); var response = HttpClient.Execute(authLoginRequest); var result = Json.Deserialize <PassThePopcornAuthResponse>(response.Content); if (result.Result != "Ok" || string.IsNullOrWhiteSpace(result.Result)) { Logger.Debug("PassThePopcorn authentication failed."); throw new Exception("Failed to authenticate with PassThePopcorn."); } Logger.Debug("PassThePopcorn authentication succeeded."); cookies = response.GetCookies(); AuthCookieCache.Set(authKey, cookies, new TimeSpan(7, 0, 0, 0, 0)); // re-auth every 7 days requestBuilder.SetCookies(cookies); } else { requestBuilder.SetCookies(cookies); } }
private void Authenticate() { var requestBuilder = new HttpRequestBuilder($"{Settings.BaseUrl.Trim().TrimEnd('/')}") { LogResponseContent = true }; requestBuilder.Method = HttpMethod.POST; requestBuilder.Resource("login.php"); requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); var authKey = Settings.BaseUrl.Trim().TrimEnd('/'); var cookies = AuthCookieCache.Find(authKey); if (cookies == null) { AuthCookieCache.Remove(authKey); var authLoginRequest = requestBuilder .AddFormParameter("username", Settings.Username) .AddFormParameter("password", Settings.Password) .AddFormParameter("keeplogged", "1") .SetHeader("Content-Type", "multipart/form-data") .Accept(HttpAccept.Json) .Build(); var response = HttpClient.Execute(authLoginRequest); cookies = response.GetCookies(); AuthCookieCache.Set(authKey, cookies); } var index = GetIndex(cookies); if (index == null || index.Status.IsNullOrWhiteSpace() || index.Status != "success") { Logger.Debug("Gazelle authentication failed."); AuthCookieCache.Remove(authKey); throw new Exception("Failed to authenticate with Gazelle."); } Logger.Debug("Gazelle authentication succeeded."); Settings.AuthKey = index.Response.Authkey; Settings.PassKey = index.Response.Passkey; }
private IEnumerable <IndexerRequest> GetRequest(string searchParameters) { Authenticate(); var filter = ""; if (searchParameters == null) { } var request = new IndexerRequest( $"{Settings.BaseUrl.Trim().TrimEnd('/')}/ajax.php?action=browse&searchstr={searchParameters}{filter}", HttpAccept.Json); var cookies = AuthCookieCache.Find(Settings.BaseUrl.Trim().TrimEnd('/')); foreach (var cookie in cookies) { request.HttpRequest.Cookies[cookie.Key] = cookie.Value; } yield return(request); }