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

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

@ -94,6 +94,8 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -94,6 +94,8 @@ public class QBittorrentAdapter implements IDaemonAdapter {
private int qbLowPriority = 1;
private int qbNormalPriority = 2;
private int qbHighPriority = 7;
// a cache of all labels on the server
private List<Label> labelList;
public QBittorrentAdapter(DaemonSettings settings) {
this.settings = settings;
@ -245,7 +247,7 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -245,7 +247,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
if (allLabelsResult == null) {
allLabelsResult = new JSONArray();
}
final List<Label> labelList = parseJsonLabels(allLabelsResult, allTorrentsResult);
labelList = parseJsonLabels(allLabelsResult, allTorrentsResult);
return new RetrieveTaskSuccessResult((RetrieveTask) task, torrentsList, labelList);
case GetTorrentDetails:
@ -446,6 +448,20 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -446,6 +448,20 @@ public class QBittorrentAdapter implements IDaemonAdapter {
case SetLabel:
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) {
path = "/api/v2/torrents/setCategory";
} else {
@ -453,7 +469,7 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -453,7 +469,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
}
makeRequest(log, path,
new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID()),
new BasicNameValuePair("category", labelTask.getNewLabel()));
new BasicNameValuePair("category", newLabel));
return new DaemonTaskSuccessResult(task);
case SetDownloadLocation:

Loading…
Cancel
Save