mirror of https://github.com/Jackett/Jackett
Now works on Linux (headless), detailed logging, season searching
This commit is contained in:
parent
ac003e7a78
commit
dce596ed1a
|
@ -89,8 +89,10 @@ namespace Jackett
|
|||
{
|
||||
var browseQuery = new TorznabQuery();
|
||||
var results = await indexer.PerformQuery(browseQuery);
|
||||
Program.LoggerInstance.Debug(string.Format("Found {0} releases from {1}", results.Length, indexer.DisplayName));
|
||||
if (results.Length == 0)
|
||||
throw new Exception("Found no results while trying to browse this tracker");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,12 +23,18 @@ namespace Jackett
|
|||
toolStripMenuItemAutoStart.Checked = AutoStart;
|
||||
toolStripMenuItemAutoStart.CheckedChanged += toolStripMenuItemAutoStart_CheckedChanged;
|
||||
|
||||
toolStripMenuItemWebUI.Click += toolStripMenuItemWebUI_Click;
|
||||
toolStripMenuItemShutdown.Click += toolStripMenuItemShutdown_Click;
|
||||
|
||||
if (Program.IsFirstRun)
|
||||
AutoStart = true;
|
||||
}
|
||||
|
||||
void toolStripMenuItemWebUI_Click(object sender, EventArgs e)
|
||||
{
|
||||
Process.Start("http://127.0.0.1:" + Server.Port);
|
||||
}
|
||||
|
||||
void toolStripMenuItemShutdown_Click(object sender, EventArgs e)
|
||||
{
|
||||
Application.Exit();
|
||||
|
|
|
@ -24,8 +24,12 @@ namespace Jackett
|
|||
|
||||
public static Logger LoggerInstance { get; private set; }
|
||||
|
||||
public static ManualResetEvent ExitEvent { get; private set; }
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
ExitEvent = new ManualResetEvent(false);
|
||||
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(AppConfigDirectory))
|
||||
|
@ -46,31 +50,45 @@ namespace Jackett
|
|||
var logFile = new FileTarget();
|
||||
logConfig.AddTarget("file", logFile);
|
||||
logFile.FileName = Path.Combine(AppConfigDirectory, "log.txt");
|
||||
logFile.Layout = "${longdate} ${level} ${message}";
|
||||
logFile.Layout = "${longdate} ${level} ${message} \n ${exception:format=ToString}\n";
|
||||
var logFileRule = new LoggingRule("*", LogLevel.Debug, logFile);
|
||||
|
||||
var logAlert = new MessageBoxTarget();
|
||||
logConfig.AddTarget("alert", logAlert);
|
||||
logAlert.Layout = "${message}";
|
||||
logAlert.Caption = "Alert";
|
||||
var logAlertRule = new LoggingRule("*", LogLevel.Error, logAlert);
|
||||
var logAlertRule = new LoggingRule("*", LogLevel.Fatal, logAlert);
|
||||
|
||||
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(logFileRule);
|
||||
logConfig.LoggingRules.Add(logAlertRule);
|
||||
logConfig.LoggingRules.Add(logConsoleRule);
|
||||
LogManager.Configuration = logConfig;
|
||||
LoggerInstance = LogManager.GetCurrentClassLogger();
|
||||
|
||||
Task.Run(() =>
|
||||
var serverTask = Task.Run(async () =>
|
||||
{
|
||||
ServerInstance = new Server();
|
||||
ServerInstance.Start();
|
||||
await ServerInstance.Start();
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Main());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Running in headless mode.");
|
||||
}
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Main());
|
||||
|
||||
Task.WaitAll(serverTask);
|
||||
Console.WriteLine("Server thread exit");
|
||||
}
|
||||
|
||||
static public void RestartAsAdmin()
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Jackett
|
|||
{
|
||||
public class Server
|
||||
{
|
||||
int Port = 9117;
|
||||
public const int Port = 9117;
|
||||
|
||||
HttpListener listener;
|
||||
IndexerManager indexerManager;
|
||||
|
@ -46,17 +46,17 @@ namespace Jackett
|
|||
}
|
||||
}
|
||||
|
||||
public async void Start()
|
||||
public async Task Start()
|
||||
{
|
||||
Program.LoggerInstance.Info("Starting HTTP server...");
|
||||
|
||||
try
|
||||
{
|
||||
listener.Start();
|
||||
Process.Start("http://127.0.0.1:" + Port);
|
||||
}
|
||||
catch (HttpListenerException ex)
|
||||
{
|
||||
Console.WriteLine("Server start exception: " + ex.ToString());
|
||||
var dialogResult = MessageBox.Show(
|
||||
"App must be ran as Admin for permission to use port " + Port + Environment.NewLine + "Restart app with admin privileges?",
|
||||
"Failed to open port",
|
||||
|
@ -75,10 +75,18 @@ namespace Jackett
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Server start exception: " + ex.ToString());
|
||||
Program.LoggerInstance.ErrorException("Error: " + ex.Message, ex);
|
||||
return;
|
||||
}
|
||||
Program.LoggerInstance.Info("Server started on port " + Port);
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start("http://127.0.0.1:" + Port);
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
while (true)
|
||||
{
|
||||
var context = await listener.GetContextAsync();
|
||||
|
@ -115,6 +123,7 @@ namespace Jackett
|
|||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
Program.LoggerInstance.ErrorException(ex.Message + ex.ToString(), ex);
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
|
@ -127,7 +136,11 @@ namespace Jackett
|
|||
catch (Exception) { }
|
||||
}
|
||||
|
||||
context.Response.Close();
|
||||
try
|
||||
{
|
||||
context.Response.Close();
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
}
|
||||
|
||||
|
@ -157,6 +170,8 @@ namespace Jackett
|
|||
|
||||
var releases = await indexer.PerformQuery(torznabQuery);
|
||||
|
||||
Program.LoggerInstance.Debug(string.Format("Found {0} releases from {1}", releases.Length, indexer.DisplayName));
|
||||
|
||||
var severUrl = string.Format("{0}://{1}:{2}/", context.Request.Url.Scheme, context.Request.Url.Host, context.Request.Url.Port);
|
||||
|
||||
var resultPage = new ResultPage(new ChannelInfo
|
||||
|
|
|
@ -30,6 +30,8 @@ namespace Jackett
|
|||
DateTime showDate;
|
||||
if (DateTime.TryParseExact(string.Format("{0} {1}", Season, Episode), "yyyy MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out showDate))
|
||||
episodeString = showDate.ToString("yyyy.MM.dd");
|
||||
else if (string.IsNullOrEmpty(Episode))
|
||||
episodeString = string.Format("S{0:00}", Season);
|
||||
else
|
||||
episodeString = string.Format("S{0:00}E{1:00}", Season, int.Parse(Episode));
|
||||
|
||||
|
|
|
@ -131,13 +131,20 @@ namespace Jackett
|
|||
break;
|
||||
}
|
||||
JToken jsonReply = await handlerTask(context);
|
||||
ReplyWithJson(context, jsonReply);
|
||||
await ReplyWithJson(context, jsonReply, method.ToString());
|
||||
}
|
||||
|
||||
async void ReplyWithJson(HttpListenerContext context, JToken json)
|
||||
async Task ReplyWithJson(HttpListenerContext context, JToken json, string apiCall)
|
||||
{
|
||||
byte[] jsonBytes = Encoding.UTF8.GetBytes(json.ToString());
|
||||
await context.Response.OutputStream.WriteAsync(jsonBytes, 0, jsonBytes.Length);
|
||||
try
|
||||
{
|
||||
byte[] jsonBytes = Encoding.UTF8.GetBytes(json.ToString());
|
||||
await context.Response.OutputStream.WriteAsync(jsonBytes, 0, jsonBytes.Length);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error writing json to stream for API call " + apiCall + Environment.NewLine + ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
async Task<JToken> HandleTestSonarr(HttpListenerContext context)
|
||||
|
|
Loading…
Reference in New Issue