mirror of https://github.com/Jackett/Jackett
commit
560a413d19
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
|
@ -29,9 +29,9 @@ namespace Jackett.Controllers
|
|||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<HttpResponseMessage> Call(string indexerName)
|
||||
public async Task<HttpResponseMessage> Call(string indexerID)
|
||||
{
|
||||
var indexer = indexerService.GetIndexer(indexerName);
|
||||
var indexer = indexerService.GetIndexer(indexerID);
|
||||
var torznabQuery = TorznabQuery.FromHttpQuery(HttpUtility.ParseQueryString(Request.RequestUri.Query));
|
||||
|
||||
if (string.Equals(torznabQuery.QueryType, "caps", StringComparison.InvariantCultureIgnoreCase))
|
||||
|
@ -70,7 +70,7 @@ namespace Jackett.Controllers
|
|||
continue;
|
||||
var originalLink = release.Link;
|
||||
var encodedLink = HttpServerUtility.UrlTokenEncode(Encoding.UTF8.GetBytes(originalLink.ToString())) + "/download.torrent";
|
||||
var proxyLink = string.Format("{0}api/{1}/download/{2}", severUrl, indexer.DisplayName, encodedLink);
|
||||
var proxyLink = string.Format("{0}api/{1}/download/{2}", severUrl, indexer.ID, encodedLink);
|
||||
release.Link = new Uri(proxyLink);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@ namespace Jackett.Controllers
|
|||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<HttpResponseMessage> Download(string indexerName, string path)
|
||||
public async Task<HttpResponseMessage> Download(string indexerID, string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
var indexer = indexerService.GetIndexer(indexerName);
|
||||
var indexer = indexerService.GetIndexer(indexerID);
|
||||
var remoteFile = Encoding.UTF8.GetString(HttpServerUtility.UrlTokenDecode(path));
|
||||
var downloadBytes = await indexer.Download(new Uri(remoteFile));
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace Jackett.Controllers
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error(e, "Error downloading " + indexerName + " " + path);
|
||||
logger.Error(e, "Error downloading " + indexerID + " " + path);
|
||||
return new HttpResponseMessage(HttpStatusCode.NotFound);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,28 +130,7 @@ namespace Jackett.Indexers
|
|||
release.Link = new Uri(BaseUrl + "/" + qDownload.Attr("href"));
|
||||
|
||||
var dateStr = row.ChildElements.ElementAt(3).Cq().Text().Trim().Replace(" and", "");
|
||||
var dateParts = dateStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
TimeSpan timeAgo = TimeSpan.Zero;
|
||||
for (var i = 0; i < dateParts.Length / 2; i++)
|
||||
{
|
||||
var val = ParseUtil.CoerceInt(dateParts[i * 2]);
|
||||
var unit = dateParts[i * 2 + 1];
|
||||
if (unit.Contains("sec"))
|
||||
timeAgo += TimeSpan.FromSeconds(val);
|
||||
else if (unit.Contains("min"))
|
||||
timeAgo += TimeSpan.FromMinutes(val);
|
||||
else if (unit.Contains("hour"))
|
||||
timeAgo += TimeSpan.FromHours(val);
|
||||
else if (unit.Contains("day"))
|
||||
timeAgo += TimeSpan.FromDays(val);
|
||||
else if (unit.Contains("week"))
|
||||
timeAgo += TimeSpan.FromDays(val * 7);
|
||||
else if (unit.Contains("month"))
|
||||
timeAgo += TimeSpan.FromDays(val * 30);
|
||||
else if (unit.Contains("year"))
|
||||
timeAgo += TimeSpan.FromDays(val * 365);
|
||||
}
|
||||
release.PublishDate = DateTime.SpecifyKind(DateTime.Now - timeAgo, DateTimeKind.Local);
|
||||
release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);
|
||||
|
||||
var sizeStr = row.ChildElements.ElementAt(4).Cq().Text().Trim();
|
||||
var sizeParts = sizeStr.Split(' ');
|
||||
|
|
|
@ -114,24 +114,7 @@ namespace Jackett.Indexers
|
|||
release.Guid = release.Comments;
|
||||
|
||||
var dateStr = descCol.ChildElements.Last().Cq().Text().Split('|').Last().ToLowerInvariant().Replace("ago.", "").Trim();
|
||||
var dateParts = dateStr.Split(new char[] { ' ', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var timeSpan = TimeSpan.Zero;
|
||||
for (var i = 0; i < dateParts.Length / 2; i++)
|
||||
{
|
||||
var timeVal = ParseUtil.CoerceInt(dateParts[i * 2]);
|
||||
var timeUnit = dateParts[i * 2 + 1];
|
||||
if (timeUnit.Contains("year"))
|
||||
timeSpan += TimeSpan.FromDays(365 * timeVal);
|
||||
else if (timeUnit.Contains("month"))
|
||||
timeSpan += TimeSpan.FromDays(30 * timeVal);
|
||||
else if (timeUnit.Contains("day"))
|
||||
timeSpan += TimeSpan.FromDays(timeVal);
|
||||
else if (timeUnit.Contains("hour"))
|
||||
timeSpan += TimeSpan.FromHours(timeVal);
|
||||
else if (timeUnit.Contains("min"))
|
||||
timeSpan += TimeSpan.FromMinutes(timeVal);
|
||||
}
|
||||
release.PublishDate = DateTime.SpecifyKind(DateTime.Now - timeSpan, DateTimeKind.Local);
|
||||
release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);
|
||||
|
||||
var sizeEl = row.ChildElements.ElementAt(7);
|
||||
var sizeVal = ParseUtil.CoerceFloat(sizeEl.ChildNodes.First().NodeValue);
|
||||
|
|
|
@ -169,22 +169,7 @@ namespace Jackett.Indexers
|
|||
|
||||
string fullSize = qRow.Find("td.mainblockcontent").Get(6).InnerText;
|
||||
string[] sizeSplit = fullSize.Split(' ');
|
||||
switch (sizeSplit[1].ToLower())
|
||||
{
|
||||
case "kb":
|
||||
size = ReleaseInfo.BytesFromKB(ParseUtil.CoerceFloat(sizeSplit[0]));
|
||||
break;
|
||||
case "mb":
|
||||
size = ReleaseInfo.BytesFromMB(ParseUtil.CoerceFloat(sizeSplit[0]));
|
||||
break;
|
||||
case "gb":
|
||||
size = ReleaseInfo.BytesFromGB(ParseUtil.CoerceFloat(sizeSplit[0]));
|
||||
break;
|
||||
default:
|
||||
size = null;
|
||||
break;
|
||||
}
|
||||
release.Size = size;
|
||||
release.Size = ReleaseInfo.GetBytes(sizeSplit[1], ParseUtil.CoerceFloat(sizeSplit[0]));
|
||||
|
||||
release.Guid = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent b a").Attr("href"));
|
||||
release.Link = new Uri(SiteLink + "/" + qRow.Find("td.mainblockcontent").Get(3).FirstChild.GetAttribute("href"));
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace Jackett.Indexers
|
|||
logger: l)
|
||||
{
|
||||
SearchUrl = SiteLink + "t?q=";
|
||||
webclient =wc;
|
||||
webclient = wc;
|
||||
}
|
||||
|
||||
public Task<ConfigurationData> GetConfigurationForSetup()
|
||||
|
@ -58,7 +58,8 @@ namespace Jackett.Indexers
|
|||
Url = SiteLink.ToString(),
|
||||
PostData = pairs,
|
||||
Referer = SiteLink.ToString(),
|
||||
Type = RequestType.POST
|
||||
Type = RequestType.POST,
|
||||
AutoRedirect = true
|
||||
});
|
||||
|
||||
cookieHeader = response.Cookies;
|
||||
|
@ -91,16 +92,7 @@ namespace Jackett.Indexers
|
|||
}
|
||||
}
|
||||
|
||||
HttpRequestMessage CreateHttpRequest(Uri uri)
|
||||
{
|
||||
var message = new HttpRequestMessage();
|
||||
message.Method = HttpMethod.Get;
|
||||
message.RequestUri = uri;
|
||||
message.Headers.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent);
|
||||
return message;
|
||||
}
|
||||
|
||||
public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig)
|
||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||
{
|
||||
cookieHeader = (string)jsonConfig["cookies"];
|
||||
IsConfigured = true;
|
||||
|
@ -137,27 +129,10 @@ namespace Jackett.Indexers
|
|||
release.Guid = new Uri(SiteLink + qTitleLink.Attr("href"));
|
||||
release.Comments = release.Guid;
|
||||
|
||||
DateTime pubDate;
|
||||
var descString = qRow.Find(".t_ctime").Text();
|
||||
var dateString = descString.Split('|').Last().Trim();
|
||||
dateString = dateString.Split(new string[] { " by " }, StringSplitOptions.None)[0];
|
||||
var dateValue = ParseUtil.CoerceFloat(dateString.Split(' ')[0]);
|
||||
var dateUnit = dateString.Split(' ')[1];
|
||||
if (dateUnit.Contains("minute"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromMinutes(dateValue);
|
||||
else if (dateUnit.Contains("hour"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromHours(dateValue);
|
||||
else if (dateUnit.Contains("day"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(dateValue);
|
||||
else if (dateUnit.Contains("week"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(7 * dateValue);
|
||||
else if (dateUnit.Contains("month"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(30 * dateValue);
|
||||
else if (dateUnit.Contains("year"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(365 * dateValue);
|
||||
else
|
||||
pubDate = DateTime.MinValue;
|
||||
release.PublishDate = pubDate;
|
||||
release.PublishDate = DateTimeUtil.FromTimeAgo(dateString);
|
||||
|
||||
var qLink = row.ChildElements.ElementAt(3).Cq().Children("a");
|
||||
release.Link = new Uri(SiteLink + qLink.Attr("href"));
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Jackett.Models;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NLog;
|
||||
using Jackett.Utils;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using CsQuery;
|
||||
using System.Web;
|
||||
using Jackett.Services;
|
||||
using Jackett.Utils.Clients;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Jackett.Indexers
|
||||
{
|
||||
public class PrivateHD : BaseIndexer, IIndexer
|
||||
{
|
||||
private readonly string LoginUrl = "";
|
||||
private readonly string SearchUrl = "";
|
||||
private string cookieHeader = "";
|
||||
|
||||
private IWebClient webclient;
|
||||
|
||||
public PrivateHD(IIndexerManagerService i, IWebClient wc, Logger l)
|
||||
: base(name: "PrivateHD",
|
||||
description: "BitTorrent site for High Quality, High Definition (HD) movies and TV Shows",
|
||||
link: new Uri("https://privatehd.to"),
|
||||
caps: TorznabCapsUtil.CreateDefaultTorznabTVCaps(),
|
||||
manager: i,
|
||||
logger: l)
|
||||
{
|
||||
LoginUrl = SiteLink + "auth/login";
|
||||
SearchUrl = SiteLink + "torrents?in=1&type=2&search={0}";
|
||||
webclient = wc;
|
||||
}
|
||||
|
||||
public async Task ApplyConfiguration(JToken configJson)
|
||||
{
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
|
||||
var loginPage = await webclient.GetString(new Utils.Clients.WebRequest()
|
||||
{
|
||||
Url = LoginUrl,
|
||||
Type = RequestType.GET,
|
||||
AutoRedirect = true,
|
||||
});
|
||||
|
||||
var token = new Regex("Avz.CSRF_TOKEN = '(.*?)';").Match(loginPage.Content).Groups[1].ToString();
|
||||
var pairs = new Dictionary<string, string> {
|
||||
{ "_token", token },
|
||||
{ "username_email", config.Username.Value },
|
||||
{ "password", config.Password.Value },
|
||||
{ "remember", "on" }
|
||||
};
|
||||
|
||||
var response = await webclient.GetString(new Utils.Clients.WebRequest()
|
||||
{
|
||||
Url = LoginUrl,
|
||||
PostData = pairs,
|
||||
Referer = LoginUrl,
|
||||
Type = RequestType.POST,
|
||||
AutoRedirect = true,
|
||||
Cookies = loginPage.Cookies
|
||||
});
|
||||
|
||||
if (!response.Content.Contains("auth/logout"))
|
||||
{
|
||||
CQ dom = response.Content;
|
||||
var messageEl = dom[".form-error"];
|
||||
var errorMessage = messageEl.Text().Trim();
|
||||
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
|
||||
}
|
||||
else
|
||||
{
|
||||
cookieHeader = response.Cookies;
|
||||
var configSaveData = new JObject();
|
||||
configSaveData["cookies"] = cookieHeader;
|
||||
SaveConfig(configSaveData);
|
||||
IsConfigured = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<byte[]> Download(Uri link)
|
||||
{
|
||||
var response = await webclient.GetBytes(new Utils.Clients.WebRequest()
|
||||
{
|
||||
Url = link.ToString(),
|
||||
Cookies = cookieHeader
|
||||
});
|
||||
|
||||
return response.Content;
|
||||
}
|
||||
|
||||
public Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
return Task.FromResult<ConfigurationData>(config);
|
||||
}
|
||||
|
||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||
{
|
||||
cookieHeader = (string)jsonConfig["cookies"];
|
||||
IsConfigured = true;
|
||||
}
|
||||
|
||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||
|
||||
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
|
||||
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
|
||||
|
||||
var response = await webclient.GetString(new Utils.Clients.WebRequest()
|
||||
{
|
||||
Url = episodeSearchUrl,
|
||||
Referer = SiteLink.ToString(),
|
||||
Cookies = cookieHeader
|
||||
});
|
||||
var results = response.Content;
|
||||
|
||||
try
|
||||
{
|
||||
CQ dom = results;
|
||||
var rows = dom["table > tbody > tr"];
|
||||
foreach (var row in rows)
|
||||
{
|
||||
CQ qRow = row.Cq();
|
||||
var release = new ReleaseInfo();
|
||||
|
||||
release.MinimumRatio = 1;
|
||||
release.MinimumSeedTime = 172800;
|
||||
|
||||
var qLink = row.ChildElements.ElementAt(1).FirstElementChild.Cq();
|
||||
release.Title = qLink.Text().Trim();
|
||||
release.Comments = new Uri(qLink.Attr("href"));
|
||||
release.Guid = release.Comments;
|
||||
|
||||
var qDownload = row.ChildElements.ElementAt(3).FirstElementChild.Cq();
|
||||
release.Link = new Uri(qDownload.Attr("href"));
|
||||
|
||||
var dateStr = row.ChildElements.ElementAt(5).Cq().Text().Trim();
|
||||
release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);
|
||||
|
||||
var sizeStr = row.ChildElements.ElementAt(6).Cq().Text().Trim();
|
||||
var sizeParts = sizeStr.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
|
||||
release.Size = ReleaseInfo.GetBytes(sizeParts[1], ParseUtil.CoerceFloat(sizeParts[0]));
|
||||
|
||||
release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(8).Cq().Text());
|
||||
release.Peers = ParseUtil.CoerceInt(row.ChildElements.ElementAt(9).Cq().Text()) + release.Seeders;
|
||||
|
||||
releases.Add(release);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnParseError(results, ex);
|
||||
}
|
||||
return releases.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -137,24 +137,7 @@ namespace Jackett.Indexers
|
|||
release.Size = ReleaseInfo.GetBytes(sizeParts[1], ParseUtil.CoerceFloat(sizeParts[0]));
|
||||
|
||||
var dateStr = qRow.Find(".ulInfo").Text().Split('|').Last().Trim();
|
||||
var dateParts = dateStr.Split(' ');
|
||||
var dateValue = ParseUtil.CoerceInt(dateParts[0]);
|
||||
TimeSpan ts = TimeSpan.Zero;
|
||||
if (dateStr.Contains("sec"))
|
||||
ts = TimeSpan.FromSeconds(dateValue);
|
||||
else if (dateStr.Contains("min"))
|
||||
ts = TimeSpan.FromMinutes(dateValue);
|
||||
else if (dateStr.Contains("hour"))
|
||||
ts = TimeSpan.FromHours(dateValue);
|
||||
else if (dateStr.Contains("day"))
|
||||
ts = TimeSpan.FromDays(dateValue);
|
||||
else if (dateStr.Contains("week"))
|
||||
ts = TimeSpan.FromDays(dateValue * 7);
|
||||
else if (dateStr.Contains("month"))
|
||||
ts = TimeSpan.FromDays(dateValue * 30);
|
||||
else if (dateStr.Contains("year"))
|
||||
ts = TimeSpan.FromDays(dateValue * 365);
|
||||
release.PublishDate = DateTime.Now - ts;
|
||||
release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);
|
||||
|
||||
release.Seeders = ParseUtil.CoerceInt(qRow.Find(".seedersInfo").Text());
|
||||
release.Peers = ParseUtil.CoerceInt(qRow.Find(".leechersInfo").Text()) + release.Seeders;
|
||||
|
|
|
@ -118,31 +118,7 @@ namespace Jackett.Indexers
|
|||
release.Link = new Uri(SiteLink + "/" + qRow.Find(".torrent_handle_links > a").First().Attr("href"));
|
||||
|
||||
var dateStr = qRow.Find(".time").Text().Trim();
|
||||
if (dateStr.ToLower().Contains("just now"))
|
||||
release.PublishDate = DateTime.Now;
|
||||
else
|
||||
{
|
||||
var dateParts = dateStr.Split(' ');
|
||||
var dateValue = ParseUtil.CoerceInt(dateParts[0]);
|
||||
TimeSpan ts = TimeSpan.Zero;
|
||||
if (dateStr.Contains("Just now"))
|
||||
ts = TimeSpan.Zero;
|
||||
else if (dateStr.Contains("sec"))
|
||||
ts = TimeSpan.FromSeconds(dateValue);
|
||||
else if (dateStr.Contains("min"))
|
||||
ts = TimeSpan.FromMinutes(dateValue);
|
||||
else if (dateStr.Contains("hour"))
|
||||
ts = TimeSpan.FromHours(dateValue);
|
||||
else if (dateStr.Contains("day"))
|
||||
ts = TimeSpan.FromDays(dateValue);
|
||||
else if (dateStr.Contains("week"))
|
||||
ts = TimeSpan.FromDays(dateValue * 7);
|
||||
else if (dateStr.Contains("month"))
|
||||
ts = TimeSpan.FromDays(dateValue * 30);
|
||||
else if (dateStr.Contains("year"))
|
||||
ts = TimeSpan.FromDays(dateValue * 365);
|
||||
release.PublishDate = DateTime.Now - ts;
|
||||
}
|
||||
release.PublishDate = DateTimeUtil.FromTimeAgo(dateStr);
|
||||
|
||||
var sizeStr = qRow.Find(".size")[0].ChildNodes[0].NodeValue.Trim();
|
||||
var sizeParts = sizeStr.Split(' ');
|
||||
|
|
|
@ -155,6 +155,7 @@
|
|||
<Compile Include="Engine.cs" />
|
||||
<Compile Include="Indexers\BaseIndexer.cs" />
|
||||
<Compile Include="Indexers\BB.cs" />
|
||||
<Compile Include="Indexers\PrivateHD.cs" />
|
||||
<Compile Include="Indexers\SpeedCD.cs" />
|
||||
<Compile Include="Models\TorznabCapabilities.cs" />
|
||||
<Compile Include="Models\Config\ServerConfig.cs" />
|
||||
|
@ -283,6 +284,9 @@
|
|||
<Content Include="Content\logos\hdtorrents.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\logos\privatehd.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\logos\sceneaccess.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
|
@ -51,19 +51,19 @@ namespace Jackett
|
|||
|
||||
config.Routes.MapHttpRoute(
|
||||
name: "apiDefault",
|
||||
routeTemplate: "api/{indexerName}",
|
||||
routeTemplate: "api/{indexerID}",
|
||||
defaults: new { controller = "API", action = "Call" }
|
||||
);
|
||||
|
||||
config.Routes.MapHttpRoute(
|
||||
name: "api",
|
||||
routeTemplate: "api/{indexerName}/api",
|
||||
routeTemplate: "api/{indexerID}/api",
|
||||
defaults: new { controller = "API", action = "Call" }
|
||||
);
|
||||
|
||||
config.Routes.MapHttpRoute(
|
||||
name: "download",
|
||||
routeTemplate: "api/{indexerName}/download/{path}/download.torrent",
|
||||
routeTemplate: "api/{indexerID}/download/{path}/download.torrent",
|
||||
defaults: new { controller = "Download", action = "Download" }
|
||||
);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace Jackett.Utils.Clients
|
|||
public string Cookies { get; set; }
|
||||
public string Referer { get; set; }
|
||||
public RequestType Type { get; set; }
|
||||
public bool AutoRedirect { get; set; }
|
||||
}
|
||||
|
||||
public enum RequestType
|
||||
|
|
|
@ -13,16 +13,18 @@ namespace Jackett.Utils.Clients
|
|||
class WindowsWebClient : IWebClient
|
||||
{
|
||||
private Logger logger;
|
||||
CookieContainer cookies;
|
||||
|
||||
public WindowsWebClient(Logger l)
|
||||
{
|
||||
logger = l;
|
||||
cookies = new CookieContainer();
|
||||
}
|
||||
|
||||
public async Task<WebClientByteResult> GetBytes(WebRequest request)
|
||||
{
|
||||
logger.Debug(string.Format("WindowsWebClient:GetBytes(Url:{0})", request.Url));
|
||||
var cookies = new CookieContainer();
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(request.Cookies))
|
||||
{
|
||||
|
@ -45,7 +47,6 @@ namespace Jackett.Utils.Clients
|
|||
CookieContainer = cookies,
|
||||
AllowAutoRedirect = false,
|
||||
UseCookies = true,
|
||||
|
||||
});
|
||||
|
||||
client.DefaultRequestHeaders.Add("User-Agent", BrowserUtil.ChromeUserAgent);
|
||||
|
@ -92,9 +93,8 @@ namespace Jackett.Utils.Clients
|
|||
var client = new HttpClient(new HttpClientHandler
|
||||
{
|
||||
CookieContainer = cookies,
|
||||
AllowAutoRedirect = false,
|
||||
AllowAutoRedirect = request.AutoRedirect,
|
||||
UseCookies = true,
|
||||
|
||||
});
|
||||
|
||||
client.DefaultRequestHeaders.Add("User-Agent", BrowserUtil.ChromeUserAgent);
|
||||
|
|
|
@ -14,5 +14,43 @@ namespace Jackett.Utils
|
|||
long unixTimeStampInTicks = (long)(unixTime * TimeSpan.TicksPerSecond);
|
||||
return new DateTime(unixStart.Ticks + unixTimeStampInTicks);
|
||||
}
|
||||
|
||||
// ex: "2 hours 1 day"
|
||||
public static DateTime FromTimeAgo(string str)
|
||||
{
|
||||
str = str.ToLowerInvariant();
|
||||
if (str.Contains("now"))
|
||||
{
|
||||
return DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Local);
|
||||
}
|
||||
|
||||
var dateParts = str.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
|
||||
TimeSpan timeAgo = TimeSpan.Zero;
|
||||
for (var i = 0; i < dateParts.Length / 2; i++)
|
||||
{
|
||||
var val = ParseUtil.CoerceFloat(dateParts[i * 2]);
|
||||
var unit = dateParts[i * 2 + 1];
|
||||
if (unit.Contains("sec"))
|
||||
timeAgo += TimeSpan.FromSeconds(val);
|
||||
else if (unit.Contains("min"))
|
||||
timeAgo += TimeSpan.FromMinutes(val);
|
||||
else if (unit.Contains("hour"))
|
||||
timeAgo += TimeSpan.FromHours(val);
|
||||
else if (unit.Contains("day"))
|
||||
timeAgo += TimeSpan.FromDays(val);
|
||||
else if (unit.Contains("week"))
|
||||
timeAgo += TimeSpan.FromDays(val * 7);
|
||||
else if (unit.Contains("month"))
|
||||
timeAgo += TimeSpan.FromDays(val * 30);
|
||||
else if (unit.Contains("year"))
|
||||
timeAgo += TimeSpan.FromDays(val * 365);
|
||||
else
|
||||
{
|
||||
throw new Exception("TimeAgo parsing failed");
|
||||
}
|
||||
}
|
||||
|
||||
return DateTime.SpecifyKind(DateTime.Now - timeAgo, DateTimeKind.Local);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,33 +11,33 @@ namespace Jackett.Utils
|
|||
{
|
||||
public static float CoerceFloat(string str)
|
||||
{
|
||||
return float.Parse(str, NumberStyles.Any, CultureInfo.InvariantCulture);
|
||||
return float.Parse(str.Trim(), NumberStyles.Any, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static int CoerceInt(string str)
|
||||
{
|
||||
return int.Parse(str, NumberStyles.Any, CultureInfo.InvariantCulture);
|
||||
return int.Parse(str.Trim(), NumberStyles.Any, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static long CoerceLong(string str)
|
||||
{
|
||||
return long.Parse(str, NumberStyles.Any, CultureInfo.InvariantCulture);
|
||||
return long.Parse(str.Trim(), NumberStyles.Any, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
|
||||
public static bool TryCoerceFloat(string str, out float result)
|
||||
{
|
||||
return float.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
|
||||
return float.TryParse(str.Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out result);
|
||||
}
|
||||
|
||||
public static bool TryCoerceInt(string str, out int result)
|
||||
{
|
||||
return int.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
|
||||
return int.TryParse(str.Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out result);
|
||||
}
|
||||
|
||||
public static bool TryCoerceLong(string str, out long result)
|
||||
{
|
||||
return long.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
|
||||
return long.TryParse(str.Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue