|
|
@ -45,7 +45,26 @@ import org.transdroid.daemon.Torrent; |
|
|
|
import org.transdroid.daemon.TorrentDetails; |
|
|
|
import org.transdroid.daemon.TorrentDetails; |
|
|
|
import org.transdroid.daemon.TorrentFile; |
|
|
|
import org.transdroid.daemon.TorrentFile; |
|
|
|
import org.transdroid.daemon.TorrentStatus; |
|
|
|
import org.transdroid.daemon.TorrentStatus; |
|
|
|
import org.transdroid.daemon.task.*; |
|
|
|
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.GetFileListTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetFileListTaskSuccessResult; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetStatsTask; |
|
|
|
|
|
|
|
import org.transdroid.daemon.task.GetStatsTaskSuccessResult; |
|
|
|
|
|
|
|
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.SetTransferRatesTask; |
|
|
|
import org.transdroid.daemon.util.HttpHelper; |
|
|
|
import org.transdroid.daemon.util.HttpHelper; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
@ -61,6 +80,7 @@ import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The daemon adapter for the qBittorrent torrent client. |
|
|
|
* The daemon adapter for the qBittorrent torrent client. |
|
|
|
|
|
|
|
* |
|
|
|
* @author erickok |
|
|
|
* @author erickok |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
@ -70,35 +90,28 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
private DaemonSettings settings; |
|
|
|
private DaemonSettings settings; |
|
|
|
private DefaultHttpClient httpclient; |
|
|
|
private DefaultHttpClient httpclient; |
|
|
|
private int version = -1; |
|
|
|
private int version = -1; |
|
|
|
private int apiVersion = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public QbittorrentAdapter(DaemonSettings settings) { |
|
|
|
public QbittorrentAdapter(DaemonSettings settings) { |
|
|
|
this.settings = settings; |
|
|
|
this.settings = settings; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private synchronized void ensureVersion(Log log) throws DaemonException { |
|
|
|
private synchronized void ensureVersion(Log log) { |
|
|
|
// Still need to retrieve the API and qBittorrent version numbers from the server?
|
|
|
|
// Still need to retrieve the API and qBittorrent version numbers from the server?
|
|
|
|
if (version > 0 && apiVersion > 0) |
|
|
|
if (version > 0) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Since 4.1, API v2 is used. Since qBittorrent 3.2, API v1 is used. Otherwise we use unofficial legacy json endpoints.
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
// The API version is only supported since qBittorrent 3.2, so otherwise we assume version 1
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
String apiVerText = makeRequest(log, "/version/api"); |
|
|
|
|
|
|
|
apiVersion = Integer.parseInt(apiVerText.trim()); |
|
|
|
|
|
|
|
} catch (DaemonException | NumberFormatException e) { |
|
|
|
|
|
|
|
apiVersion = 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.d(LOG_NAME, "qBittorrent API version is " + apiVersion); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The qBittorent version is only supported since 3.2; for earlier versions we parse the about dialog and parse it
|
|
|
|
|
|
|
|
String versionText = ""; |
|
|
|
String versionText = ""; |
|
|
|
if (apiVersion > 1) { |
|
|
|
try { |
|
|
|
// Format is something like 'v3.2.0'
|
|
|
|
// Try v2 API first, which returns version number in 'v4.1.9' format
|
|
|
|
|
|
|
|
versionText = makeRequest(log, "/api/v2/app/version").substring(1); |
|
|
|
|
|
|
|
} catch (Exception e1) { |
|
|
|
|
|
|
|
// Try v1 API, which returns version number in 'v3.2.0' format
|
|
|
|
|
|
|
|
try { |
|
|
|
versionText = makeRequest(log, "/version/qbittorrent").substring(1); |
|
|
|
versionText = makeRequest(log, "/version/qbittorrent").substring(1); |
|
|
|
} else { |
|
|
|
} catch (Exception e2) { |
|
|
|
// Format is something like 'qBittorrent v2.9.7 (Web UI)' or 'qBittorrent v3.0.0-alpha5 (Web UI)'
|
|
|
|
// Legacy mode; format is something like 'qBittorrent v2.9.7 (Web UI)' or 'qBittorrent v3.0.0-alpha5 (Web UI)'
|
|
|
|
String about = makeRequest(log, "/about.html"); |
|
|
|
String about = makeRequest(log, "/about.html"); |
|
|
|
String aboutStartText = "qBittorrent v"; |
|
|
|
String aboutStartText = "qBittorrent v"; |
|
|
|
String aboutEndText = " (Web UI)"; |
|
|
|
String aboutEndText = " (Web UI)"; |
|
|
@ -108,8 +121,20 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
versionText = about.substring(aboutStart + aboutStartText.length(), aboutEnd); |
|
|
|
versionText = about.substring(aboutStart + aboutStartText.length(), aboutEnd); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
version = parseVersionNumber(versionText); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
// Unable to establish version number; assume an old version by setting it to version 1
|
|
|
|
|
|
|
|
version = 10000; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int parseVersionNumber(String versionText) { |
|
|
|
// String found: now parse a version like 2.9.7 as a number like 20907 (allowing 10 places for each .)
|
|
|
|
// String found: now parse a version like 2.9.7 as a number like 20907 (allowing 10 places for each .)
|
|
|
|
|
|
|
|
int version = -1; |
|
|
|
String[] parts = versionText.split("\\."); |
|
|
|
String[] parts = versionText.split("\\."); |
|
|
|
if (parts.length > 0) { |
|
|
|
if (parts.length > 0) { |
|
|
|
version = Integer.parseInt(parts[0]) * 100 * 100; |
|
|
|
version = Integer.parseInt(parts[0]) * 100 * 100; |
|
|
@ -129,64 +154,71 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
version += Integer.parseInt(numbers); |
|
|
|
version += Integer.parseInt(numbers); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return version; |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
// Unable to establish version number; assume an old version by setting it to version 1
|
|
|
|
|
|
|
|
version = 10000; |
|
|
|
|
|
|
|
apiVersion = 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private synchronized void ensureAuthenticated(Log log) throws DaemonException { |
|
|
|
private synchronized void ensureAuthenticated(Log log) throws DaemonException { |
|
|
|
// API changed in 3.2.0, login is now handled by its own request, which provides you a cookie.
|
|
|
|
// API changed in 3.2.0, login is now handled by its own request, which provides you a cookie.
|
|
|
|
// If we don't have that cookie, let's try and get it.
|
|
|
|
// If we don't have that cookie, let's try and get it.
|
|
|
|
|
|
|
|
if (version != -1 && version < 30200) { |
|
|
|
if (apiVersion < 2) { |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Have we already authenticated? Check if we have the cookie that we need
|
|
|
|
// Have we already authenticated? Check if we have the cookie that we need
|
|
|
|
List<Cookie> cookies = httpclient.getCookieStore().getCookies(); |
|
|
|
if (isAuthenticated()) { |
|
|
|
for (Cookie c : cookies) { |
|
|
|
|
|
|
|
if (c.getName().equals("SID")) { |
|
|
|
|
|
|
|
// And here it is! Okay, no need authenticate again.
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final BasicNameValuePair usernameParam = new BasicNameValuePair("username", settings.getUsername()); |
|
|
|
|
|
|
|
final BasicNameValuePair passwordParam = new BasicNameValuePair("password", settings.getPassword()); |
|
|
|
|
|
|
|
if (version == -1 || version >= 40100) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
makeRequest(log, "/api/v2/auth/login", usernameParam, passwordParam); |
|
|
|
|
|
|
|
} catch (DaemonException ignored) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!isAuthenticated()) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
makeRequest(log, "/login", usernameParam, passwordParam); |
|
|
|
|
|
|
|
} catch (DaemonException ignored) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
makeRequest(log, "/login", new BasicNameValuePair("username", settings.getUsername()), |
|
|
|
if (!isAuthenticated()) { |
|
|
|
new BasicNameValuePair("password", settings.getPassword())); |
|
|
|
throw new DaemonException(ExceptionType.AuthenticationFailure, "Server rejected our login"); |
|
|
|
// The HttpClient will automatically remember the cookie for us, no need to parse it out.
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// However, we would like to see if authentication was successful or not...
|
|
|
|
private boolean isAuthenticated() { |
|
|
|
cookies = httpclient.getCookieStore().getCookies(); |
|
|
|
List<Cookie> cookies = httpclient.getCookieStore().getCookies(); |
|
|
|
for (Cookie c : cookies) { |
|
|
|
for (Cookie c : cookies) { |
|
|
|
if (c.getName().equals("SID")) { |
|
|
|
if (c.getName().equals("SID")) { |
|
|
|
// Good. Let's get out of here.
|
|
|
|
// And here it is! Okay, no need authenticate again.
|
|
|
|
return; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
// No cookie found, we didn't authenticate.
|
|
|
|
|
|
|
|
throw new DaemonException(ExceptionType.AuthenticationFailure, "Server rejected our login"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public DaemonTaskResult executeTask(Log log, DaemonTask task) { |
|
|
|
public DaemonTaskResult executeTask(Log log, DaemonTask task) { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
ensureVersion(log); |
|
|
|
initialise(); |
|
|
|
ensureAuthenticated(log); |
|
|
|
ensureAuthenticated(log); |
|
|
|
|
|
|
|
ensureVersion(log); |
|
|
|
|
|
|
|
|
|
|
|
switch (task.getMethod()) { |
|
|
|
switch (task.getMethod()) { |
|
|
|
case Retrieve: |
|
|
|
case Retrieve: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Request all torrents from server
|
|
|
|
String path; |
|
|
|
String path; |
|
|
|
if (version >= 30200) { |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/info"; |
|
|
|
|
|
|
|
} else if (version >= 30200) { |
|
|
|
path = "/query/torrents"; |
|
|
|
path = "/query/torrents"; |
|
|
|
} else if (version >= 30000) { |
|
|
|
} else if (version >= 30000) { |
|
|
|
path = "/json/torrents"; |
|
|
|
path = "/json/torrents"; |
|
|
@ -194,77 +226,145 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
path = "/json/events"; |
|
|
|
path = "/json/events"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Request all torrents from server
|
|
|
|
|
|
|
|
JSONArray result = new JSONArray(makeRequest(log, path)); |
|
|
|
JSONArray result = new JSONArray(makeRequest(log, path)); |
|
|
|
|
|
|
|
|
|
|
|
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonTorrents(result), parseJsonLabels(result)); |
|
|
|
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonTorrents(result), parseJsonLabels(result)); |
|
|
|
|
|
|
|
|
|
|
|
case GetTorrentDetails: |
|
|
|
case GetTorrentDetails: |
|
|
|
|
|
|
|
|
|
|
|
// Request tracker and error details for a specific teacher
|
|
|
|
// Request tracker and error details for a specific teacher
|
|
|
|
String mhash = task.getTargetTorrent().getUniqueID(); |
|
|
|
String mhash = task.getTargetTorrent().getUniqueID(); |
|
|
|
JSONArray messages = |
|
|
|
JSONArray messages; |
|
|
|
new JSONArray(makeRequest(log, (version >= 30200 ? "/query/propertiesTrackers/" : "/json/propertiesTrackers/") + mhash)); |
|
|
|
JSONArray pieces; |
|
|
|
return new GetTorrentDetailsTaskSuccessResult((GetTorrentDetailsTask) task, parseJsonTorrentDetails(messages)); |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
messages = new JSONArray(makeRequest(log, "/api/v2/torrents/trackers", new BasicNameValuePair("hash", mhash))); |
|
|
|
|
|
|
|
pieces = new JSONArray(makeRequest(log, "/api/v2/torrents/pieceStates", new BasicNameValuePair("hash", mhash))); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
messages = new JSONArray(makeRequest(log, "/query/propertiesTrackers/" + mhash)); |
|
|
|
|
|
|
|
pieces = new JSONArray(makeRequest(log, "/query/getPieceStates/" + mhash)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new GetTorrentDetailsTaskSuccessResult((GetTorrentDetailsTask) task, parseJsonTorrentDetails(messages, pieces)); |
|
|
|
|
|
|
|
|
|
|
|
case GetFileList: |
|
|
|
case GetFileList: |
|
|
|
|
|
|
|
|
|
|
|
// Request files listing for a specific torrent
|
|
|
|
// Request files listing for a specific torrent
|
|
|
|
String fhash = task.getTargetTorrent().getUniqueID(); |
|
|
|
String fhash = task.getTargetTorrent().getUniqueID(); |
|
|
|
JSONArray files = |
|
|
|
JSONArray files; |
|
|
|
new JSONArray(makeRequest(log, (version >= 30200 ? "/query/propertiesFiles/" : "/json/propertiesFiles/") + fhash)); |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
files = new JSONArray(makeRequest(log, "/api/v2/torrents/files", new BasicNameValuePair("hash", fhash))); |
|
|
|
|
|
|
|
} else if (version >= 30200) { |
|
|
|
|
|
|
|
files = new JSONArray(makeRequest(log, "/query/propertiesFiles/" + fhash)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
files = new JSONArray(makeRequest(log, "/json/propertiesFiles/" + fhash)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new GetFileListTaskSuccessResult((GetFileListTask) task, parseJsonFiles(files)); |
|
|
|
return new GetFileListTaskSuccessResult((GetFileListTask) task, parseJsonFiles(files)); |
|
|
|
|
|
|
|
|
|
|
|
case AddByFile: |
|
|
|
case AddByFile: |
|
|
|
|
|
|
|
|
|
|
|
// Upload a local .torrent file
|
|
|
|
// Upload a local .torrent file
|
|
|
|
|
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/add"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/command/upload"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String ufile = ((AddByFileTask) task).getFile(); |
|
|
|
String ufile = ((AddByFileTask) task).getFile(); |
|
|
|
makeUploadRequest("/command/upload", ufile, log); |
|
|
|
makeUploadRequest(path, ufile, log); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case AddByUrl: |
|
|
|
case AddByUrl: |
|
|
|
|
|
|
|
|
|
|
|
// Request to add a torrent by URL
|
|
|
|
// Request to add a torrent by URL
|
|
|
|
String url = ((AddByUrlTask) task).getUrl(); |
|
|
|
String url = ((AddByUrlTask) task).getUrl(); |
|
|
|
makeRequest(log, "/command/download", new BasicNameValuePair("urls", url)); |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/add"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/command/upload"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
makeRequest(log, path, new BasicNameValuePair("urls", url)); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case AddByMagnetUrl: |
|
|
|
case AddByMagnetUrl: |
|
|
|
|
|
|
|
|
|
|
|
// 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(); |
|
|
|
makeRequest(log, "/command/download", new BasicNameValuePair("urls", magnet)); |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/add"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/command/download"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
makeRequest(log, path, new BasicNameValuePair("urls", magnet)); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case Remove: |
|
|
|
case Remove: |
|
|
|
|
|
|
|
|
|
|
|
// Remove a torrent
|
|
|
|
// Remove a torrent
|
|
|
|
RemoveTask removeTask = (RemoveTask) task; |
|
|
|
RemoveTask removeTask = (RemoveTask) task; |
|
|
|
makeRequest(log, (removeTask.includingData() ? "/command/deletePerm" : "/command/delete"), |
|
|
|
if (version >= 40100) { |
|
|
|
new BasicNameValuePair("hashes", removeTask.getTargetTorrent().getUniqueID())); |
|
|
|
if (removeTask.includingData()) { |
|
|
|
|
|
|
|
makeRequest(log, "/api/v2/torrents/delete", |
|
|
|
|
|
|
|
new BasicNameValuePair("hashes", removeTask.getTargetTorrent().getUniqueID()), |
|
|
|
|
|
|
|
new BasicNameValuePair("deleteFiles", "true")); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
makeRequest(log, "/api/v2/torrents/delete", |
|
|
|
|
|
|
|
new BasicNameValuePair("hashes", removeTask.getTargetTorrent().getUniqueID()), |
|
|
|
|
|
|
|
new BasicNameValuePair("deleteFiles", "false")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = (removeTask.includingData() ? "/command/deletePerm" : "/command/delete"); |
|
|
|
|
|
|
|
makeRequest(log, path, new BasicNameValuePair("hashes", removeTask.getTargetTorrent().getUniqueID())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case Pause: |
|
|
|
case Pause: |
|
|
|
|
|
|
|
|
|
|
|
// Pause a torrent
|
|
|
|
// Pause a torrent
|
|
|
|
|
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
makeRequest(log, "/api/v2/torrents/pause", new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID())); |
|
|
|
|
|
|
|
} else { |
|
|
|
makeRequest(log, "/command/pause", new BasicNameValuePair("hash", task.getTargetTorrent().getUniqueID())); |
|
|
|
makeRequest(log, "/command/pause", new BasicNameValuePair("hash", task.getTargetTorrent().getUniqueID())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case PauseAll: |
|
|
|
case PauseAll: |
|
|
|
|
|
|
|
|
|
|
|
// Resume all torrents
|
|
|
|
// Resume all torrents
|
|
|
|
|
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
makeRequest(log, "/api/v2/torrents/pause", new BasicNameValuePair("hashes", "all")); |
|
|
|
|
|
|
|
} else { |
|
|
|
makeRequest(log, "/command/pauseall"); |
|
|
|
makeRequest(log, "/command/pauseall"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case Resume: |
|
|
|
case Resume: |
|
|
|
|
|
|
|
|
|
|
|
// Resume a torrent
|
|
|
|
// Resume a torrent
|
|
|
|
|
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
makeRequest(log, "/api/v2/torrents/resume", new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID())); |
|
|
|
|
|
|
|
} else { |
|
|
|
makeRequest(log, "/command/resume", new BasicNameValuePair("hash", task.getTargetTorrent().getUniqueID())); |
|
|
|
makeRequest(log, "/command/resume", new BasicNameValuePair("hash", task.getTargetTorrent().getUniqueID())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case ResumeAll: |
|
|
|
case ResumeAll: |
|
|
|
|
|
|
|
|
|
|
|
// Resume all torrents
|
|
|
|
// Resume all torrents
|
|
|
|
|
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/resume"; |
|
|
|
|
|
|
|
makeRequest(log, path, new BasicNameValuePair("hashes", "all")); |
|
|
|
|
|
|
|
} else { |
|
|
|
makeRequest(log, "/command/resumeall"); |
|
|
|
makeRequest(log, "/command/resumeall"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case SetFilePriorities: |
|
|
|
case SetFilePriorities: |
|
|
@ -281,21 +381,59 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
// We have to make a separate request per file, it seems
|
|
|
|
// We have to make a separate request per file, it seems
|
|
|
|
for (TorrentFile file : setPrio.getForFiles()) { |
|
|
|
for (TorrentFile file : setPrio.getForFiles()) { |
|
|
|
makeRequest(log, "/command/setFilePrio", new BasicNameValuePair("hash", task.getTargetTorrent().getUniqueID()), |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/filePrio"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/command/setFilePrio"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
makeRequest(log, path, new BasicNameValuePair("hash", task.getTargetTorrent().getUniqueID()), |
|
|
|
new BasicNameValuePair("id", file.getKey()), new BasicNameValuePair("priority", newPrio)); |
|
|
|
new BasicNameValuePair("id", file.getKey()), new BasicNameValuePair("priority", newPrio)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case ForceRecheck: |
|
|
|
case ForceRecheck: |
|
|
|
|
|
|
|
|
|
|
|
// Force recheck a torrent
|
|
|
|
// Force recheck a torrent
|
|
|
|
makeRequest(log, "/command/recheck", new BasicNameValuePair("hash", task.getTargetTorrent().getUniqueID())); |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/recheck"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/command/recheck"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
makeRequest(log, path, new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID())); |
|
|
|
|
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case ToggleSequentialDownload: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Toggle sequential download mode on a torrent
|
|
|
|
|
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/toggleSequentialDownload"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/command/toggleSequentialDownload"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
makeRequest(log, path, new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID())); |
|
|
|
|
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case ToggleFirstLastPieceDownload: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set policy for downloading first and last piece first on a torrent
|
|
|
|
|
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/toggleFirstLastPiecePrio"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/command/toggleFirstLastPiecePrio"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
makeRequest(log, path, new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID())); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case SetLabel: |
|
|
|
case SetLabel: |
|
|
|
|
|
|
|
|
|
|
|
SetLabelTask labelTask = (SetLabelTask) task; |
|
|
|
SetLabelTask labelTask = (SetLabelTask) task; |
|
|
|
makeRequest(log, "/command/setCategory", |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/setCategory"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/command/setCategory"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
makeRequest(log, path, |
|
|
|
new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID()), |
|
|
|
new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID()), |
|
|
|
new BasicNameValuePair("category", labelTask.getNewLabel())); |
|
|
|
new BasicNameValuePair("category", labelTask.getNewLabel())); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
@ -303,7 +441,12 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
case SetDownloadLocation: |
|
|
|
case SetDownloadLocation: |
|
|
|
|
|
|
|
|
|
|
|
SetDownloadLocationTask setLocationTask = (SetDownloadLocationTask) task; |
|
|
|
SetDownloadLocationTask setLocationTask = (SetDownloadLocationTask) task; |
|
|
|
makeRequest(log, "/command/setLocation", |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/torrents/setLocation"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/command/setLocation"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
makeRequest(log, path, |
|
|
|
new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID()), |
|
|
|
new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID()), |
|
|
|
new BasicNameValuePair("location", setLocationTask.getNewLocation())); |
|
|
|
new BasicNameValuePair("location", setLocationTask.getNewLocation())); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
@ -311,18 +454,33 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
case SetTransferRates: |
|
|
|
case SetTransferRates: |
|
|
|
|
|
|
|
|
|
|
|
// Request to set the maximum transfer rates
|
|
|
|
// Request to set the maximum transfer rates
|
|
|
|
|
|
|
|
String pathDL; |
|
|
|
|
|
|
|
String pathUL; |
|
|
|
SetTransferRatesTask ratesTask = (SetTransferRatesTask) task; |
|
|
|
SetTransferRatesTask ratesTask = (SetTransferRatesTask) task; |
|
|
|
String dl = (ratesTask.getDownloadRate() == null ? "NaN" : Long.toString(ratesTask.getDownloadRate() * 1024)); |
|
|
|
String dl = (ratesTask.getDownloadRate() == null ? "NaN" : Long.toString(ratesTask.getDownloadRate() * 1024)); |
|
|
|
String ul = (ratesTask.getUploadRate() == null ? "NaN" : Long.toString(ratesTask.getUploadRate() * 1024)); |
|
|
|
String ul = (ratesTask.getUploadRate() == null ? "NaN" : Long.toString(ratesTask.getUploadRate() * 1024)); |
|
|
|
|
|
|
|
|
|
|
|
makeRequest(log, "/command/setGlobalDlLimit", new BasicNameValuePair("limit", dl)); |
|
|
|
if (version >= 40100) { |
|
|
|
makeRequest(log, "/command/setGlobalUpLimit", new BasicNameValuePair("limit", ul)); |
|
|
|
pathDL = "/api/v2/torrents/setDownloadLimit"; |
|
|
|
|
|
|
|
pathUL = "/api/v2/torrents/setUploadLimit"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pathDL = "/command/setGlobalDlLimit"; |
|
|
|
|
|
|
|
pathUL = "/command/setGlobalUpLimit"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
makeRequest(log, pathDL, new BasicNameValuePair("limit", dl)); |
|
|
|
|
|
|
|
makeRequest(log, pathUL, new BasicNameValuePair("limit", ul)); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case GetStats: |
|
|
|
case GetStats: |
|
|
|
|
|
|
|
|
|
|
|
// Refresh alternative download speeds setting
|
|
|
|
// Refresh alternative download speeds setting
|
|
|
|
JSONObject stats = new JSONObject(makeRequest(log, "/sync/maindata?rid=0")); |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/sync/maindata?rid=0"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/sync/maindata?rid=0"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
JSONObject stats = new JSONObject(makeRequest(log, path)); |
|
|
|
JSONObject serverStats = stats.optJSONObject("server_state"); |
|
|
|
JSONObject serverStats = stats.optJSONObject("server_state"); |
|
|
|
boolean alternativeSpeeds = false; |
|
|
|
boolean alternativeSpeeds = false; |
|
|
|
if (serverStats != null) { |
|
|
|
if (serverStats != null) { |
|
|
@ -333,7 +491,12 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
case SetAlternativeMode: |
|
|
|
case SetAlternativeMode: |
|
|
|
|
|
|
|
|
|
|
|
// Flip alternative speed mode
|
|
|
|
// Flip alternative speed mode
|
|
|
|
makeRequest(log, "/command/toggleAlternativeSpeedLimits"); |
|
|
|
if (version >= 40100) { |
|
|
|
|
|
|
|
path = "/api/v2/transfer/toggleSpeedLimitsMode"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
path = "/command/toggleAlternativeSpeedLimits"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
makeRequest(log, path); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
@ -352,7 +515,9 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
// Setup request using POST
|
|
|
|
// Setup request using POST
|
|
|
|
HttpPost httppost = new HttpPost(buildWebUIUrl(path)); |
|
|
|
String url_to_request = buildWebUIUrl(path); |
|
|
|
|
|
|
|
HttpPost httppost = new HttpPost(url_to_request); |
|
|
|
|
|
|
|
|
|
|
|
List<NameValuePair> nvps = new ArrayList<>(); |
|
|
|
List<NameValuePair> nvps = new ArrayList<>(); |
|
|
|
Collections.addAll(nvps, params); |
|
|
|
Collections.addAll(nvps, params); |
|
|
|
httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); |
|
|
|
httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); |
|
|
@ -384,15 +549,14 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
private String makeWebRequest(HttpPost httppost, Log log) throws DaemonException { |
|
|
|
private String makeWebRequest(HttpPost httppost, Log log) throws DaemonException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
// Initialise the HTTP client
|
|
|
|
|
|
|
|
if (httpclient == null) { |
|
|
|
|
|
|
|
initialise(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Execute
|
|
|
|
// Execute
|
|
|
|
HttpResponse response = httpclient.execute(httppost); |
|
|
|
HttpResponse response = httpclient.execute(httppost); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Throw exception on 403
|
|
|
|
|
|
|
|
if (response.getStatusLine().getStatusCode() == 403) { |
|
|
|
|
|
|
|
throw new DaemonException(ExceptionType.AuthenticationFailure, "Response code 403"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
if (entity != null) { |
|
|
|
if (entity != null) { |
|
|
|
|
|
|
|
|
|
|
@ -413,21 +577,30 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
log.d(LOG_NAME, "Error: " + e.toString()); |
|
|
|
log.d(LOG_NAME, "Error: " + e.toString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (e instanceof DaemonException) { |
|
|
|
|
|
|
|
throw (DaemonException) e; |
|
|
|
|
|
|
|
} else { |
|
|
|
throw new DaemonException(ExceptionType.ConnectionError, e.toString()); |
|
|
|
throw new DaemonException(ExceptionType.ConnectionError, e.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Instantiates an HTTP client with proper credentials that can be used for all qBittorrent requests. |
|
|
|
* Instantiates an HTTP client with proper credentials that can be used for all qBittorrent requests. |
|
|
|
|
|
|
|
* |
|
|
|
* @throws DaemonException On conflicting or missing settings |
|
|
|
* @throws DaemonException On conflicting or missing settings |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void initialise() throws DaemonException { |
|
|
|
private void initialise() throws DaemonException { |
|
|
|
|
|
|
|
if (httpclient == null) { |
|
|
|
httpclient = HttpHelper.createStandardHttpClient(settings, true); |
|
|
|
httpclient = HttpHelper.createStandardHttpClient(settings, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Build the URL of the web UI request from the user settings |
|
|
|
* Build the URL of the web UI request from the user settings |
|
|
|
|
|
|
|
* |
|
|
|
* @return The URL to request |
|
|
|
* @return The URL to request |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String buildWebUIUrl(String path) { |
|
|
|
private String buildWebUIUrl(String path) { |
|
|
@ -439,7 +612,7 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
return (settings.getSsl() ? "https://" : "http://") + settings.getAddress() + ":" + settings.getPort() + proxyFolder + path; |
|
|
|
return (settings.getSsl() ? "https://" : "http://") + settings.getAddress() + ":" + settings.getPort() + proxyFolder + path; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private TorrentDetails parseJsonTorrentDetails(JSONArray messages) throws JSONException { |
|
|
|
private TorrentDetails parseJsonTorrentDetails(JSONArray messages, JSONArray pieceStates) throws JSONException { |
|
|
|
|
|
|
|
|
|
|
|
ArrayList<String> trackers = new ArrayList<>(); |
|
|
|
ArrayList<String> trackers = new ArrayList<>(); |
|
|
|
ArrayList<String> errors = new ArrayList<>(); |
|
|
|
ArrayList<String> errors = new ArrayList<>(); |
|
|
@ -455,8 +628,15 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<Integer> pieces = new ArrayList<>(); |
|
|
|
|
|
|
|
if (pieceStates.length() > 0) { |
|
|
|
|
|
|
|
for (int i = 0; i < pieceStates.length(); i++) { |
|
|
|
|
|
|
|
pieces.add(pieceStates.getInt(i)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Return the list
|
|
|
|
// Return the list
|
|
|
|
return new TorrentDetails(trackers, errors); |
|
|
|
return new TorrentDetails(trackers, errors, pieces); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -466,7 +646,7 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
Map<String, Label> labels = new HashMap<>(); |
|
|
|
Map<String, Label> labels = new HashMap<>(); |
|
|
|
for (int i = 0; i < response.length(); i++) { |
|
|
|
for (int i = 0; i < response.length(); i++) { |
|
|
|
JSONObject tor = response.getJSONObject(i); |
|
|
|
JSONObject tor = response.getJSONObject(i); |
|
|
|
if (apiVersion >= 2) { |
|
|
|
if (version >= 40100) { |
|
|
|
String label = tor.optString("category"); |
|
|
|
String label = tor.optString("category"); |
|
|
|
if (label != null && label.length() > 0) { |
|
|
|
if (label != null && label.length() > 0) { |
|
|
|
final Label labelObject = labels.get(label); |
|
|
|
final Label labelObject = labels.get(label); |
|
|
@ -492,11 +672,13 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
long uploaded; |
|
|
|
long uploaded; |
|
|
|
int dlspeed; |
|
|
|
int dlspeed; |
|
|
|
int upspeed; |
|
|
|
int upspeed; |
|
|
|
|
|
|
|
boolean dlseq = false; |
|
|
|
|
|
|
|
boolean dlflp = false; |
|
|
|
Date addedOn = null; |
|
|
|
Date addedOn = null; |
|
|
|
Date completionOn = null; |
|
|
|
Date completionOn = null; |
|
|
|
String label = null; |
|
|
|
String label = null; |
|
|
|
|
|
|
|
|
|
|
|
if (apiVersion >= 2) { |
|
|
|
if (version >= 30200) { |
|
|
|
leechers = new int[2]; |
|
|
|
leechers = new int[2]; |
|
|
|
leechers[0] = tor.getInt("num_leechs"); |
|
|
|
leechers[0] = tor.getInt("num_leechs"); |
|
|
|
leechers[1] = tor.getInt("num_complete") + tor.getInt("num_incomplete"); |
|
|
|
leechers[1] = tor.getInt("num_complete") + tor.getInt("num_incomplete"); |
|
|
@ -507,6 +689,12 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
ratio = tor.getDouble("ratio"); |
|
|
|
ratio = tor.getDouble("ratio"); |
|
|
|
dlspeed = tor.getInt("dlspeed"); |
|
|
|
dlspeed = tor.getInt("dlspeed"); |
|
|
|
upspeed = tor.getInt("upspeed"); |
|
|
|
upspeed = tor.getInt("upspeed"); |
|
|
|
|
|
|
|
if (tor.has("seq_dl")) { |
|
|
|
|
|
|
|
dlseq = tor.getBoolean("seq_dl"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (tor.has("f_l_piece_prio")) { |
|
|
|
|
|
|
|
dlflp = tor.getBoolean("f_l_piece_prio"); |
|
|
|
|
|
|
|
} |
|
|
|
if (tor.has("uploaded")) { |
|
|
|
if (tor.has("uploaded")) { |
|
|
|
uploaded = tor.getLong("uploaded"); |
|
|
|
uploaded = tor.getLong("uploaded"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -535,7 +723,7 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
eta = (long) (size - (size * progress)) / dlspeed; |
|
|
|
eta = (long) (size - (size * progress)) / dlspeed; |
|
|
|
// Add the parsed torrent to the list
|
|
|
|
// Add the parsed torrent to the list
|
|
|
|
// @formatter:off
|
|
|
|
// @formatter:off
|
|
|
|
torrents.add(new Torrent( |
|
|
|
Torrent torrent = new Torrent( |
|
|
|
(long) i, |
|
|
|
(long) i, |
|
|
|
tor.getString("hash"), |
|
|
|
tor.getString("hash"), |
|
|
|
tor.getString("name"), |
|
|
|
tor.getString("name"), |
|
|
@ -557,7 +745,10 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
addedOn, |
|
|
|
addedOn, |
|
|
|
completionOn, |
|
|
|
completionOn, |
|
|
|
null, |
|
|
|
null, |
|
|
|
settings.getType())); |
|
|
|
settings.getType()); |
|
|
|
|
|
|
|
torrent.mimicSequentialDownload(dlseq); |
|
|
|
|
|
|
|
torrent.mimicFirstLastPieceDownload(dlflp); |
|
|
|
|
|
|
|
torrents.add(torrent); |
|
|
|
// @formatter:on
|
|
|
|
// @formatter:on
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -679,7 +870,7 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
JSONObject file = response.getJSONObject(i); |
|
|
|
JSONObject file = response.getJSONObject(i); |
|
|
|
|
|
|
|
|
|
|
|
long size; |
|
|
|
long size; |
|
|
|
if (apiVersion >= 2) { |
|
|
|
if (version >= 30200) { |
|
|
|
size = file.getLong("size"); |
|
|
|
size = file.getLong("size"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
size = parseSize(file.getString("size")); |
|
|
|
size = parseSize(file.getString("size")); |
|
|
|