Python: How to implement get_torrents_status?

Suggestions and discussion of future versions
Posts: 16
Joined: Wed May 09, 2012 1:32 pm

Python: How to implement get_torrents_status?

Postby ratzeputz » Mon Oct 22, 2012 4:41 pm


i am just about to create a python script which periodically checks for dead torrents, as it happens sometimes that I get dead torrents of rss feeds (usually tv show premieres). Those are choking the download queue :/. I managed to get torrent status items by using

Code: Select all


for example.

How can i get the amount of data downloaded of a specific torrent? In the Copy Limit Plugin there is an implementation of the functionality i want(get_torrents_status), how can i port this to a python script (not a deluge plugin)?


Code: Select all

# Copyright (C) 2009 Florentino Sainz (BlackIceSpain) <>
# Basic plugin template created by:
# Copyright (C) 2008 Martijn Voncken <>
# Copyright (C) 2007-2009 Andrew Resch <>
# Copyright (C) 2009 Damien Churchill <>
# Deluge is free software.
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
# deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with deluge.    If not, write to:
#   The Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor
#   Boston, MA  02110-1301, USA.
#    In addition, as a special exception, the copyright holders give
#    permission to link the code of portions of this program with the OpenSSL
#    library.
#    You must obey the GNU General Public License in all respects for all of
#    the code used other than OpenSSL. If you modify file(s) with this
#    exception, you may extend this exception to your version of the file(s),
#    but you are not obligated to do so. If you do not wish to do so, delete
#    this exception statement from your version. If you delete this exception
#    statement from all source files in the program, then also delete it here.

from deluge.log import LOG as log
from deluge.plugins.pluginbase import CorePluginBase
import deluge.component as component
import deluge.configmanager
from deluge.core.rpcserver import export
from twisted.internet.task import LoopingCall


class Core(CorePluginBase):
    def enable(self):
        self.config = deluge.configmanager.ConfigManager("copylimit.conf", DEFAULT_PREFS)
        self.core = component.get("Core")
        self.ratio = self.config["LIM_COPIAS"]
        self.tamano = self.config["MIN_SIZE"]
        self.upload = self.config["UPLOAD_RATE"]
        self.tamanoReal = self.tamano * 1024 *1024
        self.update_status_timer = LoopingCall(self.trabaja)
    def disable(self):

    def update(self):

    def trabaja(self):
     [b]   torrents = self.core.get_torrents_status({"state":"Downloading"}, ["name", "total_size", "total_uploaded"]).items()           
        for torrent_id, torrent in torrents:[/b]
                uploaded = torrent["total_uploaded"]
                tamano_total= torrent["total_size"]
                if ((self.ratio * tamano_total) < uploaded) & (tamano_total > self.tamanoReal):

    def set_config(self, config):
        """Sets the config dictionary"""
        for key in config.keys():
            self.config[key] = config[key]           
        self.ratio = self.config["LIM_COPIAS"]
        self.tamano = self.config["MIN_SIZE"]
        self.upload = self.config["UPLOAD_RATE"]
        self.tamanoReal = self.tamano * 1024 *1024

    def get_config(self):
        """Returns the config dictionary"""
        return self.config.config

I wasn't able to implement it. So far my considerations for dead torrents are:

Code: Select all

         for torrent_id, status in torrents.items():
   # delete torrent if it is somewhere in path and has 0 seeds and this after beeing added over 5 hours ago; 18000s = 5h
        if torrentdir in  status["save_path"] and \
      status["total_seeds"] < 1 and \
      not status["is_finished"] and \
           status["active_time"] > 18000 :            
       global do_remove_data
            successmsg = " Removed: %s from %s because recognized as dead" % (status["name"], status["save_path"])
            errormsg = "Error removing %s" % (status["name"])
#            tlist.append(client.core.remove_torrent(torrent_id, do_remove_data).addCallbacks(printSuccess, printError, callbackArgs = (True, successmsg), errbackArgs = (errormsg)))
            printSuccess(None, False, " Skipping: %s from %s" % (status["name"], status["save_path"]))

Do you have some additional information what could be used to determine if a torrent is dead or not?

Thanks in advance,

Top Bloke
Top Bloke
Posts: 3577
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Python: How to implement get_torrents_status?

Postby Cas » Mon Oct 22, 2012 5:16 pm

Return to “Development”

Who is online

Users browsing this forum: No registered users and 1 guest