@ -83,18 +83,54 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -83,18 +83,54 @@ public class QbittorrentAdapter implements IDaemonAdapter {
try{
// 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
@ -109,12 +145,24 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -109,12 +145,24 @@ public class QbittorrentAdapter implements IDaemonAdapter {
}
}
version=parseVersionNumber(versionText);
}catch(Exceptione){
// Unable to establish version number; assume an old version by setting it to version 1
version=10000;
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+=Integer.parseInt(parts[1])*100;
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
@ -128,25 +176,18 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -128,25 +176,18 @@ public class QbittorrentAdapter implements IDaemonAdapter {
break;
}
}
version+=Integer.parseInt(numbers);
return;
version+=Float.parseFloat(numbers);
}
}
}
}catch(Exceptione){
// Unable to establish version number; assume an old version by setting it to version 1
// 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<2){
if(apiVersion<20000){
return;
}
@ -159,8 +200,13 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -159,8 +200,13 @@ public class QbittorrentAdapter implements IDaemonAdapter {
// 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...
@ -185,8 +231,12 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -185,8 +231,12 @@ public class QbittorrentAdapter implements IDaemonAdapter {
switch(task.getMethod()){
caseRetrieve:
// Request all torrents from server
Stringpath;
if(version>=30200){
if(version>=40200){
path="/api/v2/torrents/info";
}elseif(version>=30200){
path="/query/torrents";
}elseif(version>=30000){
path="/json/torrents";
@ -194,78 +244,145 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -194,78 +244,145 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@ -282,33 +399,59 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -282,33 +399,59 @@ public class QbittorrentAdapter implements IDaemonAdapter {
}
// We have to make a separate request per file, it seems
@ -316,7 +459,12 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -316,7 +459,12 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@ -324,18 +472,33 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -324,18 +472,33 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@ -346,7 +509,12 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -346,7 +509,12 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@ -365,7 +533,9 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -365,7 +533,9 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@ -406,6 +576,11 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -406,6 +576,11 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@ -426,8 +601,14 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -426,8 +601,14 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@ -486,7 +667,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -486,7 +667,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);
@ -518,7 +699,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -518,7 +699,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@ -710,7 +891,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
@@ -710,7 +891,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {