"Run At Completion" plugin - need help

Suggest, post, or discuss plugins for Deluge
Post Reply
Shishakli
New User
New User
Posts: 7
Joined: Tue Aug 05, 2008 3:13 pm

"Run At Completion" plugin - need help

Post by Shishakli »

Heya,

Abstract: I want to create (or have created) a plugin that lets you have commands set to run when a torrent completes. More specifically, I would like to be able to have a script or process run against a particular file in the torrent.

Where I'm at: I've had a look at the existing plugins and I'm pretty impressed with how powerful there are. I'm caught halfway between learning the plugin system and leveraging off existing plugins. As an example of the latter, I've been looking at the output of the "event logging" plugin, and having a shell script keep an eye on that output. When the output announces a torrent completion, I have the script act on the information in the log file. It's an ugly way to do things and the results wouldn't help anyone but myself. If I could create a user friendly plugin, that would be something else entirely.

Looking into the existing plugins I can see how the plugins make good use of the deluge classes. At the moment I'm having trouble learning the extent of the deluge classes and what information is available to the plugin system.

An obvious use for this plugin would be to have e-mails sent upon completion. "At completion run e-mail script". Another would be to move upon completion. Another would be to "unrar" upon completion. Another which I've had cause to do in the past is a script to copy a completed torrent to another directory, and rehash for seeding to another tracker.

Anyway... if anyone thinks they can help, please do as I have bugger all knowledge of the plugin system and I'm working from scratch, and as I come up with stuff that might be helpful to others I'll post here.

Cheers
Shishakli
New User
New User
Posts: 7
Joined: Tue Aug 05, 2008 3:13 pm

Re: "Run At Completion" plugin - need help

Post by Shishakli »

Well this is a good start.... The *.glade files are created by http://glade.gnome.org/

So with that in mind, I'm hijacking the torrent creator plugin and seeing what I can manipulate and make sense of.

Just a matter of copying the TorrentCreator/ into /home/user/.config/deluge/plugins and renaming any reference to TorrentCreator (I hope)
Shishakli
New User
New User
Posts: 7
Joined: Tue Aug 05, 2008 3:13 pm

Re: "Run At Completion" plugin - need help

Post by Shishakli »

Okay this is stumping me.... Can anyone tell me where FilesTabManager is defined?

as in

from TorrentFiles.tab_files import FilesTabManager
johnnyg
Top Bloke
Top Bloke
Posts: 1522
Joined: Sun Oct 28, 2007 4:00 am
Location: Sydney, Australia

Re: "Run At Completion" plugin - need help

Post by johnnyg »

Shishakli wrote:As an example of the latter, I've been looking at the output of the "event logging" plugin, and having a shell script keep an eye on that output. When the output announces a torrent completion, I have the script act on the information in the log file. It's an ugly way to do things and the results wouldn't help anyone but myself.
that is a very ugly way of doing things - seeing you can't guarantee that they'll have event logging plugin enabled (or that it's outputting to a file).
if you actually look inside the event login plugin you'll see that it uses events to print different messages, it would be smarter to use those events to determine when a torrent finishes and act upon it.

I should point out that 0.5 has pretty much reached the end of the line.
It would be much better to write this plugin for 0.6 (which are the new 1.0RCs).
Shishakli
New User
New User
Posts: 7
Joined: Tue Aug 05, 2008 3:13 pm

Re: "Run At Completion" plugin - need help

Post by Shishakli »

johnnyg wrote:I should point out that 0.5 has pretty much reached the end of the line.
It would be much better to write this plugin for 0.6 (which are the new 1.0RCs).
I'm using the 0.5 plugins as examples to get used to the system.... Is the 0.6 very different? More importantly, are there more than the 3 plugins to use as examples?
Shishakli
New User
New User
Posts: 7
Joined: Tue Aug 05, 2008 3:13 pm

Re: "Run At Completion" plugin - need help

Post by Shishakli »

Shishakli wrote:Okay this is stumping me.... Can anyone tell me where FilesTabManager is defined?

as in

from TorrentFiles.tab_files import FilesTabManager
LOL ignore this post.... the FileTabManager class is in the tab_files.py file. Forest for the trees...
johnnyg
Top Bloke
Top Bloke
Posts: 1522
Joined: Sun Oct 28, 2007 4:00 am
Location: Sydney, Australia

Re: "Run At Completion" plugin - need help

Post by johnnyg »

Shishakli wrote:
johnnyg wrote:I should point out that 0.5 has pretty much reached the end of the line.
It would be much better to write this plugin for 0.6 (which are the new 1.0RCs).
I'm using the 0.5 plugins as examples to get used to the system.... Is the 0.6 very different? More importantly, are there more than the 3 plugins to use as examples?
I think so, to be honest I haven't really peaked inside 0.6 plugins (yet).
But I know that they are incompatible so I'd guess there's a bit of a difference.

And no, for the moment there are only 3 plugins (yours could be the fourth :P).
Shishakli
New User
New User
Posts: 7
Joined: Tue Aug 05, 2008 3:13 pm

Re: "Run At Completion" plugin - need help

Post by Shishakli »

johnnyg wrote:And no, for the moment there are only 3 plugins (yours could be the fourth :P).
LOL promises promises :mrgreen:

Good advice though.... installing the RC
mvoncken
Developer
Developer
Posts: 225
Joined: Mon Sep 03, 2007 9:38 pm

Re: "Run At Completion" plugin - need help

Post by mvoncken »

Our plugin docs are non-existent, this should get you started .
0.6 plugins are completely different from 0.5 plugins.

Start with the "Test Plugin" , no docs on the eggs yet,it's ok to start with a modified test-plugin and figure out the eggs later.

Replace testp/core.py with this:

Code: Select all

from deluge.log import LOG as log
from deluge.plugins.corepluginbase import CorePluginBase
from deluge import component
from deluge.plugins.coreclient import client
#client: see http://dev.deluge-torrent.org/wiki/Development/UiClient#Remoteapi

class Core(CorePluginBase):
    def enable(self):
        component.get("AlertManager").register_handler("torrent_finished_alert", self.on_alert_torrent_finished)

    def disable(self):
        component.get("AlertManager").deregister_handler(self.on_alert_torrent_finished)

    def on_alert_torrent_finished(self, alert):
        try:
            torrent_id = str(alert.handle.info_hash())
            data = client.get_torrent_status(torrent_id, ["name","total_size", "ratio"])
            log.debug("Your logic here :%s : %s" % (torrent_id, data))

        except Exception, e:
            log.debug("error in alert %s" % e)
coreclient was added in svn , it is not available in the RC
Drop by on IRC if you have any more questions.
dev: webui, core, labels | irc:vonck7 |
Post Reply