mirror of https://github.com/Jackett/Jackett
Fixed bug with app not exiting, piratebay now works on mono
This commit is contained in:
parent
7834411bbd
commit
8cf45a5e45
|
@ -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
|
||||
|
|
|
@ -10,19 +10,12 @@ using System.Net.Http.Headers;
|
|||
|
||||
namespace Jackett
|
||||
{
|
||||
public class CurlHelper
|
||||
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 static CurlHelper Shared = new CurlHelper();
|
||||
|
||||
private BlockingCollection<CurlRequest> curlRequests = new BlockingCollection<CurlRequest>();
|
||||
|
||||
public bool IsSupported { get; private set; }
|
||||
|
||||
private class CurlRequest
|
||||
public class CurlRequest
|
||||
{
|
||||
public TaskCompletionSource<CurlResponse> TaskCompletion { get; private set; }
|
||||
|
||||
public string Url { get; private set; }
|
||||
|
||||
|
@ -36,7 +29,6 @@ namespace Jackett
|
|||
|
||||
public CurlRequest(HttpMethod method, string url, string cookies = null, string referer = null)
|
||||
{
|
||||
TaskCompletion = new TaskCompletionSource<CurlResponse>();
|
||||
Method = method;
|
||||
Url = url;
|
||||
Cookies = cookies;
|
||||
|
@ -70,54 +62,65 @@ namespace Jackett
|
|||
}
|
||||
}
|
||||
|
||||
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")
|
||||
{
|
||||
var rawCookies = h[1].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();
|
||||
}
|
||||
AddCookiesFromHeaderValue(h[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CurlResponse> GetAsync(string url, string cookies = null, string referer = null)
|
||||
public static async Task<CurlResponse> GetAsync(string url, string cookies = null, string referer = null)
|
||||
{
|
||||
var curlRequest = new CurlRequest(HttpMethod.Get, url, cookies, referer);
|
||||
curlRequests.Add(curlRequest);
|
||||
var result = await curlRequest.TaskCompletion.Task;
|
||||
var result = await PerformCurlAsync(curlRequest);
|
||||
var checkedResult = await FollowRedirect(url, result);
|
||||
return checkedResult;
|
||||
}
|
||||
|
||||
public async Task<CurlResponse> PostAsync(string url, Dictionary<string, string> formData, string cookies = null, string referer = null)
|
||||
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;
|
||||
curlRequests.Add(curlRequest);
|
||||
var result = await curlRequest.TaskCompletion.Task;
|
||||
var result = await PerformCurlAsync(curlRequest);
|
||||
var checkedResult = await FollowRedirect(url, result);
|
||||
return checkedResult;
|
||||
}
|
||||
|
||||
private async Task<CurlResponse> FollowRedirect(string url, CurlResponse response)
|
||||
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.Headers["set-cookie"];
|
||||
var redirectUrl = uri.Scheme + "://" + uri.Host + "/" + redirect;
|
||||
var newRedirect = await GetAsync(redirectUrl, cookie, url);
|
||||
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;
|
||||
}
|
||||
|
@ -125,88 +128,74 @@ namespace Jackett
|
|||
return response;
|
||||
}
|
||||
|
||||
public CurlHelper()
|
||||
|
||||
public static async Task<CurlResponse> PerformCurlAsync(CurlRequest curlRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
Curl.GlobalInit(CurlInitFlag.All);
|
||||
IsSupported = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
IsSupported = false;
|
||||
}
|
||||
Task.Run((Action)CurlServicer);
|
||||
return await Task.Run(() => PerformCurl(curlRequest));
|
||||
}
|
||||
|
||||
private void CurlServicer()
|
||||
public static CurlResponse PerformCurl(CurlRequest curlRequest)
|
||||
{
|
||||
foreach (var curlRequest in curlRequests.GetConsumingEnumerable())
|
||||
{
|
||||
PerformCurl(curlRequest);
|
||||
}
|
||||
}
|
||||
Curl.GlobalInit(CurlInitFlag.All);
|
||||
|
||||
private void PerformCurl(CurlRequest curlRequest)
|
||||
{
|
||||
var headerBuffers = new List<byte[]>();
|
||||
var contentBuffers = new List<byte[]>();
|
||||
try
|
||||
|
||||
using (var easy = new CurlEasy())
|
||||
{
|
||||
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) =>
|
||||
{
|
||||
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;
|
||||
};
|
||||
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.Cookies))
|
||||
easy.Cookie = curlRequest.Cookies;
|
||||
|
||||
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);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(curlRequest.Referer))
|
||||
easy.Referer = curlRequest.Referer;
|
||||
|
||||
easy.Perform();
|
||||
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);
|
||||
}
|
||||
|
||||
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 contentString = Encoding.UTF8.GetString (contentBytes);
|
||||
|
||||
var curlResponse = new CurlResponse(headers, contentBytes);
|
||||
curlResponse.AddCookiesFromHeaders(headers);
|
||||
curlRequest.TaskCompletion.SetResult(curlResponse);
|
||||
easy.Perform();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
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))
|
||||
{
|
||||
curlRequest.TaskCompletion.TrySetException(ex);
|
||||
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)
|
||||
|
|
|
@ -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 = "https://thepiratebay.se" };
|
||||
}
|
||||
|
||||
public override Item[] GetItems()
|
||||
|
@ -37,13 +37,12 @@ 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("https://thepiratebay.se"); } }
|
||||
|
||||
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";
|
||||
static string SearchUrl = "/s/?q=\"{0}\"&category=205&page=0&orderby=99";
|
||||
static string SwitchSingleViewUrl = "/switchview.php?view=s";
|
||||
|
||||
string BaseUrl;
|
||||
|
||||
|
@ -75,16 +74,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 +90,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 +100,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 +140,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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue