|
|
@ -17,7 +17,61 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.transdroid.daemon.Deluge; |
|
|
|
package org.transdroid.daemon.Deluge; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.support.annotation.NonNull; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.base64.android.Base64; |
|
|
|
|
|
|
|
import org.transdroid.core.gui.log.Log; |
|
|
|
|
|
|
|
import org.transdroid.daemon.Daemon; |
|
|
|
|
|
|
|
import org.transdroid.daemon.DaemonException; |
|
|
|
|
|
|
|
import org.transdroid.daemon.DaemonException.ExceptionType; |
|
|
|
|
|
|
|
import org.transdroid.daemon.DaemonSettings; |
|
|
|
|
|
|
|
import org.transdroid.daemon.IDaemonAdapter; |
|
|
|
|
|
|
|
import org.transdroid.daemon.Label; |
|
|
|
|
|
|
|
import org.transdroid.daemon.Priority; |
|
|
|
|
|
|
|
import org.transdroid.daemon.Torrent; |
|
|
|
|
|
|
|
import org.transdroid.daemon.TorrentDetails; |
|
|
|
|
|
|
|
import org.transdroid.daemon.TorrentFile; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.AddByFileTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.AddByMagnetUrlTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.AddByUrlTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.DaemonTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.DaemonTaskFailureResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.DaemonTaskResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.DaemonTaskSuccessResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.ForceRecheckTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetFileListTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetFileListTaskSuccessResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetTorrentDetailsTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.RemoveTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.RetrieveTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.RetrieveTaskSuccessResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetDownloadLocationTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetFilePriorityTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetLabelTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetTrackersTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetTransferRatesTask; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream; |
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.net.URI; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Map.Entry; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS_FIELDS_ARRAY; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DOWNLOADEDEVER; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DOWNLOADEDEVER; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_ETA; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_ETA; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FIELDS_ARRAY; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FIELDS_ARRAY; |
|
|
@ -59,71 +113,18 @@ import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_RATEUPLOAD; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SAVEPATH; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SAVEPATH; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SIZE; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_SIZE; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS_FIELDS_ARRAY; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TIER; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TIMEADDED; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TIMEADDED; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALPEERS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALPEERS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSEEDS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSEEDS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSIZE; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSIZE; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKERS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKERS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_STATUS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_STATUS; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TIER; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_URL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_UPLOADEDEVER; |
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_UPLOADEDEVER; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_URL; |
|
|
|
import android.support.annotation.NonNull; |
|
|
|
|
|
|
|
import java.io.BufferedInputStream; |
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.net.URI; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Map.Entry; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
import org.base64.android.Base64; |
|
|
|
|
|
|
|
import org.transdroid.core.gui.log.Log; |
|
|
|
|
|
|
|
import org.transdroid.daemon.Daemon; |
|
|
|
|
|
|
|
import org.transdroid.daemon.DaemonException; |
|
|
|
|
|
|
|
import org.transdroid.daemon.DaemonException.ExceptionType; |
|
|
|
|
|
|
|
import org.transdroid.daemon.DaemonSettings; |
|
|
|
|
|
|
|
import org.transdroid.daemon.IDaemonAdapter; |
|
|
|
|
|
|
|
import org.transdroid.daemon.Label; |
|
|
|
|
|
|
|
import org.transdroid.daemon.Priority; |
|
|
|
|
|
|
|
import org.transdroid.daemon.Torrent; |
|
|
|
|
|
|
|
import org.transdroid.daemon.TorrentDetails; |
|
|
|
|
|
|
|
import org.transdroid.daemon.TorrentFile; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.AddByFileTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.AddByMagnetUrlTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.AddByUrlTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.DaemonTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.DaemonTaskFailureResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.DaemonTaskResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.DaemonTaskSuccessResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.ForceRecheckTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetFileListTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetFileListTaskSuccessResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetTorrentDetailsTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetTorrentDetailsTaskSuccessResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.RemoveTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.RetrieveTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.RetrieveTaskSuccessResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetDownloadLocationTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetFilePriorityTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetLabelTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetTrackersTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.SetTransferRatesTask; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The daemon adapter from the Deluge torrent client using deluged API directly. |
|
|
|
* The daemon adapter from the Deluge torrent client using deluged API directly. |
|
|
|
* |
|
|
|
|
|
|
|
* @author alon.albert |
|
|
|
* @author alon.albert |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
@ -142,7 +143,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
public DaemonTaskResult executeTask(Log log, DaemonTask task) { |
|
|
|
public DaemonTaskResult executeTask(Log log, DaemonTask task) { |
|
|
|
final DelugeRpcClient client = new DelugeRpcClient(); |
|
|
|
final DelugeRpcClient client = new DelugeRpcClient(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
client.connect(settings.getAddress(), settings.getPort(), settings.getUsername(), settings.getPassword()); |
|
|
|
client.connect(settings); |
|
|
|
switch (task.getMethod()) { |
|
|
|
switch (task.getMethod()) { |
|
|
|
case Retrieve: |
|
|
|
case Retrieve: |
|
|
|
return doRetrieve(client, (RetrieveTask) task); |
|
|
|
return doRetrieve(client, (RetrieveTask) task); |
|
|
@ -179,9 +180,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
case ForceRecheck: |
|
|
|
case ForceRecheck: |
|
|
|
return doForceRecheck(client, (ForceRecheckTask) task); |
|
|
|
return doForceRecheck(client, (ForceRecheckTask) task); |
|
|
|
default: |
|
|
|
default: |
|
|
|
return new DaemonTaskFailureResult(task, |
|
|
|
return new DaemonTaskFailureResult(task, new DaemonException(ExceptionType.MethodUnsupported, task.getMethod() + " is not " + |
|
|
|
new DaemonException(ExceptionType.MethodUnsupported, |
|
|
|
"supported by " + getType())); |
|
|
|
task.getMethod() + " is not supported by " + getType())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (DaemonException e) { |
|
|
|
} catch (DaemonException e) { |
|
|
|
return new DaemonTaskFailureResult(task, e); |
|
|
|
return new DaemonTaskFailureResult(task, e); |
|
|
@ -204,8 +204,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
private RetrieveTaskSuccessResult doRetrieve(DelugeRpcClient client, RetrieveTask task) throws DaemonException { |
|
|
|
private RetrieveTaskSuccessResult doRetrieve(DelugeRpcClient client, RetrieveTask task) throws DaemonException { |
|
|
|
// Get torrents
|
|
|
|
// Get torrents
|
|
|
|
//noinspection unchecked
|
|
|
|
//noinspection unchecked
|
|
|
|
final Map<String, Map<String, Object>> torrentsStatus = (Map<String, Map<String, Object>>) client |
|
|
|
final Map<String, Map<String, Object>> torrentsStatus = (Map<String, Map<String, Object>>) client.sendRequest |
|
|
|
.sendRequest(RPC_METHOD_GET_TORRENTS_STATUS, new HashMap<>(), RPC_FIELDS_ARRAY); |
|
|
|
(RPC_METHOD_GET_TORRENTS_STATUS, new HashMap<>(), RPC_FIELDS_ARRAY); |
|
|
|
final List<Torrent> torrents = getTorrents(torrentsStatus.values()); |
|
|
|
final List<Torrent> torrents = getTorrents(torrentsStatus.values()); |
|
|
|
|
|
|
|
|
|
|
|
// Check if Label plugin is enabled
|
|
|
|
// Check if Label plugin is enabled
|
|
|
@ -213,9 +213,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
|
|
|
|
|
|
|
|
// Get label list from server
|
|
|
|
// Get label list from server
|
|
|
|
//noinspection unchecked
|
|
|
|
//noinspection unchecked
|
|
|
|
final List<String> labelNames = hasLabelPlugin |
|
|
|
final List<String> labelNames = hasLabelPlugin ? (List<String>) client.sendRequest(RPC_METHOD_GET_LABELS) : new ArrayList<String>(); |
|
|
|
? (List<String>) client.sendRequest(RPC_METHOD_GET_LABELS) |
|
|
|
|
|
|
|
: new ArrayList<String>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Extract labels & counts from torrents.
|
|
|
|
// Extract labels & counts from torrents.
|
|
|
|
final List<Label> labels = getLabels(labelNames, torrents); |
|
|
|
final List<Label> labels = getLabels(labelNames, torrents); |
|
|
@ -223,49 +221,39 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
return new RetrieveTaskSuccessResult(task, torrents, labels); |
|
|
|
return new RetrieveTaskSuccessResult(task, torrents, labels); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private GetTorrentDetailsTaskSuccessResult doGetTorrentDetails(DelugeRpcClient client, |
|
|
|
private GetTorrentDetailsTaskSuccessResult doGetTorrentDetails(DelugeRpcClient client, GetTorrentDetailsTask task) throws DaemonException { |
|
|
|
GetTorrentDetailsTask task) |
|
|
|
|
|
|
|
throws DaemonException { |
|
|
|
|
|
|
|
//noinspection unchecked
|
|
|
|
//noinspection unchecked
|
|
|
|
final Map<String, Object> response = (Map<String, Object>) client.sendRequest( |
|
|
|
final Map<String, Object> response = (Map<String, Object>) client.sendRequest(RPC_METHOD_STATUS, task.getTargetTorrent().getUniqueID(), |
|
|
|
RPC_METHOD_STATUS, |
|
|
|
|
|
|
|
task.getTargetTorrent().getUniqueID(), |
|
|
|
|
|
|
|
RPC_DETAILS_FIELDS_ARRAY); |
|
|
|
RPC_DETAILS_FIELDS_ARRAY); |
|
|
|
|
|
|
|
|
|
|
|
//noinspection unchecked
|
|
|
|
//noinspection unchecked
|
|
|
|
final List<Map<String, Object>> trackerResponses = (List<Map<String, Object>>) response |
|
|
|
final List<Map<String, Object>> trackerResponses = (List<Map<String, Object>>) response.get(RPC_TRACKERS); |
|
|
|
.get(RPC_TRACKERS); |
|
|
|
|
|
|
|
final List<String> trackers = new ArrayList<>(); |
|
|
|
final List<String> trackers = new ArrayList<>(); |
|
|
|
for (Map<String, Object> trackerResponse : trackerResponses) { |
|
|
|
for (Map<String, Object> trackerResponse : trackerResponses) { |
|
|
|
trackers.add((String) trackerResponse.get(RPC_URL)); |
|
|
|
trackers.add((String) trackerResponse.get(RPC_URL)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new GetTorrentDetailsTaskSuccessResult(task, new TorrentDetails( |
|
|
|
return new GetTorrentDetailsTaskSuccessResult(task, new TorrentDetails(trackers, Collections.singletonList((String) response.get |
|
|
|
trackers, |
|
|
|
(RPC_TRACKER_STATUS)))); |
|
|
|
Collections.singletonList((String) response.get(RPC_TRACKER_STATUS)))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private GetFileListTaskSuccessResult doGetFileList(DelugeRpcClient client, |
|
|
|
private GetFileListTaskSuccessResult doGetFileList(DelugeRpcClient client, GetFileListTask task) throws DaemonException { |
|
|
|
GetFileListTask task) throws DaemonException { |
|
|
|
|
|
|
|
final ArrayList<TorrentFile> files = getTorrentFiles(client, task.getTargetTorrent()); |
|
|
|
final ArrayList<TorrentFile> files = getTorrentFiles(client, task.getTargetTorrent()); |
|
|
|
return new GetFileListTaskSuccessResult(task, files); |
|
|
|
return new GetFileListTaskSuccessResult(task, files); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private DaemonTaskResult doControl(DelugeRpcClient client, DaemonTask task, |
|
|
|
private DaemonTaskResult doControl(DelugeRpcClient client, DaemonTask task, String method) throws DaemonException { |
|
|
|
String method) throws DaemonException { |
|
|
|
|
|
|
|
client.sendRequest(method, (Object) getTorrentIdsArg(task)); |
|
|
|
client.sendRequest(method, (Object) getTorrentIdsArg(task)); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private DaemonTaskResult doRemove(DelugeRpcClient client, RemoveTask task) throws DaemonException { |
|
|
|
private DaemonTaskResult doRemove(DelugeRpcClient client, RemoveTask task) throws DaemonException { |
|
|
|
client.sendRequest(RPC_METHOD_REMOVE, task.getTargetTorrent().getUniqueID(), |
|
|
|
client.sendRequest(RPC_METHOD_REMOVE, task.getTargetTorrent().getUniqueID(), task.includingData()); |
|
|
|
task.includingData()); |
|
|
|
|
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doControlAll(DelugeRpcClient client, DaemonTask task, |
|
|
|
private DaemonTaskResult doControlAll(DelugeRpcClient client, DaemonTask task, String method) throws DaemonException { |
|
|
|
String method) throws DaemonException { |
|
|
|
|
|
|
|
client.sendRequest(method); |
|
|
|
client.sendRequest(method); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
} |
|
|
|
} |
|
|
@ -285,8 +273,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doAddByMagnetUrl(DelugeRpcClient client, |
|
|
|
private DaemonTaskResult doAddByMagnetUrl(DelugeRpcClient client, AddByMagnetUrlTask task) throws DaemonException { |
|
|
|
AddByMagnetUrlTask task) throws DaemonException { |
|
|
|
|
|
|
|
client.sendRequest(RPC_METHOD_ADD_MAGNET, task.getUrl(), new HashMap<>()); |
|
|
|
client.sendRequest(RPC_METHOD_ADD_MAGNET, task.getUrl(), new HashMap<>()); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
} |
|
|
|
} |
|
|
@ -303,8 +290,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doSetFilePriorities(DelugeRpcClient client, |
|
|
|
private DaemonTaskResult doSetFilePriorities(DelugeRpcClient client, SetFilePriorityTask task) throws DaemonException { |
|
|
|
SetFilePriorityTask task) throws DaemonException { |
|
|
|
|
|
|
|
// We first need a listing of all the files (because we can only set the priorities all at once)
|
|
|
|
// We first need a listing of all the files (because we can only set the priorities all at once)
|
|
|
|
final ArrayList<TorrentFile> files = getTorrentFiles(client, task.getTargetTorrent()); |
|
|
|
final ArrayList<TorrentFile> files = getTorrentFiles(client, task.getTargetTorrent()); |
|
|
|
|
|
|
|
|
|
|
@ -331,8 +317,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doSetTransferRates(DelugeRpcClient client, |
|
|
|
private DaemonTaskResult doSetTransferRates(DelugeRpcClient client, SetTransferRatesTask task) throws DaemonException { |
|
|
|
SetTransferRatesTask task) throws DaemonException { |
|
|
|
|
|
|
|
final Map<String, Object> config = new HashMap<>(); |
|
|
|
final Map<String, Object> config = new HashMap<>(); |
|
|
|
config.put(RPC_MAXDOWNLOAD, task.getDownloadRate() == null ? -1 : task.getDownloadRate()); |
|
|
|
config.put(RPC_MAXDOWNLOAD, task.getDownloadRate() == null ? -1 : task.getDownloadRate()); |
|
|
|
config.put(RPC_MAXUPLOAD, task.getUploadRate() == null ? -1 : task.getUploadRate()); |
|
|
|
config.put(RPC_MAXUPLOAD, task.getUploadRate() == null ? -1 : task.getUploadRate()); |
|
|
@ -361,14 +346,13 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doSetDownloadLocation(DelugeRpcClient client, |
|
|
|
private DaemonTaskResult doSetDownloadLocation(DelugeRpcClient client, SetDownloadLocationTask task) throws DaemonException { |
|
|
|
SetDownloadLocationTask task) throws DaemonException { |
|
|
|
|
|
|
|
client.sendRequest(RPC_METHOD_MOVESTORAGE, getTorrentIdsArg(task), task.getNewLocation()); |
|
|
|
client.sendRequest(RPC_METHOD_MOVESTORAGE, getTorrentIdsArg(task), task.getNewLocation()); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private List<Torrent> getTorrents(Collection<Map<String, Object>> torrentMaps) throws DaemonException { |
|
|
|
private List<Torrent> getTorrents(Collection<Map<String, Object>> torrentMaps) { |
|
|
|
final List<Torrent> torrents = new ArrayList<>(); |
|
|
|
final List<Torrent> torrents = new ArrayList<>(); |
|
|
|
int id = 0; |
|
|
|
int id = 0; |
|
|
|
for (Map<String, Object> torrentMap : torrentMaps) { |
|
|
|
for (Map<String, Object> torrentMap : torrentMaps) { |
|
|
@ -390,35 +374,21 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
error = message; |
|
|
|
error = message; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
torrents.add(new Torrent( |
|
|
|
torrents.add(new Torrent(id++, (String) torrentMap.get(RPC_HASH), (String) torrentMap.get(RPC_NAME), DelugeCommon.convertDelugeState( |
|
|
|
id++, |
|
|
|
(String) torrentMap.get(RPC_STATUS)), torrentMap.get(RPC_SAVEPATH) + settings.getOS().getPathSeperator(), ((Number) torrentMap |
|
|
|
(String) torrentMap.get(RPC_HASH), |
|
|
|
.get(RPC_RATEDOWNLOAD)).intValue(), ((Number) torrentMap.get(RPC_RATEUPLOAD)).intValue(), ((Number) torrentMap.get |
|
|
|
(String) torrentMap.get(RPC_NAME), |
|
|
|
(RPC_NUMSEEDS)).intValue(), ((Number) torrentMap.get(RPC_TOTALSEEDS)).intValue(), ((Number) torrentMap.get(RPC_NUMPEERS)) |
|
|
|
DelugeCommon.convertDelugeState((String) torrentMap.get(RPC_STATUS)), |
|
|
|
.intValue(), ((Number) torrentMap.get(RPC_TOTALPEERS)).intValue(), ((Number) torrentMap.get(RPC_ETA)).intValue(), ((Number) |
|
|
|
torrentMap.get(RPC_SAVEPATH) + settings.getOS().getPathSeperator(), |
|
|
|
torrentMap.get(RPC_DOWNLOADEDEVER)).longValue(), ((Number) torrentMap.get(RPC_UPLOADEDEVER)).longValue(), ((Number) torrentMap |
|
|
|
((Number) torrentMap.get(RPC_RATEDOWNLOAD)).intValue(), |
|
|
|
.get(RPC_TOTALSIZE)).longValue(), ((Number) torrentMap.get(RPC_PARTDONE)).floatValue() / 100f, 0f, // Not available
|
|
|
|
((Number) torrentMap.get(RPC_RATEUPLOAD)).intValue(), |
|
|
|
(String) torrentMap.get(RPC_LABEL), timeAddedDate, null, // Not available
|
|
|
|
((Number) torrentMap.get(RPC_NUMSEEDS)).intValue(), |
|
|
|
error, getType())); |
|
|
|
((Number) torrentMap.get(RPC_TOTALSEEDS)).intValue(), |
|
|
|
|
|
|
|
((Number) torrentMap.get(RPC_NUMPEERS)).intValue(), |
|
|
|
|
|
|
|
((Number) torrentMap.get(RPC_TOTALPEERS)).intValue(), |
|
|
|
|
|
|
|
((Number) torrentMap.get(RPC_ETA)).intValue(), |
|
|
|
|
|
|
|
((Number) torrentMap.get(RPC_DOWNLOADEDEVER)).longValue(), |
|
|
|
|
|
|
|
((Number) torrentMap.get(RPC_UPLOADEDEVER)).longValue(), |
|
|
|
|
|
|
|
((Number) torrentMap.get(RPC_TOTALSIZE)).longValue(), |
|
|
|
|
|
|
|
((Number) torrentMap.get(RPC_PARTDONE)).floatValue() / 100f, |
|
|
|
|
|
|
|
0f, // Not available
|
|
|
|
|
|
|
|
(String) torrentMap.get(RPC_LABEL), |
|
|
|
|
|
|
|
timeAddedDate, |
|
|
|
|
|
|
|
null, // Not available
|
|
|
|
|
|
|
|
error, |
|
|
|
|
|
|
|
getType())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return torrents; |
|
|
|
return torrents; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private List<Label> getLabels(List<String> labelsResponse, List<Torrent> torrents) throws DaemonException { |
|
|
|
private List<Label> getLabels(List<String> labelsResponse, List<Torrent> torrents) { |
|
|
|
// First get all labels that torrents and count them
|
|
|
|
// First get all labels that torrents and count them
|
|
|
|
final Map<String, MutableInt> labelCounters = new HashMap<>(); |
|
|
|
final Map<String, MutableInt> labelCounters = new HashMap<>(); |
|
|
|
for (Torrent torrent : torrents) { |
|
|
|
for (Torrent torrent : torrents) { |
|
|
@ -450,14 +420,11 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
private ArrayList<TorrentFile> getTorrentFiles(DelugeRpcClient client, Torrent torrent) throws DaemonException { |
|
|
|
private ArrayList<TorrentFile> getTorrentFiles(DelugeRpcClient client, Torrent torrent) throws DaemonException { |
|
|
|
final ArrayList<TorrentFile> files = new ArrayList<>(); |
|
|
|
final ArrayList<TorrentFile> files = new ArrayList<>(); |
|
|
|
//noinspection unchecked
|
|
|
|
//noinspection unchecked
|
|
|
|
final Map<String, Object> response = (Map<String, Object>) client.sendRequest( |
|
|
|
final Map<String, Object> response = (Map<String, Object>) client.sendRequest(RPC_METHOD_STATUS, torrent.getUniqueID(), |
|
|
|
RPC_METHOD_STATUS, |
|
|
|
|
|
|
|
torrent.getUniqueID(), |
|
|
|
|
|
|
|
RPC_FILE_FIELDS_ARRAY); |
|
|
|
RPC_FILE_FIELDS_ARRAY); |
|
|
|
|
|
|
|
|
|
|
|
//noinspection unchecked
|
|
|
|
//noinspection unchecked
|
|
|
|
final List<Map<String, Object>> fileMaps = (List<Map<String, Object>>) response |
|
|
|
final List<Map<String, Object>> fileMaps = (List<Map<String, Object>>) response.get(RPC_DETAILS); |
|
|
|
.get(RPC_DETAILS); |
|
|
|
|
|
|
|
//noinspection unchecked
|
|
|
|
//noinspection unchecked
|
|
|
|
final List<Integer> priorities = (List<Integer>) response.get(RPC_FILEPRIORITIES); |
|
|
|
final List<Integer> priorities = (List<Integer>) response.get(RPC_FILEPRIORITIES); |
|
|
|
//noinspection unchecked
|
|
|
|
//noinspection unchecked
|
|
|
@ -470,14 +437,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
|
|
|
|
|
|
|
|
final String path = (String) fileMap.get(RPC_PATH); |
|
|
|
final String path = (String) fileMap.get(RPC_PATH); |
|
|
|
final long size = ((Number) fileMap.get(RPC_SIZE)).longValue(); |
|
|
|
final long size = ((Number) fileMap.get(RPC_SIZE)).longValue(); |
|
|
|
files.add(new TorrentFile( |
|
|
|
files.add(new TorrentFile(fileMap.get(RPC_INDEX).toString(), path, path, torrent.getLocationDir() + path, size, (long) (size * progress) |
|
|
|
fileMap.get(RPC_INDEX).toString(), |
|
|
|
, convertDelugePriority(client, priority))); |
|
|
|
path, |
|
|
|
|
|
|
|
path, |
|
|
|
|
|
|
|
torrent.getLocationDir() + path, |
|
|
|
|
|
|
|
size, |
|
|
|
|
|
|
|
(long) (size * progress), |
|
|
|
|
|
|
|
convertDelugePriority(client, priority))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return files; |
|
|
|
return files; |
|
|
|
} |
|
|
|
} |
|
|
@ -489,8 +450,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
try { |
|
|
|
try { |
|
|
|
in = new BufferedInputStream(new FileInputStream(file)); |
|
|
|
in = new BufferedInputStream(new FileInputStream(file)); |
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
throw new DaemonException(ExceptionType.FileAccessError, |
|
|
|
throw new DaemonException(ExceptionType.FileAccessError, "File not found: " + file.getAbsolutePath()); |
|
|
|
"File not found: " + file.getAbsolutePath()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
try { |
|
|
|
try { |
|
|
@ -504,8 +464,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
return out.toByteArray(); |
|
|
|
return out.toByteArray(); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
throw new DaemonException(ExceptionType.FileAccessError, |
|
|
|
throw new DaemonException(ExceptionType.FileAccessError, "Error reading file: " + file.getAbsolutePath()); |
|
|
|
"Error reading file: " + file.getAbsolutePath()); |
|
|
|
|
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
try { |
|
|
|
try { |
|
|
|
in.close(); |
|
|
|
in.close(); |
|
|
@ -516,8 +475,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private Priority convertDelugePriority(DelugeRpcClient client, int priority) |
|
|
|
private Priority convertDelugePriority(DelugeRpcClient client, int priority) throws DaemonException { |
|
|
|
throws DaemonException { |
|
|
|
|
|
|
|
ensureVersion(client); |
|
|
|
ensureVersion(client); |
|
|
|
return DelugeCommon.convertDelugePriority(priority, version); |
|
|
|
return DelugeCommon.convertDelugePriority(priority, version); |
|
|
|
} |
|
|
|
} |
|
|
|