Page 1 of 3

AddTorrentCheck

Posted: Sat Jul 22, 2017 10:36 am
by Kaavi
I made this through cut'n'paste and hack'n'slash - so this is not very pretty code im sure.

What it does is that it keeps updating the tracker until tracker status is "OK", it as some of the trackers im on returns "Error: unregistered torrent" when adding it fast with autodl-irssi.

It works for 1.3.x - it doesn't work for 2.0, as "component.get('TorrentManager').session_started:" gives an error. Not sure why and not going to spend time making it.

So if anyone want to make a plugin based on the ideas on this feel free - im not going to do anytihng with it myself. :)

Code: Select all

#
# core.py
#
# Basic plugin template created by:
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
# Copyright (C) 2009 Damien Churchill <damoxc@gmail.com>
#
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# 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.
#

import time
import logging
from twisted.internet.task import LoopingCall

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 deluge.ui.client import client

DEFAULT_PREFS = {
    "test":"NiNiNi"
}

class Core(CorePluginBase):

    timer = {}

    def update_tracker(self, torrent_id):
        tid = component.get('TorrentManager').torrents[torrent_id]
        tid_status = tid.get_status(['tracker_status','time_added'])
        log.info("[AddTrackerCheck](%s)(%s) : %s", torrent_id, time.time() - tid_status['time_added'], tid_status['tracker_status'])

        if tid_status['tracker_status'].find("Announce OK") != -1:
            Core.timer[torrent_id].stop();
        elif time.time() - tid_status['time_added'] > 300:
            Core.timer[torrent_id].stop();
        else:
            log.info("[AddTrackerCheck](%s) : Updating Tracker", torrent_id)
            tid.force_reannounce();
			
    def post_torrent_add(self, torrent_id, *from_state):
        if not component.get('TorrentManager').session_started:
            return
        log.info("[AddTrackerCheck](%s) : Adding New Torrent", torrent_id)
        Core.timer[torrent_id] = LoopingCall(self.update_tracker, torrent_id)
        Core.timer[torrent_id].start(2)

    def enable(self):
        # Go through the commands list and register event handlers
        self.config = deluge.configmanager.ConfigManager("addtorrentcheck.conf", DEFAULT_PREFS)
        component.get("EventManager").register_event_handler("TorrentAddedEvent", self.post_torrent_add)

    def disable(self):
        pass

    def update(self):
        pass

    @export
    def set_config(self, config):
        """Sets the config dictionary"""
        for key in config.keys():
            self.config[key] = config[key]
        self.config.save()

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

Re: AddTorrentCheck

Posted: Thu Nov 02, 2017 3:52 pm
by batezy
Hey, nice job on this! This is similar to a script I've been using someone else made. Check this link. https://pastebin.com/0wDib1dg

I wanted to ask you a question. Now I too had the unregistered torrent problem. I'm also encountering a secondary issue. Sometimes I will have torrents sit at 0% when there are no seeders or peers yet. Sometimes torrents can get stuck like this, or I end up very late in the swarm. Do you know if there is a way to add to your plugin or the script I posted to refresh the torrent every couple seconds until it gets a connection to download? I'm trying to boost ratio and this would help a whole lot! Maybe your on IRC and we could chat? Thanks alot!

Re: AddTorrentCheck

Posted: Thu Mar 15, 2018 2:59 pm
by greatscott
batezy wrote:Hey, nice job on this! This is similar to a script I've been using someone else made. Check this link. https://pastebin.com/0wDib1dg

I wanted to ask you a question. Now I too had the unregistered torrent problem. I'm also encountering a secondary issue. Sometimes I will have torrents sit at 0% when there are no seeders or peers yet. Sometimes torrents can get stuck like this, or I end up very late in the swarm. Do you know if there is a way to add to your plugin or the script I posted to refresh the torrent every couple seconds until it gets a connection to download? I'm trying to boost ratio and this would help a whole lot! Maybe your on IRC and we could chat? Thanks alot!
IIRC someone used pause/start torrent method to get around this issue:
https://www.reddit.com/r/seedboxes/comm ... ent_issue/

I haven't tried it myself though as I haven't autodl on those trackers that have the problem for a while.

Re: AddTorrentCheck

Posted: Sat Jul 27, 2019 3:05 pm
by idiocracy
There can be legit reason why a tracker would error, like "torrent already exist". Changing the search terms seems like a better option. I don't know python but i gave it a shot, i only changed the if, elif and else lines. I don't know how fast/often it runs, so i added a 10 second sleep. Maybe someone could take a quick look and provide some feedback.
Also, i don't have a system i can build a plugin on so if you're able to help with that as well it would be much appreciated.

Code: Select all

