Bläddra i källkod

nzbget work started

causefx 8 år sedan
förälder
incheckning
ffe8449b8c

+ 5 - 0
api/config/default.php

@@ -33,8 +33,13 @@ return array(
     'ssoTautulli' => false,
 	'sabnzbdURL' => '',
     'sabnzbdToken' => '',
+    'nzbgetURL' => '',
+    'nzbgetUsername' => '',
+    'nzbgetPassword' => '',
     'homepageSabnzbdEnabled' => false,
     'homepageSabnzbdAuth' => '1',
+    'homepageNzbgetEnabled' => false,
+    'homepageNzbgetAuth' => '1',
     'homepagePlexEnabled' => false,
     'homepagePlexAuth' => '1',
     'homepageEmbyEnabled' => false,

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

@@ -23,6 +23,9 @@ function homepageConnect($array){
         case 'getSabnzbd':
             return sabnzbdConnect();
             break;
+        case 'getNzbget':
+            return nzbgetConnect();
+            break;
         default:
             # code...
             break;
@@ -482,7 +485,7 @@ function embyConnect($action,$key=null,$skip=false){
 	}
 	return false;
 }
-function sabnzbdConnect($action=null) {
+function sabnzbdConnect() {
     if($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])){
         $url = qualifyURL($GLOBALS['sabnzbdURL']);
         $url = $url.'/api?mode=queue&output=json&apikey='.$GLOBALS['sabnzbdToken'];
@@ -510,3 +513,31 @@ function sabnzbdConnect($action=null) {
         return $api;
     }
 }
+function nzbgetConnect() {
+    if($GLOBALS['homepageNzbgetEnabled'] && !empty($GLOBALS['nzbgetURL']) && qualifyRequest($GLOBALS['homepageNzbgetAuth'])){
+        $url = qualifyURL($GLOBALS['nzbgetURL']);
+        $url = $url.'/'.$GLOBALS['nzbgetUsername'].':'.decrypt($GLOBALS['nzbgetPassword']).'/jsonrpc/listgroups';
+        try{
+			$options = (localURL($url)) ? array('verify' => false ) : array();
+			$response = Requests::get($url, array(), $options);
+			if($response->success){
+				$api['content']['queueItems'] = json_decode($response->body, true);
+			}
+		}catch( Requests_Exception $e ) {
+			writeLog('error', 'NZBGet Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+		};
+        $url = qualifyURL($GLOBALS['nzbgetURL']);
+        $url = $url.'/'.$GLOBALS['nzbgetUsername'].':'.decrypt($GLOBALS['nzbgetPassword']).'/jsonrpc/history';
+        try{
+			$options = (localURL($url)) ? array('verify' => false ) : array();
+			$response = Requests::get($url, array(), $options);
+			if($response->success){
+				$api['content']['historyItems']= json_decode($response->body, true);
+			}
+		}catch( Requests_Exception $e ) {
+			writeLog('error', 'NZBGet Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+		};
+        $api['content'] = isset($api['content']) ? $api['content'] : false;
+        return $api;
+    }
+}

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

@@ -51,7 +51,18 @@ function buildHomepageItem($homepageItem){
 
 			break;
 		case 'homepageOrdernzbget':
-
+			if($GLOBALS['homepageNzbgetEnabled']){
+				$item .= '
+				<script>
+				// NZBGet
+				homepageDownloader("nzbget");
+				setInterval(function() {
+					homepageDownloader("nzbget");
+				}, '.$GLOBALS['homepageDownloadRefresh'].');
+				// End NZBGet
+				</script>
+				';
+			}
 			break;
 		case 'homepageOrdersabnzbd':
 			if($GLOBALS['homepageSabnzbdEnabled']){
@@ -453,6 +464,59 @@ function getHomepageList(){
 					)
 				)
             )
+        ),
+		array(
+            'name' => 'NZBGet',
+            'enabled' => false,
+            'image' => 'plugins/images/tabs/nzbget.png',
+            'category' => 'Downloader',
+            'settings' => array(
+                'Enable' => array(
+                    array(
+            			'type' => 'switch',
+            			'name' => 'homepageNzbgetEnabled',
+            			'label' => 'Enable',
+            			'value' => $GLOBALS['homepageNzbgetEnabled']
+            		),
+					array(
+            			'type' => 'select',
+            			'name' => 'homepageNzbgetAuth',
+            			'label' => 'Minimum Authentication',
+            			'value' => $GLOBALS['homepageNzbgetAuth'],
+                        'options' => $groups
+            		)
+                ),
+				'Connection' => array(
+                    array(
+                        'type' => 'input',
+                        'name' => 'nzbgetURL',
+                        'label' => 'URL',
+                        'value' => $GLOBALS['nzbgetURL'],
+						'placeholder' => 'http(s)://hostname:port'
+                    ),
+                    array(
+                        'type' => 'input',
+                        'name' => 'nzbgetUsername',
+                        'label' => 'Username',
+                        'value' => $GLOBALS['nzbgetUsername']
+                    ),
+					array(
+                        'type' => 'password',
+                        'name' => 'nzbgetPassword',
+                        'label' => 'Password',
+                        'value' => $GLOBALS['nzbgetPassword']
+                    )
+                ),
+				'Misc Options' => array(
+					array(
+						'type' => 'select',
+						'name' => 'homepageDownloadRefresh',
+						'label' => 'Refresh Seconds',
+						'value' => $GLOBALS['homepageDownloadRefresh'],
+						'options' => $time
+					)
+				)
+            )
         )
     );
 }

+ 1 - 0
api/functions/normal-functions.php

@@ -111,6 +111,7 @@ function encrypt($password, $key = null) {
     return openssl_encrypt($password, 'AES-256-CBC', $key, 0, fillString($key,16));
 }
 function decrypt($password, $key = null) {
+	if(empty($password)){ return ''; }
     $key = (isset($GLOBALS['organizrHash'])) ? $GLOBALS['organizrHash'] : $key;
     return openssl_decrypt($password, 'AES-256-CBC', $key, 0, fillString($key,16));
 }

+ 70 - 10
js/functions.js

@@ -2004,15 +2004,12 @@ function buildDownloaderItem(array, source, type='none'){
 		case 'sabnzbd':
 			switch (type) {
 				case 'queue':
-					console.log(source);
-					console.log(array.queue);
-					console.log(array.queue.slots.length);
 					if(array.queue.slots.length == 0){
 						return '<tr><td class="max-texts" lang="en">Nothing in queue</td></tr>';
 					}
 					$.each(array.queue.slots, function(i,v) {
 						var action = (v.status == "Downloading") ? 'pause' : 'resume';
-						var actionIcon = (v.status == "Downloading") ? 'play' : 'pause';
+						var actionIcon = (v.status == "Downloading") ? 'pause' : 'play';
 						items += `
 						<tr>
 							<td class="max-texts">`+v.filename+`</td>
@@ -2030,9 +2027,6 @@ function buildDownloaderItem(array, source, type='none'){
 					});
 					break;
 				case 'history':
-					console.log(source);
-					console.log(array.history);
-					console.log(array.history.slots.length);
 					if(array.history.slots.length == 0){
 						return '<tr><td class="max-texts" lang="en">Nothing in hitsory</td></tr>';
 					}
@@ -2056,6 +2050,58 @@ function buildDownloaderItem(array, source, type='none'){
 					return false;
 			}
 			break;
+		case 'nzbget':
+			switch (type) {
+				case 'queue':
+					if(array.result.length == 0){
+						return '<tr><td class="max-texts" lang="en">Nothing in queue</td></tr>';
+					}
+					$.each(array.result, function(i,v) {
+						var action = (v.Status == "Downloading") ? 'pause' : 'resume';
+						var actionIcon = (v.Status == "Downloading") ? 'pause' : 'play';
+						var percent = Math.floor((v.FileSizeMB - v.RemainingSizeMB) / v.FileSizeMB);
+						v.Category = (v.Category !== '') ? v.Category : 'Not Set';
+						items += `
+						<tr>
+							<td class="max-texts">`+v.NZBName+`</td>
+							<td class="hidden-xs">`+v.Status+`</td>
+							<!--<td class="downloader mouse" data-target="`+v.NZBID+`" data-source="sabnzbd" data-action="`+action+`"><i class="fa fa-`+actionIcon+`"></i></td>-->
+							<td class="hidden-xs"><span class="label label-info">`+v.Category+`</span></td>
+							<td class="hidden-xs">`+humanFileSize(v.FileSizeLo,true)+`</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;
+				case 'history':
+					if(array.result.length == 0){
+						return '<tr><td class="max-texts" lang="en">Nothing in history</td></tr>';
+					}
+					$.each(array.result, function(i,v) {
+						v.Category = (v.Category !== '') ? v.Category : 'Not Set';
+						items += `
+						<tr>
+							<td class="max-texts">`+v.NZBName+`</td>
+							<td class="hidden-xs">`+v.Status+`</td>
+							<td class="hidden-xs"><span class="label label-info">`+v.Category+`</span></td>
+							<td class="hidden-xs">`+humanFileSize(v.FileSizeLo,true)+`</td>
+							<td class="text-right">
+								<div class="progress progress-lg m-b-0">
+									<div class="progress-bar progress-bar-info" style="width: 100%;" role="progressbar">100%</div>
+								</div>
+							</td>
+						</tr>
+						`;
+					});
+					break;
+				default:
+
+			}
+			break;
 		default:
 			return false;
 	}
@@ -2070,8 +2116,6 @@ function buildDownloader(array, source){
 	var state = '';
 	var active = '';
 	console.log(array);
-	console.log(queueItems);
-	console.log(historyItems);
 	console.log(downloader);
 	if(queueItems){
 		switch (source) {
@@ -2264,7 +2308,23 @@ function toUpper(str) {
 	        return word[0].toUpperCase() + word.substr(1);
 	    })
 	    .join(' ');
- }
+}
+// human filesize
+function humanFileSize(bytes, si) {
+    var thresh = si ? 1000 : 1024;
+    if(Math.abs(bytes) < thresh) {
+        return bytes + ' B';
+    }
+    var units = si
+        ? ['kB','MB','GB','TB','PB','EB','ZB','YB']
+        : ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
+    var u = -1;
+    do {
+        bytes /= thresh;
+        ++u;
+    } while(Math.abs(bytes) >= thresh && u < units.length - 1);
+    return bytes.toFixed(1)+' '+units[u];
+}
 //Settings change auth
 function changeAuth(){
     var type = $('#authSelect').val();

BIN
plugins/images/tabs/nzbget.png