mirror of
				https://github.com/KevinMidboe/delugeClient.git
				synced 2025-10-29 12:00:13 +00:00 
			
		
		
		
	Compare commits
	
		
			10 Commits
		
	
	
		
			snyk-fix-b
			...
			feature/pa
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4491e551c0 | |||
| 499b0116e8 | |||
| e22de16d8c | |||
| bb5da9c455 | |||
| 35b43e1b10 | |||
| 0616d8eeed | |||
| f101d81b43 | |||
| 1e1a270b07 | |||
| 6450041198 | |||
| 50fe8adaf1 | 
@@ -1,10 +1,11 @@
 | 
			
		||||
[Deluge]
 | 
			
		||||
HOST = YOUR_DELUGE_HOST
 | 
			
		||||
HOST = YOUR_DELUGE_HOST_IP
 | 
			
		||||
PORT = YOUR_DELUGE_PORT
 | 
			
		||||
USER = YOUR_DELUGE_USER
 | 
			
		||||
PASSWORD = YOUR_DELUGE_PASSWORD
 | 
			
		||||
 | 
			
		||||
[ssh]
 | 
			
		||||
HOST = YOUR_DELUGE_SERVER_IP
 | 
			
		||||
HOST = YOUR_SSH_HOST_IP
 | 
			
		||||
USER = YOUR_SSH_USER
 | 
			
		||||
PKEY = YOUR_SSH_PRIVATE_KEY_DIRECTORY
 | 
			
		||||
PKEY = YOUR_SSH_PRIVATE_KEY_DIR
 | 
			
		||||
PASSWORD = YOUR_SSH_PASSWORD
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,7 @@ import os
 | 
			
		||||
import sys
 | 
			
		||||
import re
 | 
			
		||||
import signal
 | 
			
		||||
import json
 | 
			
		||||
import socket
 | 
			
		||||
import logging
 | 
			
		||||
import logging.config
 | 
			
		||||
@@ -42,7 +43,7 @@ from pprint import pprint
 | 
			
		||||
from deluge_client import DelugeRPCClient
 | 
			
		||||
from sshtunnel import SSHTunnelForwarder
 | 
			
		||||
from docopt import docopt
 | 
			
		||||
from .utils import ColorizeFilter, convert
 | 
			
		||||
from utils import ColorizeFilter, convert
 | 
			
		||||
 | 
			
		||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
 | 
			
		||||
 | 
			
		||||
@@ -95,6 +96,7 @@ class Deluge(object):
 | 
			
		||||
 | 
			
		||||
      self.ssh_host = config['ssh']['HOST']
 | 
			
		||||
      self.ssh_user = config['ssh']['USER']
 | 
			
		||||
      self.ssh_password = config['ssh']['PASSWORD']
 | 
			
		||||
      self.ssh_pkey = config['ssh']['PKEY']
 | 
			
		||||
   
 | 
			
		||||
      self._connect()
 | 
			
		||||
@@ -109,6 +111,10 @@ class Deluge(object):
 | 
			
		||||
   def _connect(self):
 | 
			
		||||
      logger.info('Checking if script on same server as deluge RPC')
 | 
			
		||||
      if (socket.gethostbyname(socket.gethostname()) != self.host):
 | 
			
		||||
         if (self.ssh_password):
 | 
			
		||||
            self.tunnel = SSHTunnelForwarder(self.ssh_host, ssh_username=self.ssh_user, ssh_password=self.ssh_password,
 | 
			
		||||
               local_bind_address=('localhost', self.port), remote_bind_address=('localhost', self.port))
 | 
			
		||||
         else:
 | 
			
		||||
            self.tunnel = SSHTunnelForwarder(self.ssh_host, ssh_username=self.ssh_user, ssh_pkey=self.ssh_pkey, 
 | 
			
		||||
               local_bind_address=('localhost', self.port), remote_bind_address=('localhost', self.port))
 | 
			
		||||
         self.tunnel.start()
 | 
			
		||||
@@ -148,7 +154,7 @@ class Deluge(object):
 | 
			
		||||
      else:
 | 
			
		||||
         response = self.client.call('core.pause_torrent', [id])
 | 
			
		||||
      
 | 
			
		||||
      print('Response:', response)
 | 
			
		||||
      return response
 | 
			
		||||
 | 
			
		||||
   def remove(self, name):
 | 
			
		||||
      matches = list(filter(lambda t: t.name == name, self.get_all()))
 | 
			
		||||
@@ -163,6 +169,7 @@ class Deluge(object):
 | 
			
		||||
 | 
			
		||||
         if (response == False):
 | 
			
		||||
            raise AttributeError('Unable to remove torrent.')
 | 
			
		||||
            
 | 
			
		||||
         return response
 | 
			
		||||
      else:
 | 
			
		||||
         logger.error('ERROR. No torrent found with that name.')
 | 
			
		||||
@@ -239,13 +246,13 @@ def signal_handler(signal, frame):
 | 
			
		||||
   logger.info('\nGood bye!')
 | 
			
		||||
   sys.exit(0)
 | 
			
		||||
 | 
			
		||||
