Browse Source

Merge pull request #642 from bwitt/qbittorrent-add-new-label

Fix qBittorrent to support adding new label to torrents
pull/648/head
Eric Kok 12 months ago committed by GitHub
parent
commit
87bba074b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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;
@ -245,7 +247,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
if (allLabelsResult == null) { if (allLabelsResult == null) {
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:
@ -446,6 +448,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 {
@ -453,7 +469,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