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]
|
||||
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
|
||||
|
||||
@@ -9,7 +9,7 @@ Usage:
|
||||
deluge_cli ls [--downloading | --seeding | --paused]
|
||||
deluge_cli toggle TORRENT
|
||||
deluge_cli progress
|
||||
deluge_cli rm NAME [--destroy | --debug | --warning | --error]
|
||||
deluge_cli rm NAME [--debug | --warning | --error]
|
||||
deluge_cli (-h | --help)
|
||||
deluge_cli --version
|
||||
|
||||
@@ -24,7 +24,6 @@ Options:
|
||||
--debug Print all debug log
|
||||
--warning Print only logged warnings
|
||||
--error Print error messages (Error/Warning)
|
||||
--destroy When removing choose to remove file on disk
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -32,6 +31,7 @@ import os
|
||||
import sys
|
||||
import re
|
||||
import signal
|
||||
import json
|
||||
import socket
|
||||
import logging
|
||||
import logging.config
|
||||
@@ -96,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()
|
||||
@@ -110,8 +111,12 @@ class Deluge(object):
|
||||
def _connect(self):
|
||||
logger.info('Checking if script on same server as deluge RPC')
|
||||
if (socket.gethostbyname(socket.gethostname()) != self.host):
|
||||
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))
|
||||
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()
|
||||
|
||||
self.client = DelugeRPCClient(self.host, self.port, self.user, self.password)
|
||||
@@ -149,9 +154,9 @@ class Deluge(object):
|
||||
else:
|
||||
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()))
|
||||
logger.info('Matches for {}: {}'.format(name, matches))
|
||||
|
||||
@@ -159,11 +164,12 @@ class Deluge(object):
|
||||
raise ValueError('Multiple files found matching key. Unable to remove.')
|
||||
elif (len(matches) == 1):
|
||||
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)))
|
||||
|
||||
if (response == False):
|
||||
raise AttributeError('Unable to remove torrent.')
|
||||
|
||||
return response
|
||||
else:
|
||||
logger.error('ERROR. No torrent found with that name.')
|
||||
@@ -240,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']:
|
||||
@@ -273,35 +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']:
|
||||
destroy = arguments['--destroy']
|
||||
logger.info('Remove by name: {}. Destroy files: {}'.format(name, destroy))
|
||||
deluge.remove(name, destroy)
|
||||
logger.info('Remove by name: {}'.format(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()
|
||||
|
||||
@@ -6,6 +6,7 @@ cryptography==2.3
|
||||
deluge-client==1.6.0
|
||||
docopt==0.6.2
|
||||
idna==2.7
|
||||
paramiko==2.4.1
|
||||
pyasn1==0.4.4
|
||||
pycparser==2.18
|
||||
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
|
||||
|
||||
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, tuple): return map(convert, data)
|
||||
json_data = json.dumps(data)
|
||||
|
||||
Reference in New Issue
Block a user