Browse Source

Generalized fix #169 by applying the urldecode on magnet links for any client type. Affects #175.

pull/187/head
Eric Kok 10 years ago
parent
commit
a67741734c
  1. 12
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  2. 2
      app/src/main/java/org/transdroid/daemon/Deluge/DelugeAdapter.java

12
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -21,6 +21,8 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -945,6 +947,14 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
@Background @Background
public void addTorrentByMagnetUrl(String url, String title) { public void addTorrentByMagnetUrl(String url, String title) {
// Since v39 Chrome sends application/x-www-form-urlencoded magnet links and most torrent clients do not understand those, so decode first
try {
url = URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
// Ignore: UTF-8 is always available on Android devices
}
AddByMagnetUrlTask addByMagnetUrlTask = AddByMagnetUrlTask.create(currentConnection, url); AddByMagnetUrlTask addByMagnetUrlTask = AddByMagnetUrlTask.create(currentConnection, url);
if (!Daemon.supportsAddByMagnetUrl(currentConnection.getType())) { if (!Daemon.supportsAddByMagnetUrl(currentConnection.getType())) {
// No support for magnet links: forcefully let the task fail to report the error // No support for magnet links: forcefully let the task fail to report the error
@ -953,6 +963,7 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
currentConnection.getType().name() + " does not support magnet links")), false); currentConnection.getType().name() + " does not support magnet links")), false);
return; return;
} }
DaemonTaskResult result = addByMagnetUrlTask.execute(log); DaemonTaskResult result = addByMagnetUrlTask.execute(log);
if (result instanceof DaemonTaskSuccessResult) { if (result instanceof DaemonTaskSuccessResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title)); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title));
@ -960,6 +971,7 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@Background @Background

2
app/src/main/java/org/transdroid/daemon/Deluge/DelugeAdapter.java

@ -274,8 +274,6 @@ public class DelugeAdapter implements IDaemonAdapter {
// Request to add a magnet link by URL // Request to add a magnet link by URL
String magnet = ((AddByMagnetUrlTask) task).getUrl(); String magnet = ((AddByMagnetUrlTask) task).getUrl();
// Deluge doesn't support (fully) application/x-www-form-urlencoded magnet links
magnet = URLDecoder.decode(magnet, "UTF-8");
params.put(magnet); params.put(magnet);
params.put(new JSONArray()); params.put(new JSONArray());

Loading…
Cancel
Save