Skip to content

Commit

Permalink
Added referer and rpc port.
Browse files Browse the repository at this point in the history
  • Loading branch information
matiffeder committed Nov 9, 2017
1 parent bf86096 commit 266c72b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.



Expand All @@ -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.



Expand Down
32 changes: 25 additions & 7 deletions aria2m/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
//}
Expand Down Expand Up @@ -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();
Expand All @@ -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"))
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand Down

0 comments on commit 266c72b

Please sign in to comment.