Browse Source

Fix qbittorrent add new label to torrents

pull/642/head
Brian Witt 2 years ago
parent
commit
6c68d4e153
  1. 6
      app/src/main/java/org/transdroid/daemon/Label.java
  2. 20
      app/src/main/java/org/transdroid/daemon/adapters/qBittorrent/QBittorrentAdapter.java

6
app/src/main/java/org/transdroid/daemon/Label.java

@ -69,6 +69,12 @@ public final class Label implements Parcelable, Comparable<Label> {
return name.compareTo(another.getName()); return name.compareTo(another.getName());
} }
@Override
public boolean equals(Object another) {
// compare names
return name.equals(((Label) another).getName());
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;

20
app/src/main/java/org/transdroid/daemon/adapters/qBittorrent/QBittorrentAdapter.java

@ -94,6 +94,8 @@ public class QBittorrentAdapter implements IDaemonAdapter {
private int qbLowPriority = 1; private int qbLowPriority = 1;
private int qbNormalPriority = 2; private int qbNormalPriority = 2;
private int qbHighPriority = 7; private int qbHighPriority = 7;
// a cache of all labels on the server
private List<Label> labelList;
public QBittorrentAdapter(DaemonSettings settings) { public QBittorrentAdapter(DaemonSettings settings) {
this.settings = settings; this.settings = settings;
@ -243,7 +245,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
} else { } else {
allLabelsResult = new JSONArray(); allLabelsResult = new JSONArray();
} }
final List<Label> labelList = parseJsonLabels(allLabelsResult, allTorrentsResult); labelList = parseJsonLabels(allLabelsResult, allTorrentsResult);
return new RetrieveTaskSuccessResult((RetrieveTask) task, torrentsList, labelList); return new RetrieveTaskSuccessResult((RetrieveTask) task, torrentsList, labelList);
case GetTorrentDetails: case GetTorrentDetails:
@ -444,6 +446,20 @@ public class QBittorrentAdapter implements IDaemonAdapter {
case SetLabel: case SetLabel:
SetLabelTask labelTask = (SetLabelTask) task; SetLabelTask labelTask = (SetLabelTask) task;
String newLabel = labelTask.getNewLabel();
if (version >= 30200) {
if (!labelList.contains(new Label(newLabel, 0))) {
// create new label on server side
if (version >= 40100) {
path = "/api/v2/torrents/createCategory";
} else {
path = "/command/addCategory";
}
makeRequest(log, path,
new BasicNameValuePair("category", newLabel));
}
}
if (version >= 40100) { if (version >= 40100) {
path = "/api/v2/torrents/setCategory"; path = "/api/v2/torrents/setCategory";
} else { } else {
@ -451,7 +467,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
} }
makeRequest(log, path, makeRequest(log, path,
new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID()), new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID()),
new BasicNameValuePair("category", labelTask.getNewLabel())); new BasicNameValuePair("category", newLabel));
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case SetDownloadLocation: case SetDownloadLocation:

Loading…
Cancel
Save