Browse Source

qBittorrent Workaround for v2 API (#1287)

CauseFX 6 years ago
parent
commit
a3db9a3bb0

+ 1 - 0
api/config/default.php

@@ -86,6 +86,7 @@ return array(
 	'qBittorrentSortOrder' => 'eta',
 	'qBittorrentReverseSorting' => false,
 	'qBittorrentCombine' => false,
+	'qBittorrentApiVersion' => '1',
 	'rTorrentURL' => '',
 	'rTorrentURLOverride' => '',
 	'rTorrentUsername' => '',

+ 4 - 2
api/functions/homepage-connect-functions.php

@@ -1035,7 +1035,9 @@ function qBittorrentConnect()
 	if ($GLOBALS['homepageqBittorrentEnabled'] && !empty($GLOBALS['qBittorrentURL']) && qualifyRequest($GLOBALS['homepageqBittorrentAuth'])) {
 		$digest = qualifyURL($GLOBALS['qBittorrentURL'], true);
 		$data = array('username' => $GLOBALS['qBittorrentUsername'], 'password' => decrypt($GLOBALS['qBittorrentPassword']));
-		$url = $digest['scheme'] . '://' . $digest['host'] . $digest['port'] . $digest['path'] . '/login';
+		$apiVersionLogin = ($GLOBALS['qBittorrentApiVersion'] == '1') ? '/login' : '/api/v2/auth/login';
+		$apiVersionQuery = ($GLOBALS['qBittorrentApiVersion'] == '1') ? '/query/torrents?sort=' : '/api/v2/torrents/info?sort=';
+		$url = $digest['scheme'] . '://' . $digest['host'] . $digest['port'] . $digest['path'] . $apiVersionLogin;
 		try {
 			$options = (localURL($GLOBALS['qBittorrentURL'])) ? array('verify' => false) : array();
 			$response = Requests::post($url, array(), $data, $options);
@@ -1048,7 +1050,7 @@ function qBittorrentConnect()
 					'Cookie' => 'SID=' . $cookie['SID']->value
 				);
 				$reverse = $GLOBALS['qBittorrentReverseSorting'] ? 'true' : 'false';
-				$url = $digest['scheme'] . '://' . $digest['host'] . $digest['port'] . $digest['path'] . '/query/torrents?sort=' . $GLOBALS['qBittorrentSortOrder'] . '&reverse=' . $reverse;
+				$url = $digest['scheme'] . '://' . $digest['host'] . $digest['port'] . $digest['path'] . $apiVersionQuery . $GLOBALS['qBittorrentSortOrder'] . '&reverse=' . $reverse;
 				$response = Requests::get($url, $headers, $options);
 				if ($response) {
 					$torrentList = json_decode($response->body, true);

+ 19 - 1
api/functions/homepage-functions.php

@@ -527,6 +527,16 @@ function getHomepageList()
 			'value' => 'statusa'
 		),
 	);
+	$qBittorrentApiOptions = array(
+		array(
+			'name' => 'V1',
+			'value' => '1'
+		),
+		array(
+			'name' => 'V2',
+			'value' => '2'
+		),
+	);
 	$qBittorrentSortOptions = array(
 		array(
 			'name' => 'Hash',
@@ -1337,6 +1347,13 @@ function getHomepageList()
 						'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
 						'placeholder' => 'http(s)://hostname:port'
 					),
+					array(
+						'type' => 'select',
+						'name' => 'qBittorrentApiVersion',
+						'label' => 'API Version',
+						'value' => $GLOBALS['qBittorrentApiVersion'],
+						'options' => $qBittorrentApiOptions
+					),
 					array(
 						'type' => 'input',
 						'name' => 'qBittorrentUsername',
@@ -1356,7 +1373,8 @@ function getHomepageList()
 						'name' => 'qBittorrentHideSeeding',
 						'label' => 'Hide Seeding',
 						'value' => $GLOBALS['qBittorrentHideSeeding']
-					), array(
+					),
+					array(
 						'type' => 'switch',
 						'name' => 'qBittorrentHideCompleted',
 						'label' => 'Hide Completed',