@ -70,7 +70,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -70,7 +70,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
privateDaemonSettingssettings;
privateDefaultHttpClienthttpclient;
privateintversion=-1;
privatefloatapiVersion=-1;// starting from 2.3 old API is dropped so we are going to use float
privateintapiVersion=-1;
publicQbittorrentAdapter(DaemonSettingssettings){
this.settings=settings;
@ -87,53 +87,53 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -87,53 +87,53 @@ public class QbittorrentAdapter implements IDaemonAdapter {
// The API version is only supported since qBittorrent 3.2, so otherwise we assume version 1
@ -149,43 +149,49 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -149,43 +149,49 @@ public class QbittorrentAdapter implements IDaemonAdapter {
}
log.d(LOG_NAME,"qBittorrent client version is "+versionText);
// String found: now parse a version like 2.9.7 as a number like 20907 (allowing 10 places for each .)
String[]parts=versionText.split("\\.");
if(parts.length>0){
version=Integer.parseInt(parts[0])*100*100;
if(parts.length>1){
version+=Float.parseFloat(parts[1])*100;
if(parts.length>2){
// For the last part only read until a non-numeric character is read
// For example version 3.0.0-alpha5 is read as version code 30000
Stringnumbers="";
for(charc:parts[2].toCharArray()){
if(Character.isDigit(c))
// Still a number; add it to the numbers string
numbers+=Character.toString(c);
else{
// No longer reading numbers; stop reading
break;
}
}
version+=Float.parseFloat(numbers);
}
}
}
version=parseVersionNumber(versionText);
}catch(Exceptione){
// Unable to establish version number; assume an old version by setting it to version 1
version=10000;
apiVersion=1;
apiVersion=10000;
}
}
privateintparseVersionNumber(StringversionText){
// String found: now parse a version like 2.9.7 as a number like 20907 (allowing 10 places for each .)
intversion=-1;
String[]parts=versionText.split("\\.");
if(parts.length>0){
version=Integer.parseInt(parts[0])*100*100;
if(parts.length>1){
version+=Float.parseFloat(parts[1])*100;
if(parts.length>2){
// For the last part only read until a non-numeric character is read
// For example version 3.0.0-alpha5 is read as version code 30000
// 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(apiVersion<(float)2){
if(apiVersion<20000){
return;
}
@ -198,7 +204,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -198,7 +204,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@ -666,7 +672,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -666,7 +672,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
Map<String,Label>labels=newHashMap<>();
for(inti=0;i<response.length();i++){
JSONObjecttor=response.getJSONObject(i);
if(apiVersion>=2){
if(apiVersion>=20000){
Stringlabel=tor.optString("category");
if(label!=null&&label.length()>0){
finalLabellabelObject=labels.get(label);
@ -698,7 +704,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -698,7 +704,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@ -890,7 +896,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -890,7 +896,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {