From 266c72b372a2fb3fe7432db1a8560a75afddf614 Mon Sep 17 00:00:00 2001 From: matiffeder Date: Thu, 9 Nov 2017 18:54:16 +0800 Subject: [PATCH] Added referer and rpc port. --- README.md | 5 +++-- aria2m/Program.cs | 32 +++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e47c744..539fbfa 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Features: * Open most of local aria2's webui via trayicon. * Easily to add download links without open another aria2c (You need browser add-on like FlashGot). * Save session when you close aria2 by aria2m or exit aria2m. -* Work fine with rpc-secret. +* Work fine with rpc-secret and rpc-listen-port.   @@ -30,7 +30,8 @@ The structure in your aria2m folder must like: ```   -The arguments template in FlashGot (or other add-on) must be `[URL] [FOLDER]` or `[URL]`. +The arguments template in FlashGot (or other add-on) must be `[URL] [REFERER] [FOLDER]` or `[URL] [REFERER]`. +There is a space between arguments.   diff --git a/aria2m/Program.cs b/aria2m/Program.cs index a6d9c09..4e431a3 100644 --- a/aria2m/Program.cs +++ b/aria2m/Program.cs @@ -59,7 +59,7 @@ public void Arg_Call(string[] args) Toggle_aria2(null, null); //Clipboard.SetText(copytxt); //trayicon.ShowBalloonTip(3000, "Texts copied.", copytxt, ToolTipIcon.None); - if (Call_RPC("addUri", args[0], args[1])) + if (Call_RPC("addUri", args[0], args[1], args[2])) trayicon.ShowBalloonTip(3000, "Link added.", args[0], ToolTipIcon.None); //copytxt = null; //} @@ -119,7 +119,7 @@ private static void Close_aria2(object Sender, EventArgs e, bool exit) if (!exit || Process.GetProcessesByName("aria2c").Length > 0) { //aria2.shutdown need wait 3 seconds - Call_RPC("saveSession", null, null); + Call_RPC("saveSession", null, null, null); //Thread.Sleep(1000); //if aria2c not open at this time in the program, there is no aria2c //aria2c.CloseMainWindow(); @@ -142,7 +142,7 @@ private static void Close_aria2(object Sender, EventArgs e, bool exit) } } - private static bool Call_RPC(string method, string uri, string dir) + private static bool Call_RPC(string method, string uri, string refer, string dir) { string secret = ""; foreach (var line in File.ReadLines(AppDomain.CurrentDomain.BaseDirectory + "aria2.conf")) @@ -153,16 +153,26 @@ private static bool Call_RPC(string method, string uri, string dir) break; } } + string port = "6800"; + foreach (var line in File.ReadLines(AppDomain.CurrentDomain.BaseDirectory + "aria2.conf")) + { + if (line.StartsWith("rpc-listen-port")) + { + port = line.Substring(16); + break; + } + } if (dir != null) - dir = ", {\"dir\": \"" + dir.Replace("\\", "/") + "\"}"; + dir = "\"dir\": \"" + dir.Replace("\\", "/") + "\""; try { //string json = JsonConvert.SerializeObject(new JObject { ["jsonrpc"] = "2.0", ["id"] = "m", ["method"] = "aria2." + method, ["params"] = new JArray { "token:secret", new JArray { "https://github.com/master.zip" } } }); using (var webClient = new WebClient()) { webClient.Encoding = System.Text.Encoding.UTF8; - webClient.UploadString("http://localhost:6800/jsonrpc", "POST", "{ \"jsonrpc\": \"2.0\", \"id\": \"m\", \"method\": \"aria2." + method + "\", \"params\": [\"token:" + secret + "\", [\"" + uri + "\"]" + dir + "] }"); + webClient.UploadString("http://localhost:" + port + "/jsonrpc", "POST", "{ \"jsonrpc\": \"2.0\", \"id\": \"m\", \"method\": \"aria2." + method + "\", \"params\": [\"token:" + secret + "\", [\"" + uri + "\"], {\"referer\": \"" + refer + "\", " + dir + " } ] }"); secret = null; + port = null; return true; } //json = null; @@ -220,7 +230,11 @@ static void Main(string[] args) // program is already running. app.Startup += (s, e) => trayManager = new TrayManager(); if (args.Length > 0) - app.Startup += (s, e) => trayManager.Arg_Call(new string[] { e.CommandLine[0], e.CommandLine.Count == 2 ? e.CommandLine[1] : null }); + app.Startup += (s, e) => trayManager.Arg_Call(new string[] { + e.CommandLine[0], + e.CommandLine.Count > 1 ? e.CommandLine[1] : null, + e.CommandLine.Count > 2 ? e.CommandLine[2] : null + }); /*void start_Call(object sender, StartupEventArgs e) { trayManager = new TrayManager(); @@ -238,7 +252,11 @@ static void Main(string[] args) void next_Call(object sender, StartupNextInstanceEventArgs e) { if (e.CommandLine.Count > 0) - trayManager.Arg_Call(new string[] { e.CommandLine[0], e.CommandLine.Count == 2 ? e.CommandLine[1] : null }); + trayManager.Arg_Call(new string[] { + e.CommandLine[0], + e.CommandLine.Count > 1 ? e.CommandLine[1] : null, + e.CommandLine.Count > 2 ? e.CommandLine[2] : null + }); } app.StartupNextInstance += new StartupNextInstanceEventHandler(next_Call);