mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-10 05:43:17 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dfd68d16aa | ||
![]() |
9a4c5ffe5c | ||
![]() |
8cf45a5e45 | ||
![]() |
7834411bbd |
@@ -33,10 +33,16 @@ namespace CurlSharp
|
||||
private const string CURL_LIB = "libcurl64.dll";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if USE_LIBCURLSHIM
|
||||
private const string CURLSHIM_LIB = "libcurlshim64.dll";
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
#if LINUX
|
||||
private const string CURL_LIB = "libcurl";
|
||||
@@ -44,6 +50,9 @@ namespace CurlSharp
|
||||
private const string CURL_LIB = "libcurl.dll";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if USE_LIBCURLSHIM
|
||||
private const string CURLSHIM_LIB = "libcurlshim.dll";
|
||||
#endif
|
||||
|
213
src/Jackett/CurlHelper.cs
Normal file
213
src/Jackett/CurlHelper.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using CurlSharp;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace Jackett
|
||||
{
|
||||
public static class CurlHelper
|
||||
{
|
||||
private const string ChromeUserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36";
|
||||
|
||||
public class CurlRequest
|
||||
{
|
||||
|
||||
public string Url { get; private set; }
|
||||
|
||||
public string Cookies { get; private set; }
|
||||
|
||||
public string Referer { get; private set; }
|
||||
|
||||
public HttpMethod Method { get; private set; }
|
||||
|
||||
public Dictionary<string, string> PostData { get; set; }
|
||||
|
||||
public CurlRequest(HttpMethod method, string url, string cookies = null, string referer = null)
|
||||
{
|
||||
Method = method;
|
||||
Url = url;
|
||||
Cookies = cookies;
|
||||
Referer = referer;
|
||||
}
|
||||
}
|
||||
|
||||
public class CurlResponse
|
||||
{
|
||||
public Dictionary<string, string> Headers { get; private set; }
|
||||
|
||||
public List<string[]> HeaderList { get; private set; }
|
||||
|
||||
public byte[] Content { get; private set; }
|
||||
|
||||
public Dictionary<string, string> Cookies { get; private set; }
|
||||
|
||||
public List<string> CookiesFlat { get { return Cookies.Select(c => c.Key + "=" + c.Value).ToList(); } }
|
||||
|
||||
public string CookieHeader { get { return string.Join("; ", CookiesFlat); } }
|
||||
|
||||
public CurlResponse(List<string[]> headers, byte[] content)
|
||||
{
|
||||
Headers = new Dictionary<string, string>();
|
||||
Cookies = new Dictionary<string, string>();
|
||||
HeaderList = headers;
|
||||
Content = content;
|
||||
foreach (var h in headers)
|
||||
{
|
||||
Headers[h[0]] = h[1];
|
||||
}
|
||||
}
|
||||
|
||||
public void AddCookiesFromHeaderValue(string cookieHeaderValue)
|
||||
{
|
||||
var rawCookies = cookieHeaderValue.Split(';');
|
||||
foreach (var rawCookie in rawCookies)
|
||||
{
|
||||
var parts = rawCookie.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 1)
|
||||
Cookies[rawCookie.Trim()] = string.Empty;
|
||||
else
|
||||
Cookies[parts[0].Trim()] = parts[1].Trim();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddCookiesFromHeaders(List<string[]> headers)
|
||||
{
|
||||
foreach (var h in headers)
|
||||
{
|
||||
if (h[0] == "set-cookie")
|
||||
{
|
||||
AddCookiesFromHeaderValue(h[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<CurlResponse> GetAsync(string url, string cookies = null, string referer = null)
|
||||
{
|
||||
var curlRequest = new CurlRequest(HttpMethod.Get, url, cookies, referer);
|
||||
var result = await PerformCurlAsync(curlRequest);
|
||||
var checkedResult = await FollowRedirect(url, result);
|
||||
return checkedResult;
|
||||
}
|
||||
|
||||
public static async Task<CurlResponse> PostAsync(string url, Dictionary<string, string> formData, string cookies = null, string referer = null)
|
||||
{
|
||||
var curlRequest = new CurlRequest(HttpMethod.Post, url, cookies, referer);
|
||||
curlRequest.PostData = formData;
|
||||
var result = await PerformCurlAsync(curlRequest);
|
||||
var checkedResult = await FollowRedirect(url, result);
|
||||
return checkedResult;
|
||||
}
|
||||
|
||||
private static async Task<CurlResponse> FollowRedirect(string url, CurlResponse response)
|
||||
{
|
||||
var uri = new Uri(url);
|
||||
string redirect;
|
||||
if (response.Headers.TryGetValue("location", out redirect))
|
||||
{
|
||||
string cookie = response.CookieHeader;
|
||||
if (!redirect.StartsWith("http://") && !redirect.StartsWith("https://"))
|
||||
{
|
||||
if (redirect.StartsWith("/"))
|
||||
redirect = string.Format("{0}://{1}{2}", uri.Scheme, uri.Host, redirect);
|
||||
else
|
||||
redirect = string.Format("{0}://{1}/{2}", uri.Scheme, uri.Host, redirect);
|
||||
}
|
||||
var newRedirect = await GetAsync(redirect, cookie);
|
||||
foreach (var c in response.Cookies)
|
||||
newRedirect.Cookies[c.Key] = c.Value;
|
||||
newRedirect.AddCookiesFromHeaders(response.HeaderList);
|
||||
return newRedirect;
|
||||
}
|
||||
else
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public static async Task<CurlResponse> PerformCurlAsync(CurlRequest curlRequest)
|
||||
{
|
||||
return await Task.Run(() => PerformCurl(curlRequest));
|
||||
}
|
||||
|
||||
public static CurlResponse PerformCurl(CurlRequest curlRequest)
|
||||
{
|
||||
Curl.GlobalInit(CurlInitFlag.All);
|
||||
|
||||
var headerBuffers = new List<byte[]>();
|
||||
var contentBuffers = new List<byte[]>();
|
||||
|
||||
using (var easy = new CurlEasy())
|
||||
{
|
||||
easy.Url = curlRequest.Url;
|
||||
easy.BufferSize = 64 * 1024;
|
||||
easy.UserAgent = ChromeUserAgent;
|
||||
easy.WriteFunction = (byte[] buf, int size, int nmemb, object data) =>
|
||||
{
|
||||
contentBuffers.Add(buf);
|
||||
return size * nmemb;
|
||||
};
|
||||
easy.HeaderFunction = (byte[] buf, int size, int nmemb, object extraData) =>
|
||||
{
|
||||
headerBuffers.Add(buf);
|
||||
return size * nmemb;
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(curlRequest.Cookies))
|
||||
easy.Cookie = curlRequest.Cookies;
|
||||
|
||||
if (!string.IsNullOrEmpty(curlRequest.Referer))
|
||||
easy.Referer = curlRequest.Referer;
|
||||
|
||||
if (curlRequest.Method == HttpMethod.Post)
|
||||
{
|
||||
easy.Post = true;
|
||||
var postString = new FormUrlEncodedContent(curlRequest.PostData).ReadAsStringAsync().Result;
|
||||
easy.PostFields = postString;
|
||||
easy.PostFieldSize = Encoding.UTF8.GetByteCount(postString);
|
||||
}
|
||||
|
||||
easy.Perform();
|
||||
}
|
||||
|
||||
var headerBytes = Combine(headerBuffers.ToArray());
|
||||
var headerString = Encoding.UTF8.GetString(headerBytes);
|
||||
var headerParts = headerString.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var headers = new List<string[]>();
|
||||
foreach (var headerPart in headerParts.Skip(1))
|
||||
{
|
||||
var keyVal = headerPart.Split(new char[] { ':' }, 2);
|
||||
if (keyVal.Length > 1)
|
||||
{
|
||||
headers.Add(new[] { keyVal[0].ToLower().Trim(), keyVal[1].Trim() });
|
||||
}
|
||||
}
|
||||
|
||||
var contentBytes = Combine(contentBuffers.ToArray());
|
||||
var curlResponse = new CurlResponse(headers, contentBytes);
|
||||
|
||||
if (!string.IsNullOrEmpty(curlRequest.Cookies))
|
||||
curlResponse.AddCookiesFromHeaderValue(curlRequest.Cookies);
|
||||
curlResponse.AddCookiesFromHeaders(headers);
|
||||
|
||||
return curlResponse;
|
||||
|
||||
}
|
||||
|
||||
public static byte[] Combine(params byte[][] arrays)
|
||||
{
|
||||
byte[] ret = new byte[arrays.Sum(x => x.Length)];
|
||||
int offset = 0;
|
||||
foreach (byte[] data in arrays)
|
||||
{
|
||||
Buffer.BlockCopy(data, 0, ret, offset, data.Length);
|
||||
offset += data.Length;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
@@ -10,22 +10,23 @@ namespace Jackett
|
||||
{
|
||||
public interface IndexerInterface
|
||||
{
|
||||
|
||||
// Invoked when the indexer configuration has been applied and verified so the cookie needs to be saved
|
||||
event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
string DisplayName { get; }
|
||||
string DisplayDescription { get; }
|
||||
Uri SiteLink { get; }
|
||||
|
||||
// Whether this indexer has been configured, verified and saved in the past and has the settings required for functioning
|
||||
bool IsConfigured { get; }
|
||||
|
||||
// Retrieved for starting setup for the indexer via web API
|
||||
Task<ConfigurationData> GetConfigurationForSetup();
|
||||
|
||||
// Called when web API wants to apply setup configuration via web API, usually this is where login and storing cookie happens
|
||||
Task ApplyConfiguration(JToken configJson);
|
||||
|
||||
// Invoked when the indexer configuration has been applied and verified so the cookie needs to be saved
|
||||
event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
// Whether this indexer has been configured, verified and saved in the past and has the settings required for functioning
|
||||
bool IsConfigured { get; }
|
||||
|
||||
// Called on startup when initializing indexers from saved configuration
|
||||
void LoadFromSavedConfiguration(JToken jsonConfig);
|
||||
|
||||
|
@@ -61,7 +61,6 @@ namespace Jackett
|
||||
|
||||
void newIndexer_OnSaveConfigurationRequested(IndexerInterface indexer, JToken obj)
|
||||
{
|
||||
var name = indexer.GetType().Name.Trim().ToLower();
|
||||
var configFilePath = GetIndexerConfigFilePath(indexer);
|
||||
if (!Directory.Exists(IndexerConfigDirectory))
|
||||
Directory.CreateDirectory(IndexerConfigDirectory);
|
||||
|
@@ -73,7 +73,7 @@ namespace Jackett
|
||||
|
||||
public async Task<ConfigurationData> GetConfigurationForSetup ()
|
||||
{
|
||||
var loginPage = await client.GetAsync (LoginUrl);
|
||||
await client.GetAsync (LoginUrl);
|
||||
var captchaImage = await client.GetByteArrayAsync (CaptchaUrl);
|
||||
var config = new BmtvConfig ();
|
||||
config.CaptchaImage.Value = captchaImage;
|
||||
@@ -138,7 +138,6 @@ namespace Jackett
|
||||
foreach (var row in table.Children().Skip(1)) {
|
||||
var release = new ReleaseInfo ();
|
||||
|
||||
CQ qRow = row.Cq ();
|
||||
CQ qDetailsCol = row.ChildElements.ElementAt (1).Cq ();
|
||||
CQ qLink = qDetailsCol.Children ("a").First ();
|
||||
|
||||
|
@@ -85,7 +85,7 @@ namespace Jackett.Indexers
|
||||
string responseContent;
|
||||
JArray cookieJArray;
|
||||
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||
if (Program.IsWindows)
|
||||
{
|
||||
// If Windows use .net http
|
||||
var response = await client.PostAsync(LoginUrl, content);
|
||||
@@ -95,7 +95,7 @@ namespace Jackett.Indexers
|
||||
else
|
||||
{
|
||||
// If UNIX system use curl
|
||||
var response = await CurlHelper.Shared.PostAsync(LoginUrl, pairs);
|
||||
var response = await CurlHelper.PostAsync(LoginUrl, pairs);
|
||||
responseContent = Encoding.UTF8.GetString(response.Content);
|
||||
cookieHeader = response.CookieHeader;
|
||||
cookieJArray = new JArray(response.CookiesFlat);
|
||||
@@ -150,13 +150,13 @@ namespace Jackett.Indexers
|
||||
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
|
||||
|
||||
string results;
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||
if (Program.IsWindows)
|
||||
{
|
||||
results = await client.GetStringAsync(episodeSearchUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
var response = await CurlHelper.Shared.GetAsync(episodeSearchUrl, cookieHeader);
|
||||
var response = await CurlHelper.GetAsync(episodeSearchUrl, cookieHeader);
|
||||
results = Encoding.UTF8.GetString(response.Content);
|
||||
}
|
||||
|
||||
@@ -204,13 +204,13 @@ namespace Jackett.Indexers
|
||||
|
||||
public async Task<byte[]> Download(Uri link)
|
||||
{
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||
if (Program.IsWindows)
|
||||
{
|
||||
return await client.GetByteArrayAsync(link);
|
||||
}
|
||||
else
|
||||
{
|
||||
var response = await CurlHelper.Shared.GetAsync(link.ToString(), cookieHeader);
|
||||
var response = await CurlHelper.GetAsync(link.ToString(), cookieHeader);
|
||||
return response.Content;
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ namespace Jackett.Indexers
|
||||
|
||||
public ThePirateBayConfig()
|
||||
{
|
||||
Url = new StringItem { Name = "Url", Value = "https://thepiratebay.se/" };
|
||||
Url = new StringItem { Name = "Url", Value = DefaultUrl };
|
||||
}
|
||||
|
||||
public override Item[] GetItems()
|
||||
@@ -37,13 +37,13 @@ namespace Jackett.Indexers
|
||||
|
||||
public string DisplayDescription { get { return "The worlds largest bittorrent indexer"; } }
|
||||
|
||||
public Uri SiteLink { get { return new Uri("https://thepiratebay.se/"); } }
|
||||
public Uri SiteLink { get { return new Uri(DefaultUrl); } }
|
||||
|
||||
public bool IsConfigured { get; private set; }
|
||||
|
||||
static string SearchUrl = "s/?q=\"{0}\"&category=205&page=0&orderby=99";
|
||||
static string BrowserUrl = "browse/200";
|
||||
static string SwitchSingleViewUrl = "switchview.php?view=s";
|
||||
const string DefaultUrl = "https://thepiratebay.se";
|
||||
const string SearchUrl = "/s/?q=\"{0}\"&category=205&page=0&orderby=99";
|
||||
const string SwitchSingleViewUrl = "/switchview.php?view=s";
|
||||
|
||||
string BaseUrl;
|
||||
|
||||
@@ -75,16 +75,14 @@ namespace Jackett.Indexers
|
||||
{
|
||||
var config = new ThePirateBayConfig();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
await TestBrowse(config.Url.Value);
|
||||
BaseUrl = new Uri(config.Url.Value).ToString();
|
||||
|
||||
var message = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(BaseUrl + SwitchSingleViewUrl)
|
||||
};
|
||||
message.Headers.Referrer = new Uri(BaseUrl + BrowserUrl);
|
||||
var response = await client.SendAsync(message);
|
||||
var uri = new Uri(config.Url.Value);
|
||||
var formattedUrl = string.Format("{0}://{1}", uri.Scheme, uri.Host);
|
||||
var releases = await PerformQuery(new TorznabQuery(), formattedUrl);
|
||||
if (releases.Length == 0)
|
||||
throw new Exception("Could not find releases from this URL");
|
||||
|
||||
BaseUrl = formattedUrl;
|
||||
|
||||
var configSaveData = new JObject();
|
||||
configSaveData["base_url"] = BaseUrl;
|
||||
@@ -93,15 +91,7 @@ namespace Jackett.Indexers
|
||||
OnSaveConfigurationRequested(this, configSaveData);
|
||||
|
||||
IsConfigured = true;
|
||||
}
|
||||
|
||||
async Task TestBrowse(string url)
|
||||
{
|
||||
var result = await client.GetStringAsync(new Uri(url) + BrowserUrl);
|
||||
if (!result.Contains("<table id=\"searchResult\">"))
|
||||
{
|
||||
throw new Exception("Could not detect The Pirate Bay content");
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||
@@ -111,23 +101,39 @@ namespace Jackett.Indexers
|
||||
}
|
||||
|
||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
return await PerformQuery(query, BaseUrl);
|
||||
}
|
||||
|
||||
async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query, string baseUrl)
|
||||
{
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
|
||||
{
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var episodeSearchUrl = BaseUrl + string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
|
||||
var episodeSearchUrl = baseUrl + string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
|
||||
|
||||
var message = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(BaseUrl + SwitchSingleViewUrl)
|
||||
RequestUri = new Uri(baseUrl + SwitchSingleViewUrl)
|
||||
};
|
||||
message.Headers.Referrer = new Uri(episodeSearchUrl);
|
||||
|
||||
var response = await client.SendAsync(message);
|
||||
var results = await response.Content.ReadAsStringAsync();
|
||||
string results;
|
||||
|
||||
if (Program.IsWindows)
|
||||
{
|
||||
var response = await client.SendAsync(message);
|
||||
results = await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var response = await CurlHelper.GetAsync(baseUrl + SwitchSingleViewUrl, null, episodeSearchUrl);
|
||||
//var response = await CurlHelper.GetAsync (episodeSearchUrl, setLayoutResponse.CookieHeader);
|
||||
results = Encoding.UTF8.GetString(response.Content);
|
||||
}
|
||||
|
||||
CQ dom = results;
|
||||
|
||||
@@ -135,14 +141,14 @@ namespace Jackett.Indexers
|
||||
foreach (var row in rows)
|
||||
{
|
||||
var release = new ReleaseInfo();
|
||||
CQ qRow = row.Cq();
|
||||
|
||||
CQ qLink = row.ChildElements.ElementAt(1).Cq().Children("a").First();
|
||||
|
||||
release.MinimumRatio = 1;
|
||||
release.MinimumSeedTime = 172800;
|
||||
release.Title = qLink.Text().Trim();
|
||||
release.Description = release.Title;
|
||||
release.Comments = new Uri(BaseUrl + qLink.Attr("href").TrimStart('/'));
|
||||
release.Comments = new Uri(baseUrl + qLink.Attr("href").TrimStart('/'));
|
||||
release.Guid = release.Comments;
|
||||
|
||||
var timeString = row.ChildElements.ElementAt(2).Cq().Text();
|
||||
@@ -164,8 +170,8 @@ namespace Jackett.Indexers
|
||||
}
|
||||
|
||||
var downloadCol = row.ChildElements.ElementAt(3).Cq().Find("a");
|
||||
release.MagnetUrl = new Uri(downloadCol.Attr("href"));
|
||||
release.InfoHash = release.MagnetUrl.ToString().Split(':')[3].Split('&')[0];
|
||||
release.MagnetUri = new Uri(downloadCol.Attr("href"));
|
||||
release.InfoHash = release.MagnetUri.ToString().Split(':')[3].Split('&')[0];
|
||||
|
||||
var sizeString = row.ChildElements.ElementAt(4).Cq().Text().Split(' ');
|
||||
var sizeVal = float.Parse(sizeString[0]);
|
||||
|
164
src/Jackett/Indexers/TorrentLeech.cs
Normal file
164
src/Jackett/Indexers/TorrentLeech.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using CsQuery;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Jackett.Indexers
|
||||
{
|
||||
public class TorrentLeech : IndexerInterface
|
||||
{
|
||||
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
public string DisplayName
|
||||
{
|
||||
get { return "TorrentLeech"; }
|
||||
}
|
||||
|
||||
public string DisplayDescription
|
||||
{
|
||||
get { return "This is what happens when you seed"; }
|
||||
}
|
||||
|
||||
public Uri SiteLink
|
||||
{
|
||||
get { return new Uri(BaseUrl); }
|
||||
}
|
||||
|
||||
const string BaseUrl = "http://www.torrentleech.org";
|
||||
const string LoginUrl = BaseUrl + "/user/account/login/";
|
||||
const string SearchUrl = BaseUrl + "/torrents/browse/index/query/{0}/categories/2%2C26%2C27%2C32/orderby/added?";
|
||||
|
||||
public bool IsConfigured { get; private set; }
|
||||
|
||||
|
||||
CookieContainer cookies;
|
||||
HttpClientHandler handler;
|
||||
HttpClient client;
|
||||
|
||||
public TorrentLeech()
|
||||
{
|
||||
IsConfigured = false;
|
||||
cookies = new CookieContainer();
|
||||
handler = new HttpClientHandler
|
||||
{
|
||||
CookieContainer = cookies,
|
||||
AllowAutoRedirect = true,
|
||||
UseCookies = true,
|
||||
};
|
||||
client = new HttpClient(handler);
|
||||
}
|
||||
|
||||
public Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
return Task.FromResult<ConfigurationData>(config);
|
||||
}
|
||||
|
||||
public async Task ApplyConfiguration(JToken configJson)
|
||||
{
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
|
||||
var pairs = new Dictionary<string, string> {
|
||||
{ "username", config.Username.Value },
|
||||
{ "password", config.Password.Value },
|
||||
{ "remember_me", "on" },
|
||||
{ "login", "submit" }
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent(pairs);
|
||||
|
||||
var response = await client.PostAsync(LoginUrl, content);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (!responseContent.Contains("/user/account/logout"))
|
||||
{
|
||||
CQ dom = responseContent;
|
||||
var messageEl = dom[".ui-state-error"].Last();
|
||||
var errorMessage = messageEl.Text().Trim();
|
||||
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
|
||||
}
|
||||
else
|
||||
{
|
||||
var configSaveData = new JObject();
|
||||
configSaveData["cookies"] = cookies.ToJson(SiteLink);
|
||||
|
||||
if (OnSaveConfigurationRequested != null)
|
||||
OnSaveConfigurationRequested(this, configSaveData);
|
||||
|
||||
IsConfigured = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||
{
|
||||
cookies.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||
IsConfigured = true;
|
||||
}
|
||||
|
||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||
|
||||
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
|
||||
{
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
|
||||
var results = await client.GetStringAsync(episodeSearchUrl);
|
||||
CQ dom = results;
|
||||
|
||||
CQ qRows = dom["#torrenttable > tbody > tr"];
|
||||
|
||||
foreach (var row in qRows)
|
||||
{
|
||||
var release = new ReleaseInfo();
|
||||
|
||||
var qRow = row.Cq();
|
||||
|
||||
var debug = qRow.Html();
|
||||
|
||||
release.MinimumRatio = 1;
|
||||
release.MinimumSeedTime = 172800;
|
||||
|
||||
CQ qLink = qRow.Find(".title > a").First();
|
||||
release.Guid = new Uri(BaseUrl + qLink.Attr("href"));
|
||||
release.Comments = release.Guid;
|
||||
release.Title = qLink.Text();
|
||||
release.Description = release.Title;
|
||||
|
||||
release.Link = new Uri(BaseUrl + qRow.Find(".quickdownload > a").Attr("href"));
|
||||
|
||||
var dateString = qRow.Find(".name").First()[0].ChildNodes[4].NodeValue.Replace(" on", "").Trim();
|
||||
//"2015-04-25 23:38:12"
|
||||
//"yyyy-MMM-dd hh:mm:ss"
|
||||
release.PublishDate = DateTime.ParseExact(dateString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
|
||||
var sizeStringParts = qRow.Children().ElementAt(4).InnerText.Split(' ');
|
||||
release.Size = ReleaseInfo.GetBytes(sizeStringParts[1], float.Parse(sizeStringParts[0]));
|
||||
|
||||
release.Seeders = int.Parse(qRow.Find(".seeders").Text());
|
||||
release.Peers = int.Parse(qRow.Find(".leechers").Text());
|
||||
|
||||
releases.Add(release);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return releases.ToArray();
|
||||
}
|
||||
|
||||
public Task<byte[]> Download(Uri link)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@@ -94,7 +94,9 @@
|
||||
<Compile Include="Indexers\Freshon.cs" />
|
||||
<Compile Include="Indexers\IPTorrents.cs" />
|
||||
<Compile Include="Indexers\MoreThanTV.cs" />
|
||||
<Compile Include="Indexers\Strike.cs" />
|
||||
<Compile Include="Indexers\ThePirateBay.cs" />
|
||||
<Compile Include="Indexers\TorrentLeech.cs" />
|
||||
<Compile Include="Main.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -195,9 +197,15 @@
|
||||
<Content Include="WebContent\logos\rarbg.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="WebContent\logos\strike.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="WebContent\logos\thepiratebay.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="WebContent\logos\torrentleech.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="WebContent\setup_indexer.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
@@ -37,7 +37,7 @@ namespace Jackett
|
||||
|
||||
void toolStripMenuItemShutdown_Click(object sender, EventArgs e)
|
||||
{
|
||||
Application.Exit();
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
|
||||
void toolStripMenuItemAutoStart_CheckedChanged(object sender, EventArgs e)
|
||||
|
@@ -14,84 +14,95 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Jackett
|
||||
{
|
||||
class Program
|
||||
{
|
||||
public static string AppConfigDirectory = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData), "Jackett");
|
||||
class Program
|
||||
{
|
||||
public static string AppConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Jackett");
|
||||
|
||||
public static Server ServerInstance { get; private set; }
|
||||
public static Server ServerInstance { get; private set; }
|
||||
|
||||
public static bool IsFirstRun { get; private set; }
|
||||
public static bool IsFirstRun { get; private set; }
|
||||
|
||||
public static Logger LoggerInstance { get; private set; }
|
||||
public static Logger LoggerInstance { get; private set; }
|
||||
|
||||
public static ManualResetEvent ExitEvent { get; private set; }
|
||||
public static ManualResetEvent ExitEvent { get; private set; }
|
||||
|
||||
static void Main (string[] args)
|
||||
{
|
||||
ExitEvent = new ManualResetEvent (false);
|
||||
public static bool IsWindows { get { return Environment.OSVersion.Platform == PlatformID.Win32NT; } }
|
||||
|
||||
try {
|
||||
if (!Directory.Exists (AppConfigDirectory)) {
|
||||
IsFirstRun = true;
|
||||
Directory.CreateDirectory (AppConfigDirectory);
|
||||
}
|
||||
Console.WriteLine ("App config/log directory: " + AppConfigDirectory);
|
||||
} catch (Exception ex) {
|
||||
MessageBox.Show ("Could not create settings directory.");
|
||||
Application.Exit ();
|
||||
return;
|
||||
}
|
||||
static void Main(string[] args)
|
||||
{
|
||||
ExitEvent = new ManualResetEvent(false);
|
||||
|
||||
var logConfig = new LoggingConfiguration ();
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(AppConfigDirectory))
|
||||
{
|
||||
IsFirstRun = true;
|
||||
Directory.CreateDirectory(AppConfigDirectory);
|
||||
}
|
||||
Console.WriteLine("App config/log directory: " + AppConfigDirectory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Could not create settings directory. " + ex.Message);
|
||||
Application.Exit();
|
||||
return;
|
||||
}
|
||||
|
||||
var logFile = new FileTarget ();
|
||||
logConfig.AddTarget ("file", logFile);
|
||||
logFile.FileName = Path.Combine (AppConfigDirectory, "log.txt");
|
||||
logFile.Layout = "${longdate} ${level} ${message} \n ${exception:format=ToString}\n";
|
||||
var logFileRule = new LoggingRule ("*", LogLevel.Debug, logFile);
|
||||
logConfig.LoggingRules.Add (logFileRule);
|
||||
var logConfig = new LoggingConfiguration();
|
||||
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
|
||||
var logAlert = new MessageBoxTarget ();
|
||||
logConfig.AddTarget ("alert", logAlert);
|
||||
logAlert.Layout = "${message}";
|
||||
logAlert.Caption = "Alert";
|
||||
var logAlertRule = new LoggingRule ("*", LogLevel.Fatal, logAlert);
|
||||
logConfig.LoggingRules.Add (logAlertRule);
|
||||
}
|
||||
var logFile = new FileTarget();
|
||||
logConfig.AddTarget("file", logFile);
|
||||
logFile.FileName = Path.Combine(AppConfigDirectory, "log.txt");
|
||||
logFile.Layout = "${longdate} ${level} ${message} \n ${exception:format=ToString}\n";
|
||||
var logFileRule = new LoggingRule("*", LogLevel.Debug, logFile);
|
||||
logConfig.LoggingRules.Add(logFileRule);
|
||||
|
||||
var logConsole = new ConsoleTarget ();
|
||||
logConfig.AddTarget ("console", logConsole);
|
||||
logConsole.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}";
|
||||
var logConsoleRule = new LoggingRule ("*", LogLevel.Debug, logConsole);
|
||||
logConfig.LoggingRules.Add (logConsoleRule);
|
||||
if (Program.IsWindows)
|
||||
{
|
||||
var logAlert = new MessageBoxTarget();
|
||||
logConfig.AddTarget("alert", logAlert);
|
||||
logAlert.Layout = "${message}";
|
||||
logAlert.Caption = "Alert";
|
||||
var logAlertRule = new LoggingRule("*", LogLevel.Fatal, logAlert);
|
||||
logConfig.LoggingRules.Add(logAlertRule);
|
||||
}
|
||||
|
||||
LogManager.Configuration = logConfig;
|
||||
LoggerInstance = LogManager.GetCurrentClassLogger ();
|
||||
var logConsole = new ConsoleTarget();
|
||||
logConfig.AddTarget("console", logConsole);
|
||||
logConsole.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}";
|
||||
var logConsoleRule = new LoggingRule("*", LogLevel.Debug, logConsole);
|
||||
logConfig.LoggingRules.Add(logConsoleRule);
|
||||
|
||||
var serverTask = Task.Run (async () => {
|
||||
ServerInstance = new Server ();
|
||||
await ServerInstance.Start ();
|
||||
});
|
||||
LogManager.Configuration = logConfig;
|
||||
LoggerInstance = LogManager.GetCurrentClassLogger();
|
||||
|
||||
try {
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||
Application.Run (new Main ());
|
||||
} catch (Exception ex) {
|
||||
var serverTask = Task.Run(async () =>
|
||||
{
|
||||
ServerInstance = new Server();
|
||||
await ServerInstance.Start();
|
||||
});
|
||||
|
||||
}
|
||||
try
|
||||
{
|
||||
if (Program.IsWindows)
|
||||
Application.Run(new Main());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
Console.WriteLine ("Running in headless mode.");
|
||||
}
|
||||
|
||||
Task.WaitAll (serverTask);
|
||||
Console.WriteLine ("Server thread exit");
|
||||
}
|
||||
Console.WriteLine("Running in headless mode.");
|
||||
|
||||
static public void RestartAsAdmin ()
|
||||
{
|
||||
var startInfo = new ProcessStartInfo (Application.ExecutablePath.ToString ()) { Verb = "runas" };
|
||||
Process.Start (startInfo);
|
||||
Environment.Exit (0);
|
||||
}
|
||||
}
|
||||
Task.WaitAll(serverTask);
|
||||
Console.WriteLine("Server thread exit");
|
||||
}
|
||||
|
||||
static public void RestartAsAdmin()
|
||||
{
|
||||
var startInfo = new ProcessStartInfo(Application.ExecutablePath.ToString()) { Verb = "runas" };
|
||||
Process.Start(startInfo);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ namespace Jackett
|
||||
public Uri ConverUrl { get; set; }
|
||||
public Uri BannerUrl { get; set; }
|
||||
public string InfoHash { get; set; }
|
||||
public Uri MagnetUrl { get; set; }
|
||||
public Uri MagnetUri { get; set; }
|
||||
public double? MinimumRatio { get; set; }
|
||||
public long? MinimumSeedTime { get; set; }
|
||||
|
||||
|
@@ -73,15 +73,15 @@ namespace Jackett
|
||||
new XElement("pubDate", xmlDateFormat(r.PublishDate)),
|
||||
new XElement("size", r.Size),
|
||||
new XElement("description", r.Description),
|
||||
new XElement("link", r.Link ?? r.MagnetUrl),
|
||||
new XElement("link", r.Link ?? r.MagnetUri),
|
||||
r.Category == null ? null : new XElement("category", r.Category),
|
||||
new XElement(
|
||||
"enclosure",
|
||||
new XAttribute("url", r.Link ?? r.MagnetUrl),
|
||||
new XAttribute("url", r.Link ?? r.MagnetUri),
|
||||
new XAttribute("length", r.Size),
|
||||
new XAttribute("type", "application/x-bittorrent")
|
||||
),
|
||||
getTorznabElement("magneturl", r.MagnetUrl),
|
||||
getTorznabElement("magneturl", r.MagnetUri),
|
||||
getTorznabElement("rageid", r.RageID),
|
||||
getTorznabElement("seeders", r.Seeders),
|
||||
getTorznabElement("peers", r.Peers),
|
||||
|
@@ -64,7 +64,7 @@ namespace Jackett
|
||||
{
|
||||
var errorStr = "App must be ran as admin for permission to use port "
|
||||
+ Port + Environment.NewLine + "Restart app with admin privileges?";
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||
if (Program.IsWindows)
|
||||
{
|
||||
var dialogResult = MessageBox.Show(errorStr, "Error", MessageBoxButtons.YesNo);
|
||||
if (dialogResult == DialogResult.No)
|
||||
@@ -111,8 +111,6 @@ namespace Jackett
|
||||
Program.LoggerInstance.ErrorException("Error processing HTTP request", ex);
|
||||
}
|
||||
}
|
||||
|
||||
Program.LoggerInstance.Debug("HTTP request servicer thread died");
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
@@ -174,8 +172,6 @@ namespace Jackett
|
||||
|
||||
var query = HttpUtility.ParseQueryString(context.Request.Url.Query);
|
||||
var inputStream = context.Request.InputStream;
|
||||
var reader = new StreamReader(inputStream, context.Request.ContentEncoding);
|
||||
var bytes = await reader.ReadToEndAsync();
|
||||
|
||||
var indexerId = context.Request.Url.Segments[2].TrimEnd('/').ToLower();
|
||||
var indexer = indexerManager.GetIndexer(indexerId);
|
||||
|
@@ -27,17 +27,17 @@ namespace Jackett
|
||||
ApplySonarrConfig,
|
||||
TestSonarr
|
||||
}
|
||||
static Dictionary<string, WebApiMethod> WebApiMethods = new Dictionary<string, WebApiMethod>
|
||||
{
|
||||
{ "get_config_form", WebApiMethod.GetConfigForm },
|
||||
{ "configure_indexer", WebApiMethod.ConfigureIndexer },
|
||||
{ "get_indexers", WebApiMethod.GetIndexers },
|
||||
{ "test_indexer", WebApiMethod.TestIndexer },
|
||||
{ "delete_indexer", WebApiMethod.DeleteIndexer },
|
||||
{ "get_sonarr_config", WebApiMethod.GetSonarrConfig },
|
||||
{ "apply_sonarr_config", WebApiMethod.ApplySonarrConfig },
|
||||
{ "test_sonarr", WebApiMethod.TestSonarr }
|
||||
};
|
||||
|
||||
static Dictionary<string, WebApiMethod> WebApiMethods = new Dictionary<string, WebApiMethod> {
|
||||
{ "get_config_form", WebApiMethod.GetConfigForm },
|
||||
{ "configure_indexer", WebApiMethod.ConfigureIndexer },
|
||||
{ "get_indexers", WebApiMethod.GetIndexers },
|
||||
{ "test_indexer", WebApiMethod.TestIndexer },
|
||||
{ "delete_indexer", WebApiMethod.DeleteIndexer },
|
||||
{ "get_sonarr_config", WebApiMethod.GetSonarrConfig },
|
||||
{ "apply_sonarr_config", WebApiMethod.ApplySonarrConfig },
|
||||
{ "test_sonarr", WebApiMethod.TestSonarr }
|
||||
};
|
||||
|
||||
IndexerManager indexerManager;
|
||||
SonarrApi sonarrApi;
|
||||
@@ -80,7 +80,9 @@ namespace Jackett
|
||||
{
|
||||
await context.Response.OutputStream.WriteAsync(contentFile, 0, contentFile.Length);
|
||||
}
|
||||
catch (HttpListenerException) { }
|
||||
catch (HttpListenerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
async Task<JToken> ReadPostDataJson(Stream stream)
|
||||
@@ -93,8 +95,6 @@ namespace Jackett
|
||||
|
||||
async Task ProcessWebApiRequest(HttpListenerContext context, WebApiMethod method)
|
||||
{
|
||||
var query = HttpUtility.ParseQueryString(context.Request.Url.Query);
|
||||
|
||||
context.Response.ContentType = "text/json";
|
||||
context.Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
|
||||
|
BIN
src/Jackett/WebContent/logos/strike.png
Normal file
BIN
src/Jackett/WebContent/logos/strike.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
src/Jackett/WebContent/logos/torrentleech.png
Normal file
BIN
src/Jackett/WebContent/logos/torrentleech.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
Reference in New Issue
Block a user