Compare commits
9
Commits
c7110a15ea
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2747330a12 | ||
|
|
1772fad042 | ||
|
|
4e543be55b | ||
|
|
028147ab18 | ||
|
|
73b4e9a2c9 | ||
|
|
21b36199a6 | ||
|
|
41c911c8e9 | ||
|
|
f02f21a6dd | ||
|
|
6e32270dc6 |
@@ -1,9 +1,10 @@
|
|||||||
package cn.montaro.aria2;
|
package cn.montaro.aria2;
|
||||||
|
|
||||||
import cn.montaro.aria2.annotation.Aria2Method;
|
import cn.montaro.aria2.annotation.Aria2Method;
|
||||||
|
import cn.montaro.aria2.bean.GlobalStat;
|
||||||
import cn.montaro.aria2.bean.Task;
|
import cn.montaro.aria2.bean.Task;
|
||||||
|
import cn.montaro.aria2.bean.TaskFile;
|
||||||
import cn.montaro.aria2.constants.Aria2MethodName;
|
import cn.montaro.aria2.constants.Aria2MethodName;
|
||||||
import cn.montaro.aria2.resp.Aria2Status;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -66,13 +67,13 @@ public interface Aria2Client {
|
|||||||
|
|
||||||
// TODO: define return type
|
// TODO: define return type
|
||||||
@Aria2Method(Aria2MethodName.TELL_STATUS)
|
@Aria2Method(Aria2MethodName.TELL_STATUS)
|
||||||
Aria2Status tellStatus(String gid, String... keys);
|
Task tellStatus(String gid, String... keys);
|
||||||
|
|
||||||
@Aria2Method(Aria2MethodName.GET_URIS)
|
@Aria2Method(Aria2MethodName.GET_URIS)
|
||||||
String getUris(String gid);
|
String getUris(String gid);
|
||||||
|
|
||||||
@Aria2Method(Aria2MethodName.GET_FILES)
|
@Aria2Method(Aria2MethodName.GET_FILES)
|
||||||
String getFiles(String gid);
|
List<TaskFile> getFiles(String gid);
|
||||||
|
|
||||||
@Aria2Method(Aria2MethodName.GET_PEERS)
|
@Aria2Method(Aria2MethodName.GET_PEERS)
|
||||||
String getPeers(String gid);
|
String getPeers(String gid);
|
||||||
@@ -84,10 +85,10 @@ public interface Aria2Client {
|
|||||||
List<Task> tellActive(String... keys);
|
List<Task> tellActive(String... keys);
|
||||||
|
|
||||||
@Aria2Method(Aria2MethodName.TELL_WAITING)
|
@Aria2Method(Aria2MethodName.TELL_WAITING)
|
||||||
String tellWaiting(int offset, int num, String... keys);
|
List<Task> tellWaiting(int offset, int num, String... keys);
|
||||||
|
|
||||||
@Aria2Method(Aria2MethodName.TELL_STOPPED)
|
@Aria2Method(Aria2MethodName.TELL_STOPPED)
|
||||||
String tellStopped(int offset, int num, String... keys);
|
List<Task> tellStopped(int offset, int num, String... keys);
|
||||||
|
|
||||||
@Aria2Method(Aria2MethodName.CHANGE_POSITION)
|
@Aria2Method(Aria2MethodName.CHANGE_POSITION)
|
||||||
Integer changePosition(String gid, Integer pos, String how);
|
Integer changePosition(String gid, Integer pos, String how);
|
||||||
@@ -108,7 +109,7 @@ public interface Aria2Client {
|
|||||||
String changeGlobalOption(Map<String, String> options);
|
String changeGlobalOption(Map<String, String> options);
|
||||||
|
|
||||||
@Aria2Method(Aria2MethodName.GET_GLOBAL_STAT)
|
@Aria2Method(Aria2MethodName.GET_GLOBAL_STAT)
|
||||||
String getGlobalStat();
|
GlobalStat getGlobalStat();
|
||||||
|
|
||||||
@Aria2Method(Aria2MethodName.PURGE_DOWNLOAD_RESULT)
|
@Aria2Method(Aria2MethodName.PURGE_DOWNLOAD_RESULT)
|
||||||
String purgeDownloadResult();
|
String purgeDownloadResult();
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package cn.montaro.aria2.bean;
|
||||||
|
|
||||||
|
public class GlobalStat {
|
||||||
|
|
||||||
|
private Long downloadSpeed;
|
||||||
|
|
||||||
|
private Integer numActive;
|
||||||
|
|
||||||
|
private Integer numStopped;
|
||||||
|
|
||||||
|
private Integer numStoppedTotal;
|
||||||
|
|
||||||
|
private Integer numWaiting;
|
||||||
|
|
||||||
|
private Integer uploadSpeed;
|
||||||
|
|
||||||
|
public Integer getUploadSpeed() {
|
||||||
|
return uploadSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUploadSpeed(Integer uploadSpeed) {
|
||||||
|
this.uploadSpeed = uploadSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNumWaiting() {
|
||||||
|
return numWaiting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumWaiting(Integer numWaiting) {
|
||||||
|
this.numWaiting = numWaiting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNumStoppedTotal() {
|
||||||
|
return numStoppedTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumStoppedTotal(Integer numStoppedTotal) {
|
||||||
|
this.numStoppedTotal = numStoppedTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNumStopped() {
|
||||||
|
return numStopped;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumStopped(Integer numStopped) {
|
||||||
|
this.numStopped = numStopped;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNumActive() {
|
||||||
|
return numActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumActive(Integer numActive) {
|
||||||
|
this.numActive = numActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDownloadSpeed() {
|
||||||
|
return downloadSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadSpeed(Long downloadSpeed) {
|
||||||
|
this.downloadSpeed = downloadSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package cn.montaro.aria2.bean;
|
package cn.montaro.aria2.bean;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Task implements Serializable {
|
public class Task implements Serializable {
|
||||||
@@ -17,6 +18,39 @@ public class Task implements Serializable {
|
|||||||
|
|
||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
|
private String following;
|
||||||
|
|
||||||
|
private String dir;
|
||||||
|
|
||||||
|
private List<TaskFile> files;
|
||||||
|
|
||||||
|
public String getDir() {
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDir(String dir) {
|
||||||
|
this.dir = dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TaskFile> getFiles() {
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFiles(List<TaskFile> files) {
|
||||||
|
this.files = files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
if (Objects.isNull(dir) || this.files.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String name = files.get(0).getPath().replace(dir + "/", "");
|
||||||
|
if (name.length() <= 20) {
|
||||||
|
return String.format("%-20s", name);
|
||||||
|
}
|
||||||
|
return name.substring(0, 17) + "...";
|
||||||
|
}
|
||||||
|
|
||||||
public int getProgress() {
|
public int getProgress() {
|
||||||
if (Objects.isNull(completedLength)
|
if (Objects.isNull(completedLength)
|
||||||
|| completedLength == 0
|
|| completedLength == 0
|
||||||
@@ -75,4 +109,11 @@ public class Task implements Serializable {
|
|||||||
this.completedLength = completedLength;
|
this.completedLength = completedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFollowing() {
|
||||||
|
return following;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFollowing(String following) {
|
||||||
|
this.following = following;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package cn.montaro.aria2.bean;
|
||||||
|
|
||||||
|
public class TaskFile {
|
||||||
|
|
||||||
|
private int index;
|
||||||
|
|
||||||
|
private Long length;
|
||||||
|
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
private Long completedLength;
|
||||||
|
|
||||||
|
public Long getLength() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLength(Long length) {
|
||||||
|
this.length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndex(int index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCompletedLength() {
|
||||||
|
return completedLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompletedLength(Long completedLength) {
|
||||||
|
this.completedLength = completedLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -79,11 +79,20 @@ public class Aria2HttpProxy implements InvocationHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object deserialize(String json, Type resultType) {
|
private Object deserialize(String json, Type resultType) {
|
||||||
if (resultType.equals(String.class)) {
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
||||||
JsonElement result = jsonObject.get("result");
|
JsonElement result = jsonObject.get("result");
|
||||||
|
|
||||||
|
if (Objects.isNull(result)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultType.equals(String.class)) {
|
||||||
|
if (result.isJsonPrimitive()) {
|
||||||
|
return result.getAsJsonPrimitive().getAsString();
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
return gson.fromJson(result, resultType);
|
return gson.fromJson(result, resultType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import cn.hutool.core.collection.ListUtil;
|
|
||||||
import cn.montaro.aria2.Aria2Client;
|
|
||||||
import cn.montaro.aria2.Aria2ClientFactory;
|
|
||||||
import cn.montaro.aria2.Aria2Config;
|
|
||||||
import cn.montaro.aria2.resp.Aria2Status;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Aria2ClientTest {
|
|
||||||
|
|
||||||
Aria2Config config = new Aria2Config()
|
|
||||||
.setHost("localhost")
|
|
||||||
.setSecret("123456");
|
|
||||||
|
|
||||||
Aria2Client client = Aria2ClientFactory.httpClient(config);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
String gid = client.addUri(ListUtil.of("magnet:?xt=urn:btih:308f0122b1c3af5db9f3660775a6a2d81bd1e120"), null, null);
|
|
||||||
System.out.println("gid = " + gid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void status() {
|
|
||||||
String gid = "acc1c7d7c2043dba";
|
|
||||||
Aria2Status status = client.tellStatus(gid);
|
|
||||||
System.out.println(status);
|
|
||||||
List<String> followedBy = status.getFollowedBy();
|
|
||||||
if (followedBy != null && followedBy.size() != 0) {
|
|
||||||
gid = followedBy.get(0);
|
|
||||||
status = client.tellStatus(gid);
|
|
||||||
System.out.println(status);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user