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
|
||||||
|
|||||||
@@ -31,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
|
||||||
@@ -42,7 +43,7 @@ from pprint import pprint
|
|||||||
from deluge_client import DelugeRPCClient
|
from deluge_client import DelugeRPCClient
|
||||||
from sshtunnel import SSHTunnelForwarder
|
from sshtunnel import SSHTunnelForwarder
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
from .utils import ColorizeFilter, convert
|
from utils import ColorizeFilter, convert
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
@@ -95,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()
|
||||||
@@ -109,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()
|
||||||
@@ -148,7 +154,7 @@ 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):
|
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()))
|
||||||
@@ -163,6 +169,7 @@ class Deluge(object):
|
|||||||
|
|
||||||
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.')
|
||||||
@@ -239,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']:
|
||||||
@@ -272,34 +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']:
|
||||||
logger.info('Remove by name: {}'.format(name))
|
logger.info('Remove by name: {}'.format(name))
|
||||||
deluge.remove(name)
|
response = deluge.remove(name)
|
||||||
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user