#
# core.py
#
# Basic plugin template created by:
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
# Copyright (C) 2009 Damien Churchill <damoxc@gmail.com>
#
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# 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.
#

import time
import logging
from twisted.internet.task import LoopingCall

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 deluge.ui.client import client

DEFAULT_PREFS = {
    "test":"NiNiNi"
}

class Core(CorePluginBase):

    timer = {}

    def update_tracker(self, torrent_id):
        tid = component.get('TorrentManager').torrents[torrent_id]
        tid_status = tid.get_status(['tracker_status','time_added'])
        log.info("[AddTrackerCheck](%s)(%s) : %s", torrent_id, time.time() - tid_status['time_added'], tid_status['tracker_status'])

        if tid_status['tracker_status'].find("*unregistered*", "*Sent*", "*End*of*file*", "*Bad*Gateway*") != -1:
            log.info("[AddTrackerCheck](%s) : Updating Tracker", torrent_id)
            time.sleep(10)
            tid.force_reannounce();
        elif time.time() - tid_status['time_added'] > 120:
            Core.timer[torrent_id].stop();
        else:
            Core.timer[torrent_id].stop();
         
    def post_torrent_add(self, torrent_id, *from_state):
        if not component.get('TorrentManager').session_started:
            return
        log.info("[AddTrackerCheck](%s) : Adding New Torrent", torrent_id)
        Core.timer[torrent_id] = LoopingCall(self.update_tracker, torrent_id)
        Core.timer[torrent_id].start(2)

    def enable(self):
        # Go through the commands list and register event handlers
        self.config = deluge.configmanager.ConfigManager("addtorrentcheck.conf", DEFAULT_PREFS)
        component.get("EventManager").register_event_handler("TorrentAddedEvent", self.post_torrent_add)

    def disable(self):
        pass

    def update(self):
        pass

    @export
    def set_config(self, config):
        """Sets the config dictionary"""
        for key in config.keys():
            self.config[key] = config[key]
        self.config.save()

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

Re: AddTorrentCheck

Posted: Sat Jul 27, 2019 7:32 pm
by mhertz
Nice work fellas :)

Anyway just wanted to also make aware of the libtorrent option 'tracker_backoff' which controls how aggressively to retry failing trackers. It's by default little under 5 minutes but can be lowered to whatever and was implemented after a request by an autodl-irssi user. Ltconfig plugin works to define this option and for deluge v2 then you can use JoshDi's fork posted in the plugin thread here.

Re: AddTorrentCheck

Posted: Sat Jul 27, 2019 8:59 pm
by idiocracy
mhertz wrote:Nice work fellas :)

Anyway just wanted to also make aware of the libtorrent option 'tracker_backoff' which controls how aggressively to retry failing trackers. It's by default little under 5 minutes but can be lowered to whatever and was implemented after a request by an autodl-irssi user. Ltconfig plugin works to define this option and for deluge v2 then you can use JoshDi's fork posted in the plugin thread here.
That won't work as "tracker_backoff" is for "failure reason". "unregistered torrent" is a "warning message" and happens on trackers that are fully functional and responding, it's therefore not considered a tracker failure and "tracker_backoff" will not initiate.

That is why i'm trying to make this work as it would make life easier for everyone on every platform, just install plugin and done. But i lack the skills to do so.

Re: AddTorrentCheck

Posted: Sat Jul 27, 2019 9:48 pm
by mhertz
I apologize for posting wrong information and thanks for the correction. Unfortunately I also lack the necessary skills.

Re: AddTorrentCheck

Posted: Sat Jul 27, 2019 10:05 pm
by idiocracy
mhertz wrote:I apologize for posting wrong information and thanks for the correction. Unfortunately I also lack the necessary skills.
No worries.

Re: AddTorrentCheck

Posted: Sun Jul 28, 2019 8:45 am
by idiocracy
I tried building it, but have 0 clue if it's going to work. I changed the search term because i don't know if separators are allowed.

Code: Select all

        if tid_status['tracker_status'].find("*unregistered*") != -1:
            log.info("[AddTrackerCheck](%s) : Updating Tracker", torrent_id)
            time.sleep(10)
            tid.force_reannounce();
        elif time.time() - tid_status['time_added'] > 120:
            Core.timer[torrent_id].stop();
        else:
            Core.timer[torrent_id].stop();
Guess i'll just have to wait and see.

Re: AddTorrentCheck

Posted: Sun Jul 28, 2019 5:32 pm
by idiocracy
Well, that didn't work. Maybe wildcards aren't allowed in the find, so trying without those. I'm unsure if you need to restart deluge when you overwrite plugin, or if it's enough to just disable it, install new and overwrite and re-enable the plugin.