1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

Fixed: Can now specify a cookie for BitMeTv.

This commit is contained in:
Taloth Saldono 2015-03-14 16:06:46 +01:00
parent d1ce1bf218
commit 96469be7f0
5 changed files with 46 additions and 5 deletions

View File

@ -59,6 +59,15 @@ public HttpResponse Execute(HttpRequest request)
AddRequestHeaders(webRequest, request.Headers);
}
if (request.Cookies.Count != 0)
{
webRequest.CookieContainer = new CookieContainer();
foreach (var pair in request.Cookies)
{
webRequest.CookieContainer.Add(new Cookie(pair.Key, pair.Value, "/", request.Url.Host));
}
}
if (!request.Body.IsNullOrWhiteSpace())
{
var bytes = request.Headers.GetEncodingFromContentType().GetBytes(request.Body.ToCharArray());

View File

@ -14,6 +14,7 @@ public HttpRequest(string url, HttpAccept httpAccept = null)
Headers = new HttpHeader();
_segments = new Dictionary<string, string>();
AllowAutoRedirect = true;
Cookies = new Dictionary<string, string>();
if (httpAccept != null)
{
@ -44,6 +45,7 @@ public Uri Url
public NetworkCredential NetworkCredential { get; set; }
public bool SuppressHttpError { get; set; }
public bool AllowAutoRedirect { get; set; }
public Dictionary<string, string> Cookies { get; private set; }
public override string ToString()
{
@ -66,5 +68,20 @@ public void AddSegment(string segment, string value)
_segments.Add(key, value);
}
public void AddCookie(string key, string value)
{
Cookies[key] = value;
}
public void AddCookie(string cookies)
{
foreach (var pair in cookies.Split(';'))
{
var split = pair.Split('=');
Cookies[split[0].Trim()] = split[1].Trim();
}
}
}
}

View File

@ -20,7 +20,7 @@ public void Setup()
Subject.Definition = new IndexerDefinition()
{
Name = "BitMeTV",
Settings = new BitMeTvSettings()
Settings = new BitMeTvSettings() { Cookie = "uid=123" }
};
}

View File

@ -14,7 +14,7 @@ public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
{
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
pageableRequests.AddIfNotNull(GetRssRequests(null));
pageableRequests.AddIfNotNull(GetRssRequests());
return pageableRequests;
}
@ -44,9 +44,13 @@ public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpiso
return new List<IEnumerable<IndexerRequest>>();
}
private IEnumerable<IndexerRequest> GetRssRequests(String searchParameters)
private IEnumerable<IndexerRequest> GetRssRequests()
{
yield return new IndexerRequest(String.Format("{0}/rss.php?uid={1}&passkey={2}{3}", Settings.BaseUrl.Trim().TrimEnd('/'), Settings.UserId, Settings.RssPasskey, searchParameters), HttpAccept.Html);
var request = new IndexerRequest(String.Format("{0}/rss.php?uid={1}&passkey={2}", Settings.BaseUrl.Trim().TrimEnd('/'), Settings.UserId, Settings.RssPasskey), HttpAccept.Html);
request.HttpRequest.AddCookie(Settings.Cookie);
yield return request;
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Text.RegularExpressions;
using FluentValidation;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
@ -14,6 +15,13 @@ public BitMeTvSettingsValidator()
RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.UserId).NotEmpty();
RuleFor(c => c.RssPasskey).NotEmpty();
RuleFor(c => c.Cookie).NotEmpty();
RuleFor(c => c.Cookie)
.Matches(@"pass=[0-9a-f]{32}", RegexOptions.IgnoreCase)
.WithMessage("Wrong pattern")
.AsWarning();
}
}
@ -23,7 +31,7 @@ public class BitMeTvSettings : IProviderConfig
public BitMeTvSettings()
{
BaseUrl = "http://www.bitmetv.org";
BaseUrl = "https://www.bitmetv.org";
}
[FieldDefinition(0, Label = "Website URL")]
@ -35,6 +43,9 @@ public BitMeTvSettings()
[FieldDefinition(2, Label = "RSS Passkey")]
public String RssPasskey { get; set; }
[FieldDefinition(3, Label = "Cookie", HelpText = "BitMeTv uses a login cookie needed to access the rss, you'll have to retrieve it via a browser.")]
public String Cookie { get; set; }
public ValidationResult Validate()
{
return validator.Validate(this);