public static void Main(string[] args) { int port = 5000; int uiPort = 5001; bool runWebUi = false; string input = null; string output = null; bool verbose = false; ArgumentSyntax.Parse(args, syntax => { syntax.DefineOption("p|port", ref port, "Port to listen for incoming connections on."); syntax.DefineOption("o|output", ref output, "Path to save downloaded files to."); syntax.DefineOption("v|verbose", ref verbose, "Show detailed logging information."); var uiPortArgument = syntax.DefineOption("ui", ref uiPort, false, "Run a web UI, optionally specifying the port to listen on (default: 5001)."); runWebUi = uiPortArgument.IsSpecified; syntax.DefineParameter("input", ref input, "Path of torrent file to download."); }); if (verbose) { LogManager.Configure(factory => factory.AddConsole(LogLevel.Debug)); } else { LogManager.Configure(factory => factory.AddConsole(LogLevel.Information)); } var client = new TorrentClient(port); var extensionProtocolModule = new ExtensionProtocolModule(); //extensionProtocolModule.RegisterMessageHandler(new PeerExchangeMessageHandler(client.AdapterAddress)); extensionProtocolModule.RegisterMessageHandler(new MetadataMessageHandler()); client.Modules.Register(extensionProtocolModule); if (runWebUi) { var uri = client.EnableWebUI(uiPort); Console.WriteLine($"Web UI started at {uri}"); } var download = client.Add(input, output); download.Start(); Console.WriteLine("Downloading..."); download.WaitForDownloadCompletionAsync().Wait(); Console.ReadKey(); }
public static Uri EnableWebUI(this TorrentClient client, int port) { var listenUri = new Uri($"http://localhost:{port}"); return(client.EnableWebUI(listenUri)); }