Browse Source

Merge pull request #779 from rob1998/v2-develop

Added qBittorrent as download client
causefx 8 years ago
parent
commit
67c86e6790

+ 10 - 2
api/config/default.php

@@ -36,15 +36,22 @@ return array(
     'nzbgetURL' => '',
     'nzbgetUsername' => '',
     'nzbgetPassword' => '',
-	'transmissionURL' => '',
+    'transmissionURL' => '',
     'transmissionUsername' => '',
     'transmissionPassword' => '',
     'transmissionHideSeeding' => false,
     'transmissionHideCompleted' => false,
+    'qBittorrentURL' => '',
+    'qBittorrentUsername' => '',
+    'qBittorrentPassword' => '',
+    'qBittorrentHideSeeding' => false,
+    'qBittorrentHideCompleted' => false,
     'homepageSabnzbdEnabled' => false,
     'homepageSabnzbdAuth' => '1',
     'homepageTransmissionEnabled' => false,
     'homepageTransmissionAuth' => '1',
+    'homepageqBittorrentEnabled' => false,
+    'homepageqBittorrentAuth' => '1',
     'homepageNzbgetEnabled' => false,
     'homepageNzbgetAuth' => '1',
     'homepagePlexEnabled' => false,
@@ -65,7 +72,8 @@ return array(
 	'homepageOrderombi' => '12',
 	'homepageOrdercalendar' => '13',
 	'homepageOrdernoticeguest' => '14',
-	'homepageOrdertransmission' => '15',
+    'homepageOrdertransmission' => '15',
+    'homepageOrderqBittorrent' => '16',
     'homepageShowStreamNames' => false,
     'homepageShowStreamNamesAuth' => '1',
     'homepageStreamRefresh' => '60000',

+ 58 - 1
api/functions/homepage-connect-functions.php

@@ -29,6 +29,9 @@ function homepageConnect($array){
         case 'getTransmission':
             return transmissionConnect();
             break;
+        case 'getqBittorrent':
+            return qBittorrentConnect();
+            break;
         default:
             # code...
             break;
@@ -561,7 +564,6 @@ function nzbgetConnect() {
 function transmissionConnect() {
     if($GLOBALS['homepageTransmissionEnabled'] && !empty($GLOBALS['transmissionURL']) && qualifyRequest($GLOBALS['homepageTransmissionAuth'])){
         $digest = qualifyURL($GLOBALS['transmissionURL'], true);
-        $digest['port'] = !empty($digest['port']) ? ':'.$digest['port'] : '';
         $passwordInclude = ($GLOBALS['transmissionUsername'] != '' && $GLOBALS['transmissionPassword'] != '') ? $GLOBALS['transmissionUsername'].':'.decrypt($GLOBALS['transmissionPassword'])."@" : '';
 	    $url = $digest['scheme'].'://'.$passwordInclude.$digest['host'].$digest['port'].$digest['path'].'/rpc';
         try{
@@ -611,3 +613,58 @@ function transmissionConnect() {
         return $api;
     }
 }
+function qBittorrentConnect() {
+    if($GLOBALS['homepageqBittorrentEnabled'] && !empty($GLOBALS['qBittorrentURL']) && qualifyRequest($GLOBALS['homepageqBittorrentAuth'])){
+        $digest = qualifyURL($GLOBALS['qBittorrentURL'], true);
+        $passwordInclude = ($GLOBALS['qBittorrentUsername'] != '' && $GLOBALS['qBittorrentPassword'] != '') ? 'username='.$GLOBALS['qBittorrentUsername'].'&password='.decrypt($GLOBALS['qBittorrentPassword'])."@" : '';
+        $data = array('username'=>$GLOBALS['qBittorrentUsername'], 'password'=> decrypt($GLOBALS['qBittorrentPassword']));
+        $url = $digest['scheme'].'://'.$digest['host'].$digest['port'].$digest['path'].'/login';
+        try{
+            $options = (localURL($GLOBALS['qBittorrentURL'])) ? array('verify' => false ) : array();
+            $response = Requests::post($url, array(), $data, $options);
+            $reflection = new ReflectionClass($response->cookies);
+            $cookie = $reflection->getProperty("cookies");
+            $cookie->setAccessible(true);
+            $cookie = $cookie->getValue($response->cookies);
+            if($cookie){
+                $headers = array(
+                    'Cookie' => 'SID=' . $cookie['SID']->value
+                );
+                $url = $digest['scheme'].'://'.$digest['host'].$digest['port'].$digest['path'].'/query/torrents?filter=downloading&sort=eta';
+                $response = Requests::get($url, $headers, $options);
+                if($response){
+                    $torrentList = json_decode($response->body, true);
+                    if($GLOBALS['qBittorrentHideSeeding'] || $GLOBALS['qBittorrentHideCompleted']){
+                        $filter = array();
+                        $torrents['arguments']['torrents'] = array();
+                        if($GLOBALS['qBittorrentHideSeeding']){ array_push($filter, 'uploading', 'stalledUP', 'queuedUP'); }
+                        if($GLOBALS['qBittorrentHideCompleted']){ array_push($filter, 'pausedUP'); }
+                        foreach ($torrentList as $key => $value) {
+                            if(!in_array($value['state'], $filter)){
+                                $torrents['arguments']['torrents'][] = $value;
+                            }
+                        }
+                    }else{
+                        $torrents['arguments']['torrents'] = json_decode($response->body, true);
+                    }
+
+                    $api['content']['queueItems'] = $torrents;
+                    $api['content']['historyItems'] = false;
+                    
+                }
+            }else{
+                writeLog('error', 'qBittorrent Connect Function - Error: Could not get session ID', 'SYSTEM');
+            }
+        }catch( Requests_Exception $e ) {
+            writeLog('error', 'qBittorrent Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+        };
+        $api['content'] = isset($api['content']) ? $api['content'] : false;
+        return $api;
+    }
+}
+function accessProtected($obj, $prop) {
+  $reflection = new ReflectionClass($obj);
+  $property = $reflection->getProperty($prop);
+  $property->setAccessible(true);
+  return $property->getValue($obj);
+}

+ 115 - 36
api/functions/homepage-functions.php

@@ -16,7 +16,8 @@ function homepageOrder(){
 		"homepageOrderombi" => $GLOBALS['homepageOrderombi'],
 		"homepageOrdercalendar" => $GLOBALS['homepageOrdercalendar'],
 		"homepageOrdernoticeguest" => $GLOBALS['homepageOrdernoticeguest'],
-		"homepageOrdertransmission" => $GLOBALS['homepageOrdertransmission'],
+        "homepageOrdertransmission" => $GLOBALS['homepageOrdertransmission'],
+        "homepageOrderqBittorrent" => $GLOBALS['homepageOrderqBittorrent'],
 	);
 	asort($homepageOrder);
 	return $homepageOrder;
@@ -47,6 +48,20 @@ function buildHomepageItem($homepageItem){
 		case 'homepageOrderspeedtest':
 
 			break;
+        case 'homepageOrderqBittorrent':
+            if($GLOBALS['homepageOrderqBittorrent']){
+                $item .= '
+                <script>
+                // homepageOrderqBittorrent
+                homepageDownloader("qBittorrent");
+                setInterval(function() {
+                    homepageDownloader("qBittorrent");
+                }, '.$GLOBALS['homepageDownloadRefresh'].');
+                // End homepageOrderqBittorrent
+                </script>
+                ';
+            }
+            break;
 		case 'homepageOrdertransmission':
 			if($GLOBALS['homepageTransmissionEnabled']){
 				$item .= '
@@ -529,7 +544,7 @@ function getHomepageList(){
 				)
             )
         ),
-		array(
+        array(
             'name' => 'Transmission',
             'enabled' => false,
             'image' => 'plugins/images/tabs/transmission.png',
@@ -537,26 +552,26 @@ function getHomepageList(){
             'settings' => array(
                 'Enable' => array(
                     array(
-            			'type' => 'switch',
-            			'name' => 'homepageTransmissionEnabled',
-            			'label' => 'Enable',
-            			'value' => $GLOBALS['homepageTransmissionEnabled']
-            		),
-					array(
-            			'type' => 'select',
-            			'name' => 'homepageTransmissionAuth',
-            			'label' => 'Minimum Authentication',
-            			'value' => $GLOBALS['homepageTransmissionAuth'],
+                        'type' => 'switch',
+                        'name' => 'homepageTransmissionEnabled',
+                        'label' => 'Enable',
+                        'value' => $GLOBALS['homepageTransmissionEnabled']
+                    ),
+                    array(
+                        'type' => 'select',
+                        'name' => 'homepageTransmissionAuth',
+                        'label' => 'Minimum Authentication',
+                        'value' => $GLOBALS['homepageTransmissionAuth'],
                         'options' => $groups
-            		)
+                    )
                 ),
-				'Connection' => array(
+                'Connection' => array(
                     array(
                         'type' => 'input',
                         'name' => 'transmissionURL',
                         'label' => 'URL',
                         'value' => $GLOBALS['transmissionURL'],
-						'placeholder' => 'http(s)://hostname:port'
+                        'placeholder' => 'http(s)://hostname:port'
                     ),
                     array(
                         'type' => 'input',
@@ -564,33 +579,97 @@ function getHomepageList(){
                         'label' => 'Username',
                         'value' => $GLOBALS['transmissionUsername']
                     ),
-					array(
+                    array(
                         'type' => 'password',
                         'name' => 'transmissionPassword',
                         'label' => 'Password',
                         'value' => $GLOBALS['transmissionPassword']
                     )
                 ),
-				'Misc Options' => array(
-					array(
-            			'type' => 'switch',
-            			'name' => 'transmissionHideSeeding',
-            			'label' => 'Hide Seeding',
-            			'value' => $GLOBALS['transmissionHideSeeding']
-            		),array(
-            			'type' => 'switch',
-            			'name' => 'transmissionHideCompleted',
-            			'label' => 'Hide Completed',
-            			'value' => $GLOBALS['transmissionHideCompleted']
-            		),
-					array(
-						'type' => 'select',
-						'name' => 'homepageDownloadRefresh',
-						'label' => 'Refresh Seconds',
-						'value' => $GLOBALS['homepageDownloadRefresh'],
-						'options' => $time
-					)
-				)
+                'Misc Options' => array(
+                    array(
+                        'type' => 'switch',
+                        'name' => 'transmissionHideSeeding',
+                        'label' => 'Hide Seeding',
+                        'value' => $GLOBALS['transmissionHideSeeding']
+                    ),array(
+                        'type' => 'switch',
+                        'name' => 'transmissionHideCompleted',
+                        'label' => 'Hide Completed',
+                        'value' => $GLOBALS['transmissionHideCompleted']
+                    ),
+                    array(
+                        'type' => 'select',
+                        'name' => 'homepageDownloadRefresh',
+                        'label' => 'Refresh Seconds',
+                        'value' => $GLOBALS['homepageDownloadRefresh'],
+                        'options' => $time
+                    )
+                )
+            )
+        ),
+        array(
+            'name' => 'qBittorrent',
+            'enabled' => false,
+            'image' => 'plugins/images/tabs/qBittorrent.png',
+            'category' => 'Downloader',
+            'settings' => array(
+                'Enable' => array(
+                    array(
+                        'type' => 'switch',
+                        'name' => 'homepageqBittorrentEnabled',
+                        'label' => 'Enable',
+                        'value' => $GLOBALS['homepageqBittorrentEnabled']
+                    ),
+                    array(
+                        'type' => 'select',
+                        'name' => 'homepageqBittorrentAuth',
+                        'label' => 'Minimum Authentication',
+                        'value' => $GLOBALS['homepageqBittorrentAuth'],
+                        'options' => $groups
+                    )
+                ),
+                'Connection' => array(
+                    array(
+                        'type' => 'input',
+                        'name' => 'qBittorrentURL',
+                        'label' => 'URL',
+                        'value' => $GLOBALS['qBittorrentURL'],
+                        'placeholder' => 'http(s)://hostname:port'
+                    ),
+                    array(
+                        'type' => 'input',
+                        'name' => 'qBittorrentUsername',
+                        'label' => 'Username',
+                        'value' => $GLOBALS['qBittorrentUsername']
+                    ),
+                    array(
+                        'type' => 'password',
+                        'name' => 'qBittorrentPassword',
+                        'label' => 'Password',
+                        'value' => $GLOBALS['qBittorrentPassword']
+                    )
+                ),
+                'Misc Options' => array(
+                    array(
+                        'type' => 'switch',
+                        'name' => 'qBittorrentHideSeeding',
+                        'label' => 'Hide Seeding',
+                        'value' => $GLOBALS['qBittorrentHideSeeding']
+                    ),array(
+                        'type' => 'switch',
+                        'name' => 'qBittorrentnHideCompleted',
+                        'label' => 'Hide Completed',
+                        'value' => $GLOBALS['qBittorrentHideCompleted']
+                    ),
+                    array(
+                        'type' => 'select',
+                        'name' => 'homepageDownloadRefresh',
+                        'label' => 'Refresh Seconds',
+                        'value' => $GLOBALS['homepageDownloadRefresh'],
+                        'options' => $time
+                    )
+                )
             )
         )
     );

+ 66 - 1
js/functions.js

@@ -680,7 +680,6 @@ function buildHomepage(){
 	ajaxloader(".content-wrap","in");
 	organizrAPI('GET','api/?v1/settings/homepage/list').success(function(data) {
 		var response = JSON.parse(data);
-		console.log(response);
 		$('#settings-homepage-list').html(buildHomepageItem(response.data));
 	}).fail(function(xhr) {
 		console.error("Organizr Function: API Connection Failed");
@@ -818,6 +817,7 @@ function buildTabEditor(){
 	ajaxloader(".content-wrap","in");
 	organizrAPI('GET','api/?v1/tab/list').success(function(data) {
 		var response = JSON.parse(data);
+		console.log(response.data);
 		$('#tabEditorTable').html(buildTabEditorItem(response.data));
 	}).fail(function(xhr) {
 		console.error("Organizr Function: API Connection Failed");
@@ -2166,6 +2166,68 @@ function buildDownloaderItem(array, source, type='none'){
 
 			}
 			break;
+
+		case 'qBittorrent':
+			switch (type) {
+				case 'queue':
+				console.log(array);
+					if(array.arguments.torrents == 0){
+						return '<tr><td class="max-texts" lang="en">Nothing in queue</td></tr>';
+					}
+					$.each(array.arguments.torrents, function(i,v) {
+						switch (v.state) {
+							case 'stalledDL':
+								var status = 'No Peers';
+								break;
+							case 'metaDL':
+								var status = 'Getting Metadata';
+								break;
+							case 'uploading':
+								var status = 'Seeding';
+								break;
+							case 'queuedUP':
+								var status = 'Seeding Queued';
+								break;
+							case 'downloading':
+								var status = 'Downloading';
+								break;
+							case 'queuedDL':
+								var status = 'Queued';
+								break;
+							case 'checkingDL':
+							case 'checkingUP':
+								var status = 'Checking Files';
+								break;
+							case 'pausedDL':
+								var status = 'Paused';
+								break;
+							case 'pausedUP':
+								var status = 'Complete';
+								break;
+							default:
+								var status = 'Complete';
+						}
+						var percent = Math.floor(v.progress * 100);
+						var size = v.total_size != -1 ? humanFileSize(v.total_size,true) : "?";
+						items += `
+						<tr>
+							<td class="max-texts">`+v.name+`</td>
+							<td class="hidden-xs">`+status+`</td>
+							<td class="hidden-xs">`+v.save_path+`</td>
+							<td class="hidden-xs">`+size+`</td>
+							<td class="text-right">
+								<div class="progress progress-lg m-b-0">
+									<div class="progress-bar progress-bar-info" style="width: `+percent+`%;" role="progressbar">`+percent+`%</div>
+								</div>
+							</td>
+						</tr>
+						`;
+					});
+					break;
+				default:
+
+			}
+			break;
 		default:
 			return false;
 	}
@@ -2308,6 +2370,9 @@ function homepageDownloader(type){
 		case 'transmission':
 			var action = 'getTransmission';
 			break;
+		case 'qBittorrent':
+			var action = 'getqBittorrent';
+			break;
 		default:
 
 	}

BIN
plugins/images/tabs/qBittorrent.png