|
|
@ -89,28 +89,39 @@ public class QbittorrentAdapter implements IDaemonAdapter { |
|
|
|
// Since 4.2.0, old API is dropped. Fallback to old one if the new one failed for version <4.2.0
|
|
|
|
// Since 4.2.0, old API is dropped. Fallback to old one if the new one failed for version <4.2.0
|
|
|
|
// The API version is only supported since qBittorrent 3.2, so otherwise we assume version 1
|
|
|
|
// The API version is only supported since qBittorrent 3.2, so otherwise we assume version 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean is_v2 = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// First, try the v2 api version endpoint
|
|
|
|
try { |
|
|
|
try { |
|
|
|
String apiVerText = makeRequest(log, "/api/v2/app/webapiVersion", new BasicNameValuePair("username", settings.getUsername()), |
|
|
|
String apiVerText = makeRequest(log, "/api/v2/app/webapiVersion"); |
|
|
|
new BasicNameValuePair("password", settings.getPassword())); |
|
|
|
|
|
|
|
apiVersion = Float.parseFloat(apiVerText.trim()); |
|
|
|
apiVersion = Float.parseFloat(apiVerText.trim()); |
|
|
|
} catch (DaemonException | NumberFormatException e) { |
|
|
|
} catch (DaemonException | NumberFormatException e) { |
|
|
|
if (http_response_code == 403) { |
|
|
|
is_v2 = http_response_code == 403; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Keep trying
|
|
|
|
|
|
|
|
if (is_v2) { |
|
|
|
|
|
|
|
// Preemptive assumption, for authentication
|
|
|
|
|
|
|
|
apiVersion = (float) 2.3; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Authenticate, and try v2 again
|
|
|
|
try { |
|
|
|
try { |
|
|
|
ensureAuthenticated(log); |
|
|
|
ensureAuthenticated(log); |
|
|
|
String apiVerText = makeRequest(log, "/api/v2/app/webapiVersion"); |
|
|
|
String apiVerText = makeRequest(log, "/api/v2/app/webapiVersion"); |
|
|
|
apiVersion = Float.parseFloat(apiVerText.trim()); |
|
|
|
apiVersion = Float.parseFloat(apiVerText.trim()); |
|
|
|
} catch (DaemonException | NumberFormatException e2) { |
|
|
|
} catch (DaemonException | NumberFormatException e) { |
|
|
|
apiVersion = (float) 2.3; // assume this is new API since we are forbidden to access API
|
|
|
|
apiVersion = (float) 2.3; // assume this is new API since we are forbidden to access API
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
// Fall back to old api
|
|
|
|
try { |
|
|
|
try { |
|
|
|
String apiVerText = makeRequest(log, "/version/api"); |
|
|
|
String apiVerText = makeRequest(log, "/version/api"); |
|
|
|
apiVersion = Float.parseFloat(apiVerText.trim()); |
|
|
|
apiVersion = Float.parseFloat(apiVerText.trim()); |
|
|
|
} catch (DaemonException | NumberFormatException e3) { |
|
|
|
} catch (DaemonException | NumberFormatException e) { |
|
|
|
apiVersion = 1; |
|
|
|
apiVersion = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.d(LOG_NAME, "qBittorrent API version is " + apiVersion); |
|
|
|
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
|
|
|
|
// The qBittorent version is only supported since 3.2; for earlier versions we parse the about dialog and parse it
|
|
|
|