Autoadd peer using Execute plugin

Specific support for Deluge on Microsoft Windows OS
Post Reply
showstoppre
New User
New User
Posts: 7
Joined: Mon Apr 26, 2021 6:25 am

Autoadd peer using Execute plugin

Post by showstoppre »

I'm pretty new to Deluge. Exploring features.

I'm trying to automatically add a common peer across all torrents upon adding the torrent. I did some search and came across Execute plugin. I enabled Execute plugin, then restarted it and inputed the below command.

Event: Torrent Added
client.core.connect_peer(torrent_id, 3.1.1.1, 11592)

Am I missing something here as it doesn't seem to add the peer. I'm not sure what I need to input under torrent_id. So I left it as it is. Ideally I'm looking for adding the same peer to all torrents. FYI, I'm referencing a sample IP here not the real one I used.

I'm using Windows latest official deluge build.

Any help would be appreciated
mhertz
Moderator
Moderator
Posts: 2182
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Autoadd peer using Execute plugin

Post by mhertz »

The execute plugin runs commands that is executable on your system from a terminal/cmd-prompt, usually batch-files on windows. That functionality you're after could be made with a little homemade plugin, but easier from execute plugin as you stated, since already hooks into torrent_added_event and no boilerplate-code needed, so add a python filename/path instead, and the file of-course too, but python file needs be able to run on your system(associated) or else add batch-file calling said python file. You still need add initial deluge imports and initializations, and sorry I have no experience with this function you're after, only very basic stuff made myself, and only used deluge.core parts like getting torrent_status and running event based on that etc, and that call seemingly is part of RPC-API the docs state, and I saw very old example, propperly not working anymore as 10 years old, using I think deffereds from twisted for it(addcallback I believe, or something), which I'm also not gotten to learn myself yet, though not very difficult I'm guessing from looking at others plugins.
showstoppre
New User
New User
Posts: 7
Joined: Mon Apr 26, 2021 6:25 am

Re: Autoadd peer using Execute plugin

Post by showstoppre »

Thanks for pointing me in right direction.

I've just picked up Python. Hopefully I'll write the script one day.
mhertz
Moderator
Moderator
Posts: 2182
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Autoadd peer using Execute plugin

Post by mhertz »

You're very welcome :) BTW, here's the link for old script I mentioned to maybe get inspiration from, though keep in mind it's 10 years old, so probably need little changing for certain points for working with current API unless lucky, and you can too cut all the error checking out if wanted and hardcode IP/port etc, so final version only few lines and much smaller:

https://www.google.com/url?sa=t&source= ... 9434655145

You can try running it by itself while having deluge running and check with one of the torrent's torrent-id and make changes and retest untill works and then add to execute plugin afterwards while changing torrent-id to hardcoded %1 I believe, or rather sys.argv something I guess, as execute plugin executes your defined script with 3 paramers after like stated in docs, where first parameter is current torrent's torrent-id. Hmm maybe you can just use torrent_ID when importing deluge, now I'm becoming in doubt honestly, never tried with scripts and only tried with a few plugins, so need play with it yourself and find out.

Also, docs for execute plugin, while add it:

https://www.google.com/url?sa=t&source= ... 3bdeGIrh4q

Edit: Note there's an issue with add_peer in latest stable deluge, though fixed in dev-branch: https://dev.deluge-torrent.org/ticket/3348#comment:1

Edit2: Sorry, you're on deluge 1.3.x which I forgot, which hopefully isn't affected.
mhertz
Moderator
Moderator
Posts: 2182
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Autoadd peer using Execute plugin

Post by mhertz »

I didn't test on deluge 1.x, but tried from previously posted old script example, to quickly threw together deluge2 working execute python script, which works for me in deluge2 on linux, if running in thinclient mode, either daemon alone or in GTK or web UI, but not in classic mode. Log stated the defined IP was added. I know not your setup, but just for inspiration.

Code: Select all

#!/bin/python

import sys
from deluge.ui.client import client
from twisted.internet import reactor

d = client.connect()
 
def on_connect_success(self):
    def on_connect_peer(self):
        client.disconnect()
        reactor.stop()
   
    client.core.connect_peer(sys.argv[1],"1.1.1.1","6466").addCallback(on_connect_peer)
 
d.addCallback(on_connect_success)
 
reactor.run()
Also, when on windows and not having installed from source then you need add script to deluge app dir itself(since else deluge's modules cannot be found/imported - python supports relative lookups, so looks downwards the path from where executed, hence needs relocation close to source in specific dir - didn't knew before, sorry - note, this is only like this because importing deluge/twisted, as else wouldn't be an issue and could have script wherever and use py3 if wanted etc), I believe it's under a folder in program dir named deluge something and ending in .egg. Then you also need have same python version installed as the one deluge uses internally i.e. py2.6 or py2.7 for deluge1. Easier would be make a plugin in that situation imho.

Edit: viewtopic.php?f=9&t=55936
Post Reply