|
|
@ -234,17 +234,9 @@ public class QBittorrentAdapter implements IDaemonAdapter { |
|
|
|
path = "/json/events"; |
|
|
|
path = "/json/events"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
JSONArray allTorrentsResult = new JSONArray(makeRequest(log, path)); |
|
|
|
JSONArray result = new JSONArray(makeRequest(log, path)); |
|
|
|
final List<Torrent> torrentsList = parseJsonTorrents(allTorrentsResult); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray allLabelsResult; |
|
|
|
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonTorrents(result), parseJsonLabels(result)); |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
allLabelsResult = new JSONObject(makeRequest(log, "/api/v2/torrents/categories")).names(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
allLabelsResult = new JSONArray(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
final List<Label> labelList = parseJsonLabels(allLabelsResult, allTorrentsResult); |
|
|
|
|
|
|
|
return new RetrieveTaskSuccessResult((RetrieveTask) task, torrentsList, labelList); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case GetTorrentDetails: |
|
|
|
case GetTorrentDetails: |
|
|
|
|
|
|
|
|
|
|
@ -477,8 +469,8 @@ public class QBittorrentAdapter implements IDaemonAdapter { |
|
|
|
String ul = (ratesTask.getUploadRate() == null ? "NaN" : Long.toString(ratesTask.getUploadRate() * 1024)); |
|
|
|
String ul = (ratesTask.getUploadRate() == null ? "NaN" : Long.toString(ratesTask.getUploadRate() * 1024)); |
|
|
|
|
|
|
|
|
|
|
|
if (version >= 40100) { |
|
|
|
if (version >= 40100) { |
|
|
|
pathDL = "/api/v2/transfer/setDownloadLimit"; |
|
|
|
pathDL = "/api/v2/torrents/setDownloadLimit"; |
|
|
|
pathUL = "/api/v2/transfer/setUploadLimit"; |
|
|
|
pathUL = "/api/v2/torrents/setUploadLimit"; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
pathDL = "/command/setGlobalDlLimit"; |
|
|
|
pathDL = "/command/setGlobalDlLimit"; |
|
|
|
pathUL = "/command/setGlobalUpLimit"; |
|
|
|
pathUL = "/command/setGlobalUpLimit"; |
|
|
@ -656,25 +648,18 @@ public class QBittorrentAdapter implements IDaemonAdapter { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Label> parseJsonLabels(JSONArray allLabelsResponse, JSONArray allTorrentsResponse) throws JSONException { |
|
|
|
private List<Label> parseJsonLabels(JSONArray response) throws JSONException { |
|
|
|
|
|
|
|
|
|
|
|
// Collect used labels from torrents response
|
|
|
|
// Collect used labels from response
|
|
|
|
Map<String, Label> labels = new HashMap<>(); |
|
|
|
Map<String, Label> labels = new HashMap<>(); |
|
|
|
for (int i = 0; i < allTorrentsResponse.length(); i++) { |
|
|
|
for (int i = 0; i < response.length(); i++) { |
|
|
|
JSONObject tor = allTorrentsResponse.getJSONObject(i); |
|
|
|
JSONObject tor = response.getJSONObject(i); |
|
|
|
if (tor.has("category")) { |
|
|
|
if (tor.has("category")) { |
|
|
|
String label = tor.optString("category"); |
|
|
|
String label = tor.optString("category"); |
|
|
|
final Label labelObject = labels.get(label); |
|
|
|
final Label labelObject = labels.get(label); |
|
|
|
labels.put(label, new Label(label, (labelObject != null) ? labelObject.getCount() + 1 : 1)); |
|
|
|
labels.put(label, new Label(label, (labelObject != null) ? labelObject.getCount() + 1 : 1)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// add unused labels
|
|
|
|
|
|
|
|
for (int i = 0; i < allLabelsResponse.length(); i++) { |
|
|
|
|
|
|
|
String label = allLabelsResponse.getString(i); |
|
|
|
|
|
|
|
if (!labels.containsKey(label)) { |
|
|
|
|
|
|
|
labels.put(label, new Label(label, 0)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return new ArrayList<>(labels.values()); |
|
|
|
return new ArrayList<>(labels.values()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|