mirror of
				https://github.com/KevinMidboe/delugeClient.git
				synced 2025-10-29 12:00:13 +00:00 
			
		
		
		
	Compare commits
	
		
			10 Commits
		
	
	
		
			py2-compat
			...
			feature/pa
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4491e551c0 | |||
| 499b0116e8 | |||
| e22de16d8c | |||
| bb5da9c455 | |||
| 35b43e1b10 | |||
| 0616d8eeed | |||
| f101d81b43 | |||
| 1e1a270b07 | |||
| 6450041198 | |||
| 50fe8adaf1 | 
@@ -1,10 +1,11 @@
 | 
				
			|||||||
[Deluge]
 | 
					[Deluge]
 | 
				
			||||||
HOST = YOUR_DELUGE_HOST
 | 
					HOST = YOUR_DELUGE_HOST_IP
 | 
				
			||||||
PORT = YOUR_DELUGE_PORT
 | 
					PORT = YOUR_DELUGE_PORT
 | 
				
			||||||
USER = YOUR_DELUGE_USER
 | 
					USER = YOUR_DELUGE_USER
 | 
				
			||||||
PASSWORD = YOUR_DELUGE_PASSWORD
 | 
					PASSWORD = YOUR_DELUGE_PASSWORD
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ssh]
 | 
					[ssh]
 | 
				
			||||||
HOST = YOUR_DELUGE_SERVER_IP
 | 
					HOST = YOUR_SSH_HOST_IP
 | 
				
			||||||
USER = YOUR_SSH_USER
 | 
					USER = YOUR_SSH_USER
 | 
				
			||||||
PKEY = YOUR_SSH_PRIVATE_KEY_DIRECTORY
 | 
					PKEY = YOUR_SSH_PRIVATE_KEY_DIR
 | 
				
			||||||
 | 
					PASSWORD = YOUR_SSH_PASSWORD
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,7 @@ Usage:
 | 
				
			|||||||
   deluge_cli ls [--downloading | --seeding | --paused]
 | 
					   deluge_cli ls [--downloading | --seeding | --paused]
 | 
				
			||||||
   deluge_cli toggle TORRENT
 | 
					   deluge_cli toggle TORRENT
 | 
				
			||||||
   deluge_cli progress
 | 
					   deluge_cli progress
 | 
				
			||||||
   deluge_cli rm NAME [--destroy | --debug | --warning | --error]
 | 
					   deluge_cli rm NAME [--debug | --warning | --error]
 | 
				
			||||||
   deluge_cli (-h | --help)
 | 
					   deluge_cli (-h | --help)
 | 
				
			||||||
   deluge_cli --version
 | 
					   deluge_cli --version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -24,7 +24,6 @@ Options:
 | 
				
			|||||||
   --debug       Print all debug log
 | 
					   --debug       Print all debug log
 | 
				
			||||||
   --warning     Print only logged warnings
 | 
					   --warning     Print only logged warnings
 | 
				
			||||||
   --error       Print error messages (Error/Warning)
 | 
					   --error       Print error messages (Error/Warning)
 | 
				
			||||||
   --destroy     When removing choose to remove file on disk
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
@@ -32,6 +31,7 @@ import os
 | 
				
			|||||||
import sys
 | 
					import sys
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
import signal
 | 
					import signal
 | 
				
			||||||
 | 
					import json
 | 
				
			||||||
import socket
 | 
					import socket
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import logging.config
 | 
					import logging.config
 | 
				
			||||||
@@ -96,6 +96,7 @@ class Deluge(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      self.ssh_host = config['ssh']['HOST']
 | 
					      self.ssh_host = config['ssh']['HOST']
 | 
				
			||||||
      self.ssh_user = config['ssh']['USER']
 | 
					      self.ssh_user = config['ssh']['USER']
 | 
				
			||||||
 | 
					      self.ssh_password = config['ssh']['PASSWORD']
 | 
				
			||||||
      self.ssh_pkey = config['ssh']['PKEY']
 | 
					      self.ssh_pkey = config['ssh']['PKEY']
 | 
				
			||||||
   
 | 
					   
 | 
				
			||||||
      self._connect()
 | 
					      self._connect()
 | 
				
			||||||
@@ -110,6 +111,10 @@ class Deluge(object):
 | 
				
			|||||||
   def _connect(self):
 | 
					   def _connect(self):
 | 
				
			||||||
      logger.info('Checking if script on same server as deluge RPC')
 | 
					      logger.info('Checking if script on same server as deluge RPC')
 | 
				
			||||||
      if (socket.gethostbyname(socket.gethostname()) != self.host):
 | 
					      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, 
 | 
					            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))
 | 
					               local_bind_address=('localhost', self.port), remote_bind_address=('localhost', self.port))
 | 
				
			||||||
         self.tunnel.start()
 | 
					         self.tunnel.start()
 | 
				
			||||||
