mirror of
https://github.com/Jackett/Jackett
synced 2025-03-12 07:04:22 +00:00
commit
916df7393b
2 changed files with 901 additions and 876 deletions
|
@ -1,232 +1,257 @@
|
||||||
using CsQuery;
|
using CsQuery;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
namespace Jackett.Indexers
|
|
||||||
{
|
namespace Jackett.Indexers
|
||||||
public class AlphaRatio : IndexerInterface
|
{
|
||||||
{
|
public class AlphaRatio : IndexerInterface
|
||||||
public string DisplayName
|
{
|
||||||
{
|
public string DisplayName
|
||||||
get { return "AlphaRatio"; }
|
{
|
||||||
}
|
get { return "AlphaRatio"; }
|
||||||
|
}
|
||||||
public string DisplayDescription
|
|
||||||
{
|
public string DisplayDescription
|
||||||
get { return "Legendary"; }
|
{
|
||||||
}
|
get { return "Legendary"; }
|
||||||
|
}
|
||||||
public Uri SiteLink
|
|
||||||
{
|
public Uri SiteLink
|
||||||
get { return new Uri(BaseUrl); }
|
{
|
||||||
}
|
get { return new Uri(BaseUrl); }
|
||||||
|
}
|
||||||
|
|
||||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
|
||||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||||
|
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||||
public bool IsConfigured { get; private set; }
|
|
||||||
|
public bool IsConfigured { get; private set; }
|
||||||
static string BaseUrl = "https://alpharatio.cc";
|
|
||||||
|
static string BaseUrl = "https://alpharatio.cc";
|
||||||
static string LoginUrl = BaseUrl + "/login.php";
|
|
||||||
|
static string LoginUrl = BaseUrl + "/login.php";
|
||||||
static string SearchUrl = BaseUrl + "/ajax.php?action=browse&searchstr=";
|
|
||||||
|
static string SearchUrl = BaseUrl + "/ajax.php?action=browse&searchstr=";
|
||||||
static string DownloadUrl = BaseUrl + "/torrents.php?action=download&id=";
|
|
||||||
|
static string DownloadUrl = BaseUrl + "/torrents.php?action=download&id=";
|
||||||
static string GuidUrl = BaseUrl + "/torrents.php?torrentid=";
|
|
||||||
|
static string GuidUrl = BaseUrl + "/torrents.php?torrentid=";
|
||||||
CookieContainer cookies;
|
|
||||||
HttpClientHandler handler;
|
static string chromeUserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36";
|
||||||
HttpClient client;
|
|
||||||
|
CookieContainer cookies;
|
||||||
string cookieHeader;
|
HttpClientHandler handler;
|
||||||
|
HttpClient client;
|
||||||
public AlphaRatio()
|
|
||||||
{
|
string cookieHeader;
|
||||||
IsConfigured = false;
|
|
||||||
cookies = new CookieContainer();
|
public AlphaRatio()
|
||||||
handler = new HttpClientHandler
|
{
|
||||||
{
|
IsConfigured = false;
|
||||||
CookieContainer = cookies,
|
cookies = new CookieContainer();
|
||||||
AllowAutoRedirect = true,
|
handler = new HttpClientHandler
|
||||||
UseCookies = true,
|
{
|
||||||
};
|
CookieContainer = cookies,
|
||||||
client = new HttpClient(handler);
|
AllowAutoRedirect = true,
|
||||||
}
|
UseCookies = true,
|
||||||
|
|
||||||
public Task<ConfigurationData> GetConfigurationForSetup()
|
};
|
||||||
{
|
client = new HttpClient(handler);
|
||||||
var config = new ConfigurationDataBasicLogin();
|
}
|
||||||
return Task.FromResult<ConfigurationData>(config);
|
|
||||||
}
|
public Task<ConfigurationData> GetConfigurationForSetup()
|
||||||
|
{
|
||||||
public async Task ApplyConfiguration(JToken configJson)
|
var config = new ConfigurationDataBasicLogin();
|
||||||
{
|
return Task.FromResult<ConfigurationData>(config);
|
||||||
var config = new ConfigurationDataBasicLogin();
|
}
|
||||||
config.LoadValuesFromJson(configJson);
|
|
||||||
|
public async Task ApplyConfiguration(JToken configJson)
|
||||||
var pairs = new Dictionary<string, string> {
|
{
|
||||||
{ "username", config.Username.Value },
|
cookies = new CookieContainer();
|
||||||
{ "password", config.Password.Value },
|
client = new HttpClient(handler);
|
||||||
{ "login", "Log in" },
|
|
||||||
{ "keeplogged", "1" }
|
var configSaveData = new JObject();
|
||||||
};
|
if (OnSaveConfigurationRequested != null)
|
||||||
|
OnSaveConfigurationRequested(this, configSaveData);
|
||||||
var content = new FormUrlEncodedContent(pairs);
|
|
||||||
|
var config = new ConfigurationDataBasicLogin();
|
||||||
string responseContent;
|
config.LoadValuesFromJson(configJson);
|
||||||
JArray cookieJArray;
|
|
||||||
|
var pairs = new Dictionary<string, string> {
|
||||||
if (Program.IsWindows)
|
{ "username", config.Username.Value },
|
||||||
{
|
{ "password", @config.Password.Value },
|
||||||
// If Windows use .net http
|
{ "login", "Login" },
|
||||||
var response = await client.PostAsync(LoginUrl, content);
|
{ "keeplogged", "1" }
|
||||||
responseContent = await response.Content.ReadAsStringAsync();
|
};
|
||||||
cookieJArray = cookies.ToJson(SiteLink);
|
|
||||||
}
|
var content = new FormUrlEncodedContent(pairs);
|
||||||
else
|
var message = CreateHttpRequest(new Uri(LoginUrl));
|
||||||
{
|
message.Content = content;
|
||||||
// If UNIX system use curl
|
|
||||||
var response = await CurlHelper.PostAsync(LoginUrl, pairs);
|
//message.Headers.Referrer = new Uri(LoginUrl);
|
||||||
responseContent = Encoding.UTF8.GetString(response.Content);
|
string responseContent;
|
||||||
cookieHeader = response.CookieHeader;
|
JArray cookieJArray;
|
||||||
cookieJArray = new JArray(response.CookiesFlat);
|
|
||||||
}
|
if (Program.IsWindows)
|
||||||
|
{
|
||||||
if (!responseContent.Contains("logout.php?"))
|
// If Windows use .net http
|
||||||
{
|
var response = await client.SendAsync(message);
|
||||||
CQ dom = responseContent;
|
responseContent = await response.Content.ReadAsStringAsync();
|
||||||
dom["#loginform > table"].Remove();
|
cookieJArray = cookies.ToJson(SiteLink);
|
||||||
var errorMessage = dom["#loginform"].Text().Trim().Replace("\n\t", " ");
|
}
|
||||||
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
|
else
|
||||||
|
{
|
||||||
}
|
// If UNIX system use curl, probably broken due to missing chromeUseragent record for CURL...cannot test
|
||||||
else
|
var response = await CurlHelper.PostAsync(LoginUrl, pairs);
|
||||||
{
|
responseContent = Encoding.UTF8.GetString(response.Content);
|
||||||
|
cookieHeader = response.CookieHeader;
|
||||||
var configSaveData = new JObject();
|
cookieJArray = new JArray(response.CookiesFlat);
|
||||||
configSaveData["cookies"] = cookieJArray;
|
}
|
||||||
if (OnSaveConfigurationRequested != null)
|
|
||||||
OnSaveConfigurationRequested(this, configSaveData);
|
if (!responseContent.Contains("logout.php?"))
|
||||||
|
{
|
||||||
IsConfigured = true;
|
CQ dom = responseContent;
|
||||||
}
|
dom["#loginform > table"].Remove();
|
||||||
}
|
var errorMessage = dom["#loginform"].Text().Trim().Replace("\n\t", " ");
|
||||||
|
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
|
||||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
|
||||||
{
|
}
|
||||||
cookies.FillFromJson(SiteLink, (JArray)jsonConfig["cookies"]);
|
else
|
||||||
cookieHeader = cookies.GetCookieHeader(SiteLink);
|
{
|
||||||
IsConfigured = true;
|
configSaveData = new JObject();
|
||||||
}
|
configSaveData["cookies"] = cookieJArray;
|
||||||
|
if (OnSaveConfigurationRequested != null)
|
||||||
void FillReleaseInfoFromJson(ReleaseInfo release, JObject r)
|
OnSaveConfigurationRequested(this, configSaveData);
|
||||||
{
|
|
||||||
var id = r["torrentId"];
|
IsConfigured = true;
|
||||||
release.Size = (long)r["size"];
|
}
|
||||||
release.Seeders = (int)r["seeders"];
|
}
|
||||||
release.Peers = (int)r["leechers"] + release.Seeders;
|
|
||||||
release.Guid = new Uri(GuidUrl + id);
|
HttpRequestMessage CreateHttpRequest(Uri uri)
|
||||||
release.Comments = release.Guid;
|
{
|
||||||
release.Link = new Uri(DownloadUrl + id);
|
var message = new HttpRequestMessage();
|
||||||
}
|
message.Method = HttpMethod.Post;
|
||||||
|
message.RequestUri = uri;
|
||||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
message.Headers.UserAgent.ParseAdd(chromeUserAgent);
|
||||||
{
|
return message;
|
||||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
}
|
||||||
|
|
||||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
|
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||||
{
|
{
|
||||||
|
cookies.FillFromJson(SiteLink, (JArray)jsonConfig["cookies"]);
|
||||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
cookieHeader = cookies.GetCookieHeader(SiteLink);
|
||||||
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
|
IsConfigured = true;
|
||||||
|
}
|
||||||
string results;
|
|
||||||
if (Program.IsWindows)
|
void FillReleaseInfoFromJson(ReleaseInfo release, JObject r)
|
||||||
{
|
{
|
||||||
results = await client.GetStringAsync(episodeSearchUrl);
|
var id = r["torrentId"];
|
||||||
}
|
release.Size = (long)r["size"];
|
||||||
else
|
release.Seeders = (int)r["seeders"];
|
||||||
{
|
release.Peers = (int)r["leechers"] + release.Seeders;
|
||||||
var response = await CurlHelper.GetAsync(episodeSearchUrl, cookieHeader);
|
release.Guid = new Uri(GuidUrl + id);
|
||||||
results = Encoding.UTF8.GetString(response.Content);
|
release.Comments = release.Guid;
|
||||||
}
|
release.Link = new Uri(DownloadUrl + id);
|
||||||
try
|
}
|
||||||
{
|
|
||||||
|
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||||
var json = JObject.Parse(results);
|
{
|
||||||
foreach (JObject r in json["response"]["results"])
|
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||||
{
|
|
||||||
DateTime pubDate = DateTime.MinValue;
|
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
|
||||||
double dateNum;
|
{
|
||||||
if (double.TryParse((string)r["groupTime"], out dateNum))
|
|
||||||
pubDate = UnixTimestampToDateTime(dateNum);
|
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||||
|
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
|
||||||
var groupName = (string)r["groupName"];
|
|
||||||
|
string results;
|
||||||
if (r["torrents"] is JArray)
|
if (Program.IsWindows)
|
||||||
{
|
{
|
||||||
foreach (JObject t in r["torrents"])
|
var request = CreateHttpRequest(new Uri(episodeSearchUrl));
|
||||||
{
|
request.Method = HttpMethod.Get;
|
||||||
var release = new ReleaseInfo();
|
var response = await client.SendAsync(request);
|
||||||
release.PublishDate = pubDate;
|
results = await response.Content.ReadAsStringAsync();
|
||||||
release.Title = groupName;
|
}
|
||||||
release.Description = groupName;
|
else
|
||||||
FillReleaseInfoFromJson(release, t);
|
{
|
||||||
releases.Add(release);
|
var response = await CurlHelper.GetAsync(episodeSearchUrl, cookieHeader);
|
||||||
}
|
results = Encoding.UTF8.GetString(response.Content);
|
||||||
}
|
}
|
||||||
else
|
try
|
||||||
{
|
{
|
||||||
var release = new ReleaseInfo();
|
|
||||||
release.PublishDate = pubDate;
|
var json = JObject.Parse(results);
|
||||||
release.Title = groupName;
|
foreach (JObject r in json["response"]["results"])
|
||||||
release.Description = groupName;
|
{
|
||||||
FillReleaseInfoFromJson(release, r);
|
DateTime pubDate = DateTime.MinValue;
|
||||||
releases.Add(release);
|
double dateNum;
|
||||||
}
|
if (double.TryParse((string)r["groupTime"], out dateNum))
|
||||||
|
pubDate = UnixTimestampToDateTime(dateNum);
|
||||||
}
|
|
||||||
}
|
var groupName = (string)r["groupName"];
|
||||||
catch (Exception ex)
|
|
||||||
{
|
if (r["torrents"] is JArray)
|
||||||
OnResultParsingError(this, results, ex);
|
{
|
||||||
throw ex;
|
foreach (JObject t in r["torrents"])
|
||||||
}
|
{
|
||||||
}
|
var release = new ReleaseInfo();
|
||||||
|
release.PublishDate = pubDate;
|
||||||
return releases.ToArray();
|
release.Title = groupName;
|
||||||
}
|
release.Description = groupName;
|
||||||
|
FillReleaseInfoFromJson(release, t);
|
||||||
static DateTime UnixTimestampToDateTime(double unixTime)
|
releases.Add(release);
|
||||||
{
|
}
|
||||||
DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
|
}
|
||||||
long unixTimeStampInTicks = (long)(unixTime * TimeSpan.TicksPerSecond);
|
else
|
||||||
return new DateTime(unixStart.Ticks + unixTimeStampInTicks);
|
{
|
||||||
}
|
var release = new ReleaseInfo();
|
||||||
|
release.PublishDate = pubDate;
|
||||||
public async Task<byte[]> Download(Uri link)
|
release.Title = groupName;
|
||||||
{
|
release.Description = groupName;
|
||||||
if (Program.IsWindows)
|
FillReleaseInfoFromJson(release, r);
|
||||||
{
|
releases.Add(release);
|
||||||
return await client.GetByteArrayAsync(link);
|
}
|
||||||
}
|
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
var response = await CurlHelper.GetAsync(link.ToString(), cookieHeader);
|
catch (Exception ex)
|
||||||
return response.Content;
|
{
|
||||||
}
|
OnResultParsingError(this, results, ex);
|
||||||
|
throw ex;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
return releases.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
static DateTime UnixTimestampToDateTime(double unixTime)
|
||||||
|
{
|
||||||
|
DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
|
||||||
|
long unixTimeStampInTicks = (long)(unixTime * TimeSpan.TicksPerSecond);
|
||||||
|
return new DateTime(unixStart.Ticks + unixTimeStampInTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<byte[]> Download(Uri link)
|
||||||
|
{
|
||||||
|
if (Program.IsWindows)
|
||||||
|
{
|
||||||
|
return await client.GetByteArrayAsync(link);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var response = await CurlHelper.GetAsync(link.ToString(), cookieHeader);
|
||||||
|
return response.Content;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue