Skip to content

BackSlasher/deluge_framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

deluge_framework

http://blog.oneboredadmin.com/2014/04/python-library-for-deluge-torrent.html
A framework for manipulating deluge remotely

QuickStart

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.

Examples

Display all torrents containing "linux" in the title

#!/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.

Print progress and state for all torrents

#!/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.

Summing the size of all torrents

#!/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

Removing all done torrents

#!/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.

Parameters for filter_torrents

connection_data

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 to localhost
  • port: Port of the deluge daemon. Defaults to 58846
  • username: Username to connect to the deluge daemon. Not needed if running locally on the same user.
  • password: Complementing username

info_wanted

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

action

Callback for your function. Defaults to listing all torrents

interactive

A boolean, indicating whether to print information to stdout. Defaults to true, can be disabled for cronjobs.

About

A framework for manipulating deluge remotely

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages