http://blog.oneboredadmin.com/2014/04/python-library-for-deluge-torrent.html
A framework for manipulating deluge remotely
Import the module using python, create a function with that looks like torrentAction(torrent_id,torrent_info)
(name can differ) that returns one of the following values:
- (empty string) to ignore torrent
- d to delete torrent without downloaded files
- D to delete torrent with downloaded files
- l to list torrent (display in output)
You can also do other stuff inside the function (caclulate sum, measure title length, etc).
Function arguments are:
- torrent_id as the torrent id (a unique hash)
- torrent_info as a dictionary containing the torrent's information
Call the function deluge_framework.filter_torrents
with connection data, a collection of wanted fields and a callback for the function defined earlier.
#!/usr/bin/python
from deluge_framework import filter_torrents
def torrentAction(torrent_id,torrent_info):
if 'linux' in torrent_info['name']: return 'l'
return ''
filter_torrents({},['name'],torrentAction)
output:
[+] Connection was successful!
[i] ?????????SECRET????????????????????????? [kali-linux-1.0.5-amd64]: Listing (doing nothing)
[+] Finished
[i] Client disconnected.
#!/usr/bin/python
from deluge_framework import filter_torrents
def torrentAction(torrent_id,torrent_info):
print ('%s: %s %s' % (torrent_id,torrent_info['state'],torrent_info['progress']))
return ''
filter_torrents({},['name','state','progress'],torrentAction)
output:
[+] Connection was successful!
?????????SECRET?????????????????????????: Queued 100.0
?????????SECRET?????????????????????????: Queued 100.0
?????????SECRET?????????????????????????: Seeding 100.0
?????????SECRET?????????????????????????: Queued 100.0
?????????SECRET?????????????????????????: Queued 100.0
?????????SECRET?????????????????????????: Seeding 100.0
?????????SECRET?????????????????????????: Queued 100.0
?????????SECRET?????????????????????????: Queued 100.0
?????????SECRET?????????????????????????: Queued 100.0
[+] Finished
[i] Client disconnected.
#!/usr/bin/python
from deluge_framework import filter_torrents
sum=0
def torrentAction(torrent_id,torrent_info):
global sum
sum+=torrent_info['total_done']
return ''
filter_torrents({},['total_done'],torrentAction)
print ('total: %i' % (sum/1024/1024/1024))
output:
[+] Connection was successful!
[+] Finished
[i] Client disconnected.
total: 198
#!/usr/bin/python
from deluge_framework import filter_torrents
def torrentAction(torrent_id,torrent_info):
if torrent_info['progress'] == 100: return 'd'
return ''
filter_torrents({},['progress'],torrentAction)
output:
[+] Connection was successful!
[+] ?????????SECRET????????????????????????? [SOME TORRENT NAME]: Deleted without data
[+] ?????????SECRET????????????????????????? [SOME TORRENT NAME]: Deleted without data
[+] ?????????SECRET????????????????????????? [SOME TORRENT NAME]: Deleted without data
[+] Finished
[i] Client disconnected.
A dictionary of paramters defining how to connect to the deluge daemon. Unspecified keys get default value. Possible keys:
host
: Name / IP of the machine running the deluge daemon. Defaults tolocalhost
port
: Port of the deluge daemon. Defaults to58846
username
: Username to connect to the deluge daemon. Not needed if running locally on the same user.password
: Complementingusername
An array of fields to return for every torrent. Possible values:
"state", "save_path", "tracker", "next_announce", "name", "total_size", "progress", "num_seeds", "total_seeds", "num_peers", "total_peers", "eta", "download_payload_rate", "upload_payload_rate", "ratio", "distributed_copies", "num_pieces", "piece_length", "piece_info", "total_done", "files"
Defaults to nothing
Callback for your function. Defaults to listing all torrents
A boolean, indicating whether to print information to stdout. Defaults to true
, can be disabled for cronjobs.