|
|
@ -27,13 +27,17 @@ import java.net.URI; |
|
|
|
import java.net.URLDecoder; |
|
|
|
import java.net.URLDecoder; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Map.Entry; |
|
|
|
|
|
|
|
|
|
|
|
import org.base64.android.Base64; |
|
|
|
import org.base64.android.Base64; |
|
|
|
import org.transdroid.daemon.Daemon; |
|
|
|
import org.transdroid.daemon.Daemon; |
|
|
|
import org.transdroid.daemon.DaemonException; |
|
|
|
import org.transdroid.daemon.DaemonException; |
|
|
|
import org.transdroid.daemon.DaemonSettings; |
|
|
|
import org.transdroid.daemon.DaemonSettings; |
|
|
|
import org.transdroid.daemon.IDaemonAdapter; |
|
|
|
import org.transdroid.daemon.IDaemonAdapter; |
|
|
|
|
|
|
|
import org.transdroid.daemon.Label; |
|
|
|
import org.transdroid.daemon.Priority; |
|
|
|
import org.transdroid.daemon.Priority; |
|
|
|
import org.transdroid.daemon.Torrent; |
|
|
|
import org.transdroid.daemon.Torrent; |
|
|
|
import org.transdroid.daemon.TorrentDetails; |
|
|
|
import org.transdroid.daemon.TorrentDetails; |
|
|
@ -77,6 +81,7 @@ public class RtorrentAdapter implements IDaemonAdapter { |
|
|
|
|
|
|
|
|
|
|
|
private DaemonSettings settings; |
|
|
|
private DaemonSettings settings; |
|
|
|
private XMLRPCClient rpcclient; |
|
|
|
private XMLRPCClient rpcclient; |
|
|
|
|
|
|
|
private List<Label> lastKnownLabels = null; |
|
|
|
|
|
|
|
|
|
|
|
public RtorrentAdapter(DaemonSettings settings) { |
|
|
|
public RtorrentAdapter(DaemonSettings settings) { |
|
|
|
this.settings = settings; |
|
|
|
this.settings = settings; |
|
|
@ -90,7 +95,7 @@ public class RtorrentAdapter implements IDaemonAdapter { |
|
|
|
case Retrieve: |
|
|
|
case Retrieve: |
|
|
|
|
|
|
|
|
|
|
|
Object result = makeRtorrentCall("d.multicall", new String[] { "main", "d.get_hash=", "d.get_name=", "d.get_state=", "d.get_down_rate=", "d.get_up_rate=", "d.get_peers_connected=", "d.get_peers_not_connected=", "d.get_peers_accounted=", "d.get_bytes_done=", "d.get_up_total=", "d.get_size_bytes=", "d.get_creation_date=", "d.get_left_bytes=", "d.get_complete=", "d.is_active=", "d.is_hash_checking=", "d.get_base_path=", "d.get_base_filename=", "d.get_message=", "d.get_custom=addtime", "d.get_custom=seedingtime", "d.get_custom1=" }); |
|
|
|
Object result = makeRtorrentCall("d.multicall", new String[] { "main", "d.get_hash=", "d.get_name=", "d.get_state=", "d.get_down_rate=", "d.get_up_rate=", "d.get_peers_connected=", "d.get_peers_not_connected=", "d.get_peers_accounted=", "d.get_bytes_done=", "d.get_up_total=", "d.get_size_bytes=", "d.get_creation_date=", "d.get_left_bytes=", "d.get_complete=", "d.is_active=", "d.is_hash_checking=", "d.get_base_path=", "d.get_base_filename=", "d.get_message=", "d.get_custom=addtime", "d.get_custom=seedingtime", "d.get_custom1=" }); |
|
|
|
return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result),null); |
|
|
|
return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result), lastKnownLabels); |
|
|
|
|
|
|
|
|
|
|
|
case GetTorrentDetails: |
|
|
|
case GetTorrentDetails: |
|
|
|
|
|
|
|
|
|
|
@ -277,10 +282,8 @@ public class RtorrentAdapter implements IDaemonAdapter { |
|
|
|
|
|
|
|
|
|
|
|
// Parse torrent list from response
|
|
|
|
// Parse torrent list from response
|
|
|
|
// Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download
|
|
|
|
// Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download
|
|
|
|
// 'Labels' are supported in rTorrent as 'groups' that can become the 'active view';
|
|
|
|
|
|
|
|
// support for this is not trivial since it requires multiple calls to get all the info at best
|
|
|
|
|
|
|
|
// (if it is even feasible with the current approach)
|
|
|
|
|
|
|
|
List<Torrent> torrents = new ArrayList<Torrent>(); |
|
|
|
List<Torrent> torrents = new ArrayList<Torrent>(); |
|
|
|
|
|
|
|
Map<String, Integer> labels = new HashMap<String, Integer>(); |
|
|
|
Object[] responseList = (Object[]) response; |
|
|
|
Object[] responseList = (Object[]) response; |
|
|
|
for (int i = 0; i < responseList.length; i++) { |
|
|
|
for (int i = 0; i < responseList.length; i++) { |
|
|
|
|
|
|
|
|
|
|
@ -323,7 +326,13 @@ public class RtorrentAdapter implements IDaemonAdapter { |
|
|
|
String label = null; |
|
|
|
String label = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
label = URLDecoder.decode((String)info[21], "UTF-8"); |
|
|
|
label = URLDecoder.decode((String)info[21], "UTF-8"); |
|
|
|
|
|
|
|
if (labels.containsKey(label)) { |
|
|
|
|
|
|
|
labels.put(label, labels.get(label) + 1); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
labels.put(label, 0); |
|
|
|
|
|
|
|
} |
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
|
|
|
// Can't decode label name; ignore it
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (info[3] instanceof Long) { |
|
|
|
if (info[3] instanceof Long) { |
|
|
@ -388,6 +397,11 @@ public class RtorrentAdapter implements IDaemonAdapter { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
lastKnownLabels = new ArrayList<Label>(); |
|
|
|
|
|
|
|
for (Entry<String, Integer> pair : labels.entrySet()) { |
|
|
|
|
|
|
|
if (pair.getKey() != null) |
|
|
|
|
|
|
|
lastKnownLabels.add(new Label(pair.getKey(), pair.getValue())); |
|
|
|
|
|
|
|
} |
|
|
|
return torrents; |
|
|
|
return torrents; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|