|
|
@ -17,6 +17,59 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.transdroid.daemon.Deluge; |
|
|
|
package org.transdroid.daemon.Deluge; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_DETAILS; |
|
|
|
|
|
|
|
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_FIELDS_ARRAY; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILEPRIORITIES; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILEPROGRESS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILE_FIELDS_ARRAY; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_HASH; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_INDEX; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_LABEL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MAXDOWNLOAD; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MAXUPLOAD; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MESSAGE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD_FILE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD_MAGNET; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_FORCERECHECK; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET_LABELS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET_METHOD_LIST; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET_TORRENTS_STATUS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_INFO; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_MOVESTORAGE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_PAUSE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_PAUSE_ALL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_REMOVE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_RESUME; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_RESUME_ALL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETCONFIG; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETLABEL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETTRACKERS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SET_TORRENT_OPTIONS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_STATUS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NAME; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NUMPEERS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NUMSEEDS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_PARTDONE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_PATH; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_RATEDOWNLOAD; |
|
|
|
|
|
|
|
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_SIZE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS_FIELDS_ARRAY; |
|
|
|
|
|
|
|
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_TOTALSEEDS; |
|
|
|
|
|
|
|
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_TRACKER_STATUS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_TIER; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_URL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_UPLOADEDEVER; |
|
|
|
|
|
|
|
|
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import java.io.BufferedInputStream; |
|
|
|
import java.io.BufferedInputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
@ -68,58 +121,6 @@ import org.transdroid.daemon.task.SetLabelTask; |
|
|
|
import org.transdroid.daemon.task.SetTrackersTask; |
|
|
|
import org.transdroid.daemon.task.SetTrackersTask; |
|
|
|
import org.transdroid.daemon.task.SetTransferRatesTask; |
|
|
|
import org.transdroid.daemon.task.SetTransferRatesTask; |
|
|
|
|
|
|
|
|
|
|
|
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_DETAILS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILEPRIORITIES; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILEPROGRESS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_HASH; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_INDEX; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_LABEL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MAXDOWNLOAD; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MAXUPLOAD; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_MESSAGE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD_FILE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_ADD_MAGNET; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_FORCERECHECK; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET_LABELS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_GET_TORRENTS_STATUS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_INFO; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_MOVESTORAGE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_PAUSE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_PAUSE_ALL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_REMOVE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_RESUME; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_RESUME_ALL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETCONFIG; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETLABEL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SETTRACKERS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_SET_TORRENT_OPTIONS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_STATUS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NAME; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NUMPEERS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_NUMSEEDS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_PARTDONE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_PATH; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_RATEDOWNLOAD; |
|
|
|
|
|
|
|
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_SIZE; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS; |
|
|
|
|
|
|
|
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_TOTALSEEDS; |
|
|
|
|
|
|
|
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_TRACKER_STATUS; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_TIER; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_URL; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_UPLOADEDEVER; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FIELDS_ARRAY; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_FILE_FIELDS_ARRAY; |
|
|
|
|
|
|
|
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_STATUS_FIELDS_ARRAY; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The daemon adapter from the Deluge torrent client using deluged API directly. |
|
|
|
* The daemon adapter from the Deluge torrent client using deluged API directly. |
|
|
|
* |
|
|
|
* |
|
|
@ -130,53 +131,53 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
public static final int DEFAULT_PORT = 58846; |
|
|
|
public static final int DEFAULT_PORT = 58846; |
|
|
|
|
|
|
|
|
|
|
|
private final DaemonSettings settings; |
|
|
|
private final DaemonSettings settings; |
|
|
|
private final DelugeRpcClient client; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int version = -1; |
|
|
|
private int version = -1; |
|
|
|
|
|
|
|
|
|
|
|
public DelugeRpcAdapter(DaemonSettings settings) { |
|
|
|
public DelugeRpcAdapter(DaemonSettings settings) { |
|
|
|
this.settings = settings; |
|
|
|
this.settings = settings; |
|
|
|
client = new DelugeRpcClient(settings); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public DaemonTaskResult executeTask(Log log, DaemonTask task) { |
|
|
|
public DaemonTaskResult executeTask(Log log, DaemonTask task) { |
|
|
|
|
|
|
|
final DelugeRpcClient client = new DelugeRpcClient(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
client.connect(settings.getAddress(), settings.getPort(), settings.getUsername(), settings.getPassword()); |
|
|
|
switch (task.getMethod()) { |
|
|
|
switch (task.getMethod()) { |
|
|
|
case Retrieve: |
|
|
|
case Retrieve: |
|
|
|
return doRetrieve((RetrieveTask) task); |
|
|
|
return doRetrieve(client, (RetrieveTask) task); |
|
|
|
case AddByUrl: |
|
|
|
case AddByUrl: |
|
|
|
return doAddByUrl((AddByUrlTask) task); |
|
|
|
return doAddByUrl(client, (AddByUrlTask) task); |
|
|
|
case AddByMagnetUrl: |
|
|
|
case AddByMagnetUrl: |
|
|
|
return doAddByMagnetUrl((AddByMagnetUrlTask) task); |
|
|
|
return doAddByMagnetUrl(client, (AddByMagnetUrlTask) task); |
|
|
|
case AddByFile: |
|
|
|
case AddByFile: |
|
|
|
return doAddByFile((AddByFileTask) task); |
|
|
|
return doAddByFile(client, (AddByFileTask) task); |
|
|
|
case Remove: |
|
|
|
case Remove: |
|
|
|
return doRemove((RemoveTask) task); |
|
|
|
return doRemove(client, (RemoveTask) task); |
|
|
|
case Pause: |
|
|
|
case Pause: |
|
|
|
return doControl(task, RPC_METHOD_PAUSE); |
|
|
|
return doControl(client, task, RPC_METHOD_PAUSE); |
|
|
|
case PauseAll: |
|
|
|
case PauseAll: |
|
|
|
return doControlAll(task, RPC_METHOD_PAUSE_ALL); |
|
|
|
return doControlAll(client, task, RPC_METHOD_PAUSE_ALL); |
|
|
|
case Resume: |
|
|
|
case Resume: |
|
|
|
return doControl(task, RPC_METHOD_RESUME); |
|
|
|
return doControl(client, task, RPC_METHOD_RESUME); |
|
|
|
case ResumeAll: |
|
|
|
case ResumeAll: |
|
|
|
return doControlAll(task, RPC_METHOD_RESUME_ALL); |
|
|
|
return doControlAll(client, task, RPC_METHOD_RESUME_ALL); |
|
|
|
case GetFileList: |
|
|
|
case GetFileList: |
|
|
|
return doGetFileList((GetFileListTask) task); |
|
|
|
return doGetFileList(client, (GetFileListTask) task); |
|
|
|
case SetFilePriorities: |
|
|
|
case SetFilePriorities: |
|
|
|
return doSetFilePriorities((SetFilePriorityTask) task); |
|
|
|
return doSetFilePriorities(client, (SetFilePriorityTask) task); |
|
|
|
case SetTransferRates: |
|
|
|
case SetTransferRates: |
|
|
|
return doSetTransferRates((SetTransferRatesTask) task); |
|
|
|
return doSetTransferRates(client, (SetTransferRatesTask) task); |
|
|
|
case SetLabel: |
|
|
|
case SetLabel: |
|
|
|
return doSetLabel((SetLabelTask) task); |
|
|
|
return doSetLabel(client, (SetLabelTask) task); |
|
|
|
case SetDownloadLocation: |
|
|
|
case SetDownloadLocation: |
|
|
|
return doSetDownloadLocation((SetDownloadLocationTask) task); |
|
|
|
return doSetDownloadLocation(client, (SetDownloadLocationTask) task); |
|
|
|
case GetTorrentDetails: |
|
|
|
case GetTorrentDetails: |
|
|
|
return doGetTorrentDetails((GetTorrentDetailsTask) task); |
|
|
|
return doGetTorrentDetails(client, (GetTorrentDetailsTask) task); |
|
|
|
case SetTrackers: |
|
|
|
case SetTrackers: |
|
|
|
return doSetTrackers((SetTrackersTask) task); |
|
|
|
return doSetTrackers(client, (SetTrackersTask) task); |
|
|
|
case ForceRecheck: |
|
|
|
case ForceRecheck: |
|
|
|
return doForceRecheck((ForceRecheckTask) task); |
|
|
|
return doForceRecheck(client, (ForceRecheckTask) task); |
|
|
|
default: |
|
|
|
default: |
|
|
|
return new DaemonTaskFailureResult(task, |
|
|
|
return new DaemonTaskFailureResult(task, |
|
|
|
new DaemonException(ExceptionType.MethodUnsupported, |
|
|
|
new DaemonException(ExceptionType.MethodUnsupported, |
|
|
@ -184,6 +185,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (DaemonException e) { |
|
|
|
} catch (DaemonException e) { |
|
|
|
return new DaemonTaskFailureResult(task, e); |
|
|
|
return new DaemonTaskFailureResult(task, e); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
client.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -198,24 +201,32 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private RetrieveTaskSuccessResult doRetrieve(RetrieveTask task) throws DaemonException { |
|
|
|
private RetrieveTaskSuccessResult doRetrieve(DelugeRpcClient client, RetrieveTask task) throws DaemonException { |
|
|
|
|
|
|
|
// Get torrents
|
|
|
|
final List<Object> results = client.sendRequests( |
|
|
|
|
|
|
|
new Request(RPC_METHOD_INFO), |
|
|
|
|
|
|
|
new Request(RPC_METHOD_GET_TORRENTS_STATUS, new HashMap<>(), RPC_FIELDS_ARRAY), |
|
|
|
|
|
|
|
new Request(RPC_METHOD_GET_LABELS)); |
|
|
|
|
|
|
|
version = DelugeCommon.getVersionString((String) results.get(0)); |
|
|
|
|
|
|
|
//noinspection unchecked
|
|
|
|
//noinspection unchecked
|
|
|
|
final Map<String, Map<String, Object>> torrentsStatus = (Map<String, Map<String, Object>>) results |
|
|
|
final Map<String, Map<String, Object>> torrentsStatus = (Map<String, Map<String, Object>>) client |
|
|
|
.get(1); |
|
|
|
.sendRequest(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
|
|
|
|
|
|
|
|
//noinspection unchecked
|
|
|
|
|
|
|
|
final List<String> methods = (List<String>) client.sendRequest(RPC_METHOD_GET_METHOD_LIST); |
|
|
|
|
|
|
|
final boolean hasLabelPlugin = methods.contains(RPC_METHOD_GET_LABELS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get label list from server
|
|
|
|
//noinspection unchecked
|
|
|
|
//noinspection unchecked
|
|
|
|
final List<Label> labels = getLabels((List<String>) results.get(2), torrents); |
|
|
|
final List<String> labelNames = hasLabelPlugin |
|
|
|
|
|
|
|
? (List<String>) client.sendRequest(RPC_METHOD_GET_LABELS) |
|
|
|
|
|
|
|
: new ArrayList<String>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Extract labels & counts from torrents.
|
|
|
|
|
|
|
|
final List<Label> labels = getLabels(labelNames, torrents); |
|
|
|
|
|
|
|
|
|
|
|
return new RetrieveTaskSuccessResult(task, torrents, labels); |
|
|
|
return new RetrieveTaskSuccessResult(task, torrents, labels); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private GetTorrentDetailsTaskSuccessResult doGetTorrentDetails(GetTorrentDetailsTask task) |
|
|
|
private GetTorrentDetailsTaskSuccessResult doGetTorrentDetails(DelugeRpcClient client, |
|
|
|
|
|
|
|
GetTorrentDetailsTask task) |
|
|
|
throws DaemonException { |
|
|
|
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( |
|
|
@ -236,30 +247,33 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
Collections.singletonList((String) response.get(RPC_TRACKER_STATUS)))); |
|
|
|
Collections.singletonList((String) response.get(RPC_TRACKER_STATUS)))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private GetFileListTaskSuccessResult doGetFileList(GetFileListTask task) throws DaemonException { |
|
|
|
private GetFileListTaskSuccessResult doGetFileList(DelugeRpcClient client, |
|
|
|
final ArrayList<TorrentFile> files = getTorrentFiles(task.getTargetTorrent()); |
|
|
|
GetFileListTask task) throws DaemonException { |
|
|
|
|
|
|
|
final ArrayList<TorrentFile> files = getTorrentFiles(client, task.getTargetTorrent()); |
|
|
|
return new GetFileListTaskSuccessResult(task, files); |
|
|
|
return new GetFileListTaskSuccessResult(task, files); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private DaemonTaskResult doControl(DaemonTask task, String method) throws DaemonException { |
|
|
|
private DaemonTaskResult doControl(DelugeRpcClient client, DaemonTask task, |
|
|
|
|
|
|
|
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(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(DaemonTask task, String method) throws DaemonException { |
|
|
|
private DaemonTaskResult doControlAll(DelugeRpcClient client, DaemonTask task, |
|
|
|
|
|
|
|
String method) throws DaemonException { |
|
|
|
client.sendRequest(method); |
|
|
|
client.sendRequest(method); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doAddByFile(AddByFileTask task) throws DaemonException { |
|
|
|
private DaemonTaskResult doAddByFile(DelugeRpcClient client, AddByFileTask task) throws DaemonException { |
|
|
|
final String file = task.getFile(); |
|
|
|
final String file = task.getFile(); |
|
|
|
final String fileContent = Base64.encodeBytes(loadFile(file)); |
|
|
|
final String fileContent = Base64.encodeBytes(loadFile(file)); |
|
|
|
client.sendRequest(RPC_METHOD_ADD_FILE, file, fileContent, new HashMap<>()); |
|
|
|
client.sendRequest(RPC_METHOD_ADD_FILE, file, fileContent, new HashMap<>()); |
|
|
@ -267,19 +281,20 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doAddByUrl(AddByUrlTask task) throws DaemonException { |
|
|
|
private DaemonTaskResult doAddByUrl(DelugeRpcClient client, AddByUrlTask task) throws DaemonException { |
|
|
|
client.sendRequest(RPC_METHOD_ADD, task.getUrl(), new HashMap<>()); |
|
|
|
client.sendRequest(RPC_METHOD_ADD, task.getUrl(), new HashMap<>()); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doAddByMagnetUrl(AddByMagnetUrlTask task) throws DaemonException { |
|
|
|
private DaemonTaskResult doAddByMagnetUrl(DelugeRpcClient client, |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doSetLabel(SetLabelTask task) throws DaemonException { |
|
|
|
private DaemonTaskResult doSetLabel(DelugeRpcClient client, SetLabelTask task) throws DaemonException { |
|
|
|
final String torrentId = task.getTargetTorrent().getUniqueID(); |
|
|
|
final String torrentId = task.getTargetTorrent().getUniqueID(); |
|
|
|
final String label = task.getNewLabel() == null ? "" : task.getNewLabel(); |
|
|
|
final String label = task.getNewLabel() == null ? "" : task.getNewLabel(); |
|
|
|
client.sendRequest(RPC_METHOD_SETLABEL, torrentId, label); |
|
|
|
client.sendRequest(RPC_METHOD_SETLABEL, torrentId, label); |
|
|
@ -287,9 +302,10 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doSetFilePriorities(SetFilePriorityTask task) throws DaemonException { |
|
|
|
private DaemonTaskResult doSetFilePriorities(DelugeRpcClient client, |
|
|
|
|
|
|
|
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(task.getTargetTorrent()); |
|
|
|
final ArrayList<TorrentFile> files = getTorrentFiles(client, task.getTargetTorrent()); |
|
|
|
|
|
|
|
|
|
|
|
// prepare options arg
|
|
|
|
// prepare options arg
|
|
|
|
final Map<String, Object> optionsArgs = new HashMap<>(); |
|
|
|
final Map<String, Object> optionsArgs = new HashMap<>(); |
|
|
@ -304,8 +320,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
final ArrayList<Integer> priorities = new ArrayList<>(); |
|
|
|
final ArrayList<Integer> priorities = new ArrayList<>(); |
|
|
|
final Priority newPriority = task.getNewPriority(); |
|
|
|
final Priority newPriority = task.getNewPriority(); |
|
|
|
for (TorrentFile file : files) { |
|
|
|
for (TorrentFile file : files) { |
|
|
|
priorities.add( |
|
|
|
final Priority priority = changedFiles.contains(file.getKey()) ? newPriority : file.getPriority(); |
|
|
|
convertPriority(changedFiles.contains(file.getKey()) ? newPriority : file.getPriority())); |
|
|
|
priorities.add(convertPriority(client, priority)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
optionsArgs.put(RPC_FILEPRIORITIES, priorities); |
|
|
|
optionsArgs.put(RPC_FILEPRIORITIES, priorities); |
|
|
@ -314,7 +330,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doSetTransferRates(SetTransferRatesTask task) throws DaemonException { |
|
|
|
private DaemonTaskResult doSetTransferRates(DelugeRpcClient client, |
|
|
|
|
|
|
|
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()); |
|
|
@ -323,7 +340,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doSetTrackers(SetTrackersTask task) throws DaemonException { |
|
|
|
private DaemonTaskResult doSetTrackers(DelugeRpcClient client, SetTrackersTask task) throws DaemonException { |
|
|
|
final List<Map<String, Object>> trackers = new ArrayList<>(); |
|
|
|
final List<Map<String, Object>> trackers = new ArrayList<>(); |
|
|
|
final ArrayList<String> newTrackers = task.getNewTrackers(); |
|
|
|
final ArrayList<String> newTrackers = task.getNewTrackers(); |
|
|
|
for (int i = 0, n = newTrackers.size(); i < n; i++) { |
|
|
|
for (int i = 0, n = newTrackers.size(); i < n; i++) { |
|
|
@ -337,13 +354,14 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doForceRecheck(ForceRecheckTask task) throws DaemonException { |
|
|
|
private DaemonTaskResult doForceRecheck(DelugeRpcClient client, ForceRecheckTask task) throws DaemonException { |
|
|
|
client.sendRequest(RPC_METHOD_FORCERECHECK, getTorrentIdsArg(task)); |
|
|
|
client.sendRequest(RPC_METHOD_FORCERECHECK, getTorrentIdsArg(task)); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private DaemonTaskResult doSetDownloadLocation(SetDownloadLocationTask task) throws DaemonException { |
|
|
|
private DaemonTaskResult doSetDownloadLocation(DelugeRpcClient client, |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
@ -428,7 +446,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private ArrayList<TorrentFile> getTorrentFiles(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( |
|
|
@ -458,7 +476,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
torrent.getLocationDir() + path, |
|
|
|
torrent.getLocationDir() + path, |
|
|
|
size, |
|
|
|
size, |
|
|
|
(long) (size * progress), |
|
|
|
(long) (size * progress), |
|
|
|
convertDelugePriority(priority))); |
|
|
|
convertDelugePriority(client, priority))); |
|
|
|
} |
|
|
|
} |
|
|
|
return files; |
|
|
|
return files; |
|
|
|
} |
|
|
|
} |
|
|
@ -497,18 +515,18 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private Priority convertDelugePriority(int priority) |
|
|
|
private Priority convertDelugePriority(DelugeRpcClient client, int priority) |
|
|
|
throws DaemonException { |
|
|
|
throws DaemonException { |
|
|
|
ensureVersion(); |
|
|
|
ensureVersion(client); |
|
|
|
return DelugeCommon.convertDelugePriority(priority, version); |
|
|
|
return DelugeCommon.convertDelugePriority(priority, version); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private int convertPriority(Priority priority) throws DaemonException { |
|
|
|
private int convertPriority(DelugeRpcClient client, Priority priority) throws DaemonException { |
|
|
|
ensureVersion(); |
|
|
|
ensureVersion(client); |
|
|
|
return DelugeCommon.convertPriority(priority, version); |
|
|
|
return DelugeCommon.convertPriority(priority, version); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void ensureVersion() throws DaemonException { |
|
|
|
private void ensureVersion(DelugeRpcClient client) throws DaemonException { |
|
|
|
if (version > 0) { |
|
|
|
if (version > 0) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -520,4 +538,24 @@ public class DelugeRpcAdapter implements IDaemonAdapter { |
|
|
|
private Object getTorrentIdsArg(DaemonTask task) { |
|
|
|
private Object getTorrentIdsArg(DaemonTask task) { |
|
|
|
return new String[]{task.getTargetTorrent().getUniqueID()}; |
|
|
|
return new String[]{task.getTargetTorrent().getUniqueID()}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Used to count torrents in labels. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static class MutableInt { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int value = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MutableInt(int value) { |
|
|
|
|
|
|
|
this.value = value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void increment() { |
|
|
|
|
|
|
|
++value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int get() { |
|
|
|
|
|
|
|
return value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|