mirror of
https://github.com/KevinMidboe/delugeClient.git
synced 2025-12-09 04:28:42 +00:00
Changed back to rename taking name not id as input arg. Changed progress function to return a dict of torrents with only the values relevant for checking progress. This also needed the filterOnValue. Torrents toJSON function returns lowercase dict keys.
This commit is contained in:
@@ -8,7 +8,8 @@ Usage:
|
|||||||
deluge_cli get TORRENT
|
deluge_cli get TORRENT
|
||||||
deluge_cli ls [--downloading | --seeding | --paused]
|
deluge_cli ls [--downloading | --seeding | --paused]
|
||||||
deluge_cli toggle TORRENT
|
deluge_cli toggle TORRENT
|
||||||
deluge_cli rm TORRENT [--debug | --warning | --error]
|
deluge_cli progress
|
||||||
|
deluge_cli rm NAME [--debug | --warning | --error]
|
||||||
deluge_cli (-h | --help)
|
deluge_cli (-h | --help)
|
||||||
deluge_cli --version
|
deluge_cli --version
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ Options:
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import re
|
import re
|
||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
@@ -128,21 +130,46 @@ class Deluge(object):
|
|||||||
|
|
||||||
print('Response:', response)
|
print('Response:', response)
|
||||||
|
|
||||||
def remove(self, torrent_id):
|
def remove(self, name):
|
||||||
for torrent in self.get_all():
|
matches = list(filter(lambda t: t.name == name, self.get_all()))
|
||||||
if (torrent_id == torrent.key):
|
logger.info('Matches for {}: {}'.format(name, matches))
|
||||||
|
|
||||||
|
if (len(matches) > 1):
|
||||||
|
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, False)
|
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:
|
||||||
|
logger.error('ERROR. No torrent found with that name.')
|
||||||
|
|
||||||
logger.error('ERROR: No torrent found with that id.')
|
def filterOnValue(self, torrents, value):
|
||||||
|
filteredTorrents = []
|
||||||
|
value_template = {'key': None, 'name': None, value: None}
|
||||||
|
for t in torrents:
|
||||||
|
value_template['key'] = t.key
|
||||||
|
value_template['name'] = t.name
|
||||||
|
value_template[value] = getattr(t, value)
|
||||||
|
|
||||||
def status(self):
|
filteredTorrents.append(value_template)
|
||||||
response = self.client.call('core.get_torrents_status', {}, ['progress'])
|
return filteredTorrents
|
||||||
torrents = self.parseResponse(response)
|
|
||||||
|
def progress(self):
|
||||||
|
attributes = ['progress', 'eta', 'state']
|
||||||
|
all_torrents = self.get_all()
|
||||||
|
|
||||||
|
torrents = []
|
||||||
|
for i, attribute in enumerate(attributes):
|
||||||
|
if i < 1:
|
||||||
|
torrents = self.filterOnValue(all_torrents, attribute)
|
||||||
|
continue
|
||||||
|
torrents = [dict(e, **v) for e,v in zip(torrents, self.filterOnValue(all_torrents, attribute))]
|
||||||
|
|
||||||
|
return torrents
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if hasattr(self, 'tunnel'):
|
if hasattr(self, 'tunnel'):
|
||||||
@@ -174,9 +201,9 @@ class Torrent(object):
|
|||||||
d['paused'], d['is_finished'], d['files'])
|
d['paused'], d['is_finished'], d['files'])
|
||||||
|
|
||||||
def toJSON(self):
|
def toJSON(self):
|
||||||
return {'Key': self.key, 'Name': self.name, 'Progress': self.progress, 'ETA': self.eta,
|
return {'key': self.key, 'name': self.name, 'progress': self.progress, 'eta': self.eta,
|
||||||
'Save path': self.save_path, 'State': self.state, 'Paused': self.paused,
|
'save path': self.save_path, 'state': self.state, 'paused': self.paused,
|
||||||
'Finished': self.finished, 'Files': self.files, 'Packed': self.packed()}
|
'finished': self.finished, 'files': self.files, 'packed': self.packed()}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Name: {}, Progress: {}%, ETA: {}, State: {}, Paused: {}".format(
|
return "Name: {}, Progress: {}%, ETA: {}, State: {}, Paused: {}".format(
|
||||||
@@ -233,6 +260,7 @@ def main():
|
|||||||
_id = arguments['TORRENT']
|
_id = arguments['TORRENT']
|
||||||
query = arguments['NAME']
|
query = arguments['NAME']
|
||||||
magnet = arguments['MAGNET']
|
magnet = arguments['MAGNET']
|
||||||
|
name = arguments['NAME']
|
||||||
_filter = [ a[2:] for a in ['--downloading', '--seeding', '--paused'] if arguments[a] ]
|
_filter = [ a[2:] for a in ['--downloading', '--seeding', '--paused'] if arguments[a] ]
|
||||||
print(_id, query, _filter)
|
print(_id, query, _filter)
|
||||||
|
|
||||||
@@ -246,6 +274,12 @@ def main():
|
|||||||
response = deluge.search(query)
|
response = deluge.search(query)
|
||||||
[ pprint(t.toJSON()) for t in response ]
|
[ pprint(t.toJSON()) for t in response ]
|
||||||
|
|
||||||
|
elif arguments['progress']:
|
||||||
|
logger.info('Progress cmd selected.')
|
||||||
|
pprint(deluge.progress())
|
||||||
|
exit(0)
|
||||||
|
[ pprint(t.toJSON()) for t in deluge.progress() ]
|
||||||
|
|
||||||
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)
|
||||||
@@ -260,8 +294,8 @@ def main():
|
|||||||
deluge.togglePaused(_id)
|
deluge.togglePaused(_id)
|
||||||
|
|
||||||
elif arguments['rm']:
|
elif arguments['rm']:
|
||||||
logger.info('Remove id: {}'.format(_id))
|
logger.info('Remove by name: {}'.format(name))
|
||||||
deluge.remove(_id)
|
deluge.remove(name)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user