From e68e84960b0034e5340857954026b7173b1ef6d2 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Wed, 22 Feb 2012 00:24:44 +0100 Subject: [PATCH] Added tracker list and error messages to qBittorrent (issue 345). (ALso removed BTJunkie enum value.) --- .../transdroid/preferences/Preferences.java | 5 +-- lib/src/org/transdroid/daemon/Daemon.java | 2 +- .../Qbittorrent/QbittorrentAdapter.java | 33 ++++++++++++++++++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/android/src/org/transdroid/preferences/Preferences.java b/android/src/org/transdroid/preferences/Preferences.java index a2f94a0e..d9bf79bd 100644 --- a/android/src/org/transdroid/preferences/Preferences.java +++ b/android/src/org/transdroid/preferences/Preferences.java @@ -543,7 +543,6 @@ public class Preferences { */ public static List getSupportedSiteSettings() { List settings = new ArrayList(); - settings.add(new SiteSettings("site_btjunkie", "BTJunkie")); settings.add(new SiteSettings("site_extratorrent", "ExtraTorrent")); settings.add(new SiteSettings("site_ezrss", "EzRss")); settings.add(new SiteSettings("site_isohunt", "isoHunt")); @@ -564,9 +563,7 @@ public class Preferences { * @return The Transdroid Torrent Search site key, f.e. 'Mininova' */ public static String getCursorKeyForPreferencesKey(String preferencesKey) { - if (preferencesKey.equals("site_btjunkie")) { - return "Btjunkie"; - } else if (preferencesKey.equals("site_extratorrent")) { + if (preferencesKey.equals("site_extratorrent")) { return "ExtraTorrent"; } else if (preferencesKey.equals("site_ezrss")) { return "EzRss"; diff --git a/lib/src/org/transdroid/daemon/Daemon.java b/lib/src/org/transdroid/daemon/Daemon.java index 35db8770..5b4a87e1 100644 --- a/lib/src/org/transdroid/daemon/Daemon.java +++ b/lib/src/org/transdroid/daemon/Daemon.java @@ -192,7 +192,7 @@ public enum Daemon { } public static boolean supportsFineDetails(Daemon type) { - return type == uTorrent || type == BitTorrent || type == Daemon.Transmission || type == Deluge || type == rTorrent; + return type == uTorrent || type == BitTorrent || type == Daemon.Transmission || type == Deluge || type == rTorrent || type == qBittorrent; } public static boolean needsManualPathSpecified(Daemon type) { diff --git a/lib/src/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java b/lib/src/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java index 0d9b6703..59edced5 100644 --- a/lib/src/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java +++ b/lib/src/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java @@ -42,6 +42,7 @@ import org.transdroid.daemon.DaemonSettings; import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.Priority; import org.transdroid.daemon.Torrent; +import org.transdroid.daemon.TorrentDetails; import org.transdroid.daemon.TorrentFile; import org.transdroid.daemon.TorrentStatus; import org.transdroid.daemon.DaemonException.ExceptionType; @@ -54,6 +55,8 @@ import org.transdroid.daemon.task.DaemonTaskResult; import org.transdroid.daemon.task.DaemonTaskSuccessResult; 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; @@ -92,7 +95,14 @@ public class QbittorrentAdapter implements IDaemonAdapter { // Request all torrents from server JSONArray result = new JSONArray(makeRequest("/json/events")); return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonTorrents(result)); - + + case GetTorrentDetails: + + // Request tracker and error details for a specific teacher + String mhash = ((GetTorrentDetailsTask)task).getTargetTorrent().getUniqueID(); + JSONArray messages = new JSONArray(makeRequest("/json/propertiesTrackers/" + mhash)); + return new GetTorrentDetailsTaskSuccessResult((GetTorrentDetailsTask) task, parseJsonTorrentDetails(messages)); + case GetFileList: // Request files listing for a specific torrent @@ -296,6 +306,27 @@ public class QbittorrentAdapter implements IDaemonAdapter { private String buildWebUIUrl(String path) { return (settings.getSsl() ? "https://" : "http://") + settings.getAddress() + ":" + settings.getPort() + path; } + + private TorrentDetails parseJsonTorrentDetails(JSONArray messages) throws JSONException { + + ArrayList trackers = new ArrayList(); + ArrayList errors = new ArrayList(); + + // Parse response + if (messages.length() > 0) { + for (int i = 0; i < messages.length(); i++) { + JSONObject tor = messages.getJSONObject(i); + trackers.add(tor.getString("url")); + String msg = tor.getString("msg"); + if (msg != null && !msg.equals("")) + errors.add(msg); + } + } + + // Return the list + return new TorrentDetails(trackers, errors); + + } private ArrayList parseJsonTorrents(JSONArray response) throws JSONException {