def main():
 | 
			
		||||
def main(arg=None):
 | 
			
		||||
   """
 | 
			
		||||
   Main function, parse the input
 | 
			
		||||
   """
 | 
			
		||||
   signal.signal(signal.SIGINT, signal_handler)
 | 
			
		||||
 | 
			
		||||
   arguments = docopt(__doc__, version='1')
 | 
			
		||||
   arguments = docopt(__doc__, argv=arg, version='1')
 | 
			
		||||
 | 
			
		||||
   # Set logging level for streamHandler
 | 
			
		||||
   if arguments['--debug']:
 | 
			
		||||
@@ -272,34 +279,45 @@ def main():
 | 
			
		||||
      logger.info('Add cmd selected with link {}'.format(magnet))
 | 
			
		||||
      response = deluge.add(magnet)
 | 
			
		||||
      print('Add response: ', response)
 | 
			
		||||
      return response
 | 
			
		||||
 | 
			
		||||
   elif arguments['search']:
 | 
			
		||||
      logger.info('Search cmd selected for query: {}'.format(query))
 | 
			
		||||
      response = deluge.search(query)
 | 
			
		||||
      [ pprint(t.toJSON()) for t in response ]
 | 
			
		||||
      return response
 | 
			
		||||
 | 
			
		||||
   elif arguments['progress']:
 | 
			
		||||
      logger.info('Progress cmd selected.')
 | 
			
		||||
      pprint(deluge.progress())
 | 
			
		||||
      exit(0)
 | 
			
		||||
      [ pprint(t.toJSON()) for t in deluge.progress() ]
 | 
			
		||||
      response = deluge.progress()
 | 
			
		||||
      print(response)
 | 
			
		||||
      # [ pprint(t.toJSON()) for t in response ]
 | 
			
		||||
      return response
 | 
			
		||||
 | 
			
		||||
   elif arguments['get']:
 | 
			
		||||
      logger.info('Get cmd selected for id: {}'.format(_id))
 | 
			
		||||
      response = deluge.get(_id)
 | 
			
		||||
      pprint(response.toJSON())
 | 
			
		||||
      return response
 | 
			
		||||
 | 
			
		||||
   elif arguments['ls']:
 | 
			
		||||
      logger.info('List cmd selected')
 | 
			
		||||
      [ pprint(t.toJSON()) for t in deluge.get_all(_filter=_filter) ]
 | 
			
		||||
      response = deluge.get_all(_filter=_filter)
 | 
			
		||||
      response = [t.toJSON() for t in response]
 | 
			
		||||
      # pprint(response)
 | 
			
		||||
      return json.dumps(response)
 | 
			
		||||
 | 
			
		||||
   elif arguments['toggle']:
 | 
			
		||||
      logger.info('Toggling id: {}'.format(_id))
 | 
			
		||||
      deluge.togglePaused(_id)
 | 
			
		||||
      response = deluge.togglePaused(_id)
 | 
			
		||||
      print('toggle response: ', response)
 | 
			
		||||
      return response
 | 
			
		||||
 | 
			
		||||
   elif arguments['rm']:
 | 
			
		||||
      logger.info('Remove by name: {}'.format(name))
 | 
			
		||||
      deluge.remove(name)
 | 
			
		||||
      response = deluge.remove(name)
 | 
			
		||||
      print('rm response: ', response)
 | 
			
		||||
      return response
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
   main()
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,9 @@ import asyncio
 | 
			
		||||
import datetime
 | 
			
		||||
import random
 | 
			
		||||
import websockets
 | 
			
		||||
import json
 | 
			
		||||
 | 
			
		||||
import deluge_cli
 | 
			
		||||
 | 
			
		||||
async def hello(websocket, path):
 | 
			
		||||
	name = await websocket.recv()
 | 
			
		||||
@@ -19,9 +22,16 @@ async def time(websocket, path):
 | 
			
		||||
		await asyncio.sleep(1)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def deluge(websocket, path):
 | 
			
		||||
	while True:
 | 
			
		||||
		downloading = deluge_cli.main(['progress'])
 | 
			
		||||
		await websocket.send(json.dumps(downloading))
 | 
			
		||||
 | 
			
		||||
		await asyncio.sleep(1)
 | 
			
		||||
 | 
			
		||||
serve_hello = websockets.serve(hello, '0.0.0.0', 8765)
 | 
			
		||||
serve_time = websockets.serve(time, '0.0.0.0', 5678)
 | 
			
		||||
serve_deluge = websockets.serve(deluge, '0.0.0.0', 5678)
 | 
			
		||||
 | 
			
		||||
asyncio.get_event_loop().run_until_complete(serve_hello)
 | 
			
		||||
asyncio.get_event_loop().run_until_complete(serve_time)
 | 
			
		||||
asyncio.get_event_loop().run_until_complete(serve_deluge)
 | 
			
		||||
asyncio.get_event_loop().run_forever()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user