@@ -149,9 +154,9 @@ class Deluge(object):
 | 
				
			|||||||
      else:
 | 
					      else:
 | 
				
			||||||
         response = self.client.call('core.pause_torrent', [id])
 | 
					         response = self.client.call('core.pause_torrent', [id])
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      print('Response:', response)
 | 
					      return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def remove(self, name, destroyFiles=False):
 | 
					   def remove(self, name):
 | 
				
			||||||
      matches = list(filter(lambda t: t.name == name, self.get_all()))
 | 
					      matches = list(filter(lambda t: t.name == name, self.get_all()))
 | 
				
			||||||
      logger.info('Matches for {}: {}'.format(name, matches))
 | 
					      logger.info('Matches for {}: {}'.format(name, matches))
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
@@ -159,11 +164,12 @@ class Deluge(object):
 | 
				
			|||||||
         raise ValueError('Multiple files found matching key. Unable to remove.')
 | 
					         raise ValueError('Multiple files found matching key. Unable to remove.')
 | 
				
			||||||
      elif (len(matches) == 1):
 | 
					      elif (len(matches) == 1):
 | 
				
			||||||
         torrent = matches[0]
 | 
					         torrent = matches[0]
 | 
				
			||||||
         response = self.client.call('core.remove_torrent', torrent.key, destroyFiles)
 | 
					         response = self.client.call('core.remove_torrent', torrent.key, False)
 | 
				
			||||||
         logger.info('Response: {}'.format(str(response)))
 | 
					         logger.info('Response: {}'.format(str(response)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         if (response == False):
 | 
					         if (response == False):
 | 
				
			||||||
            raise AttributeError('Unable to remove torrent.')
 | 
					            raise AttributeError('Unable to remove torrent.')
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
         return response
 | 
					         return response
 | 
				
			||||||
      else:
 | 
					      else:
 | 
				
			||||||
         logger.error('ERROR. No torrent found with that name.')
 | 
					         logger.error('ERROR. No torrent found with that name.')
 | 
				
			||||||
@@ -240,13 +246,13 @@ def signal_handler(signal, frame):
 | 
				
			|||||||
   logger.info('\nGood bye!')
 | 
					   logger.info('\nGood bye!')
 | 
				
			||||||
   sys.exit(0)
 | 
					   sys.exit(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main(arg=None):
 | 
				
			||||||
   """
 | 
					   """
 | 
				
			||||||
   Main function, parse the input
 | 
					   Main function, parse the input
 | 
				
			||||||
   """
 | 
					   """
 | 
				
			||||||
   signal.signal(signal.SIGINT, signal_handler)
 | 
					   signal.signal(signal.SIGINT, signal_handler)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   arguments = docopt(__doc__, version='1')
 | 
					   arguments = docopt(__doc__, argv=arg, version='1')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   # Set logging level for streamHandler
 | 
					   # Set logging level for streamHandler
 | 
				
			||||||
   if arguments['--debug']:
 | 
					   if arguments['--debug']:
 | 
				
			||||||
@@ -273,35 +279,45 @@ def main():
 | 
				
			|||||||
      logger.info('Add cmd selected with link {}'.format(magnet))
 | 
					      logger.info('Add cmd selected with link {}'.format(magnet))
 | 
				
			||||||
      response = deluge.add(magnet)
 | 
					      response = deluge.add(magnet)
 | 
				
			||||||
      print('Add response: ', response)
 | 
					      print('Add response: ', response)
 | 
				
			||||||
 | 
					      return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   elif arguments['search']:
 | 
					   elif arguments['search']:
 | 
				
			||||||
      logger.info('Search cmd selected for query: {}'.format(query))
 | 
					      logger.info('Search cmd selected for query: {}'.format(query))
 | 
				
			||||||
      response = deluge.search(query)
 | 
					      response = deluge.search(query)
 | 
				
			||||||
      [ pprint(t.toJSON()) for t in response ]
 | 
					      [ pprint(t.toJSON()) for t in response ]
 | 
				
			||||||
 | 
					      return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   elif arguments['progress']:
 | 
					   elif arguments['progress']:
 | 
				
			||||||
      logger.info('Progress cmd selected.')
 | 
					      logger.info('Progress cmd selected.')
 | 
				
			||||||
      pprint(deluge.progress())
 | 
					      response = deluge.progress()
 | 
				
			||||||
      exit(0)
 | 
					      print(response)
 | 
				
			||||||
      [ pprint(t.toJSON()) for t in deluge.progress() ]
 | 
					      # [ pprint(t.toJSON()) for t in response ]
 | 
				
			||||||
 | 
					      return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   elif arguments['get']:
 | 
					   elif arguments['get']:
 | 
				
			||||||
      logger.info('Get cmd selected for id: {}'.format(_id))
 | 
					      logger.info('Get cmd selected for id: {}'.format(_id))
 | 
				
			||||||
      response = deluge.get(_id)
 | 
					      response = deluge.get(_id)
 | 
				
			||||||
      pprint(response.toJSON())
 | 
					      pprint(response.toJSON())
 | 
				
			||||||
 | 
					      return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   elif arguments['ls']:
 | 
					   elif arguments['ls']:
 | 
				
			||||||
      logger.info('List cmd selected')
 | 
					      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']:
 | 
					   elif arguments['toggle']:
 | 
				
			||||||
      logger.info('Toggling id: {}'.format(_id))
 | 
					      logger.info('Toggling id: {}'.format(_id))
 | 
				
			||||||
      deluge.togglePaused(_id)
 | 
					      response = deluge.togglePaused(_id)
 | 
				
			||||||
 | 
					      print('toggle response: ', response)
 | 
				
			||||||
 | 
					      return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   elif arguments['rm']:
 | 
					   elif arguments['rm']:
 | 
				
			||||||
      destroy = arguments['--destroy']
 | 
					      logger.info('Remove by name: {}'.format(name))
 | 
				
			||||||
      logger.info('Remove by name: {}. Destroy files: {}'.format(name, destroy))
 | 
					      response = deluge.remove(name)
 | 
				
			||||||
      deluge.remove(name, destroy)
 | 
					      print('rm response: ', response)
 | 
				
			||||||
 | 
					      return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
   main()
 | 
					   main()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,9 @@ import asyncio
 | 
				
			|||||||
import datetime
 | 
					import datetime
 | 
				
			||||||
import random
 | 
					import random
 | 
				
			||||||
import websockets
 | 
					import websockets
 | 
				
			||||||
 | 
					import json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import deluge_cli
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async def hello(websocket, path):
 | 
					async def hello(websocket, path):
 | 
				
			||||||
	name = await websocket.recv()
 | 
						name = await websocket.recv()
 | 
				
			||||||
@@ -19,9 +22,16 @@ async def time(websocket, path):
 | 
				
			|||||||
		await asyncio.sleep(1)
 | 
							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_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_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()
 | 
					asyncio.get_event_loop().run_forever()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ cryptography==2.3
 | 
				
			|||||||
deluge-client==1.6.0
 | 
					deluge-client==1.6.0
 | 
				
			||||||
docopt==0.6.2
 | 
					docopt==0.6.2
 | 
				
			||||||
idna==2.7
 | 
					idna==2.7
 | 
				
			||||||
 | 
					paramiko==2.4.1
 | 
				
			||||||
pyasn1==0.4.4
 | 
					pyasn1==0.4.4
 | 
				
			||||||
pycparser==2.18
 | 
					pycparser==2.18
 | 
				
			||||||
PyNaCl==1.2.1
 | 
					PyNaCl==1.2.1
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								test.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								test.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					import deluge_cli
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					resp = deluge_cli.main('ls')
 | 
				
			||||||
 | 
					for el in list(resp):
 | 
				
			||||||
 | 
					    print(el)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# print(resp)
 | 
				
			||||||
							
								
								
									
										2
									
								
								utils.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								utils.py
									
									
									
									
									
								
							@@ -35,7 +35,7 @@ class ColorizeFilter(logging.Filter):
 | 
				
			|||||||
      return True
 | 
					      return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def convert(data):
 | 
					def convert(data):
 | 
				
			||||||
    if isinstance(data, bytes):  return data.decode('utf-8')
 | 
					    if isinstance(data, bytes):  return data.decode('ascii')
 | 
				
			||||||
    if isinstance(data, dict):   return dict(map(convert, data.items()))
 | 
					    if isinstance(data, dict):   return dict(map(convert, data.items()))
 | 
				
			||||||
    if isinstance(data, tuple):  return map(convert, data)
 | 
					    if isinstance(data, tuple):  return map(convert, data)
 | 
				
			||||||
    json_data = json.dumps(data)
 | 
					    json_data = json.dumps(data)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user