Script to unpause torrent after X seconds and then recheck (Execute Plugin)?

General support for problems installing or using Deluge
Post Reply
Formula Juan
Member
Member
Posts: 12
Joined: Mon Oct 28, 2019 6:53 pm

Script to unpause torrent after X seconds and then recheck (Execute Plugin)?

Post by Formula Juan »

Long story short, the way I have my torrents automated using the YaRRS2 and LabelPlus Plugins means that I have a problem with torrents being added by YaRRS2 to a default download location, and then moved to a location as dictated my my labels and sub-labels. As the torrents in question or periodically updated (have files added to them but still use the same torrent name), this results in torrents not being rechecked as the torrent is added to one empty directory by YaRSS2 before being moved to a populated directory by LabelPlus.

I could fix the issue by using separate YaRRS2 feeds for each event / series of torrents but that would be a lot of working. So I wa hoping there was a way I could automate the process using a shell script.

I was thinking I could use the Execute Plugin to run a Bash script when a new torrent is added. I've tried

Code: Select all

/usr/bin/deluge-console "recheck $1"
when a torrent is added but it doesn't appear to work... I'm guessing because if it's being triggered, it's being triggered when the torrent is in the empty folder, before LabelPlus moves it. So what I'm think is perhaps there needs to be some kind of delay before the command is run in order to account for LabelPlus doing it's thing.

Being a novice script writer, I'm think what needs to be done by the script is-

1. Set the global default to add torrents in a paused state.
2. When a new torrent is added, wait X number of seconds in order to give LabelPlus time to finish.
3. Recheck the newly added torrent.
4. Unnpause torrent when recheck is complete.

I can set non-LabelPlus labels (deluge's default labels) using the YaRSS2 plugin. So would it be possible for the script to only force recheck torrents that match a given label (or even LabelPlus label)? That way, if a torrent doesn't match the given label, it could be unpaused immediately.

Any help in writing a script to automate the process I've described would be greatly appreciated.
Formula Juan
Member
Member
Posts: 12
Joined: Mon Oct 28, 2019 6:53 pm

Re: Script to unpause torrent after X seconds and then recheck (Execute Plugin)?

Post by Formula Juan »

[EDIT 2] The script below does not work but I'm going to leave it up in the hopes that it might prove educcationaal for fellow script noobs like myself.

-----------------------------------------------------------

Here's the script I've created. I use the Execute plugin to run it when a torrent is added. I should make it clear that I am a noob at writing scripts and the following script is not tested yet.

Code: Select all

#!/bin/bash

#variables
torrentid=$1
torrentname=$2
torrentpath=$3

sleep 30 #sleep so that LabelPlus can do it's stuff
recheck $1
echo  "Torrent Details: " "$torrentname" "$torrentpath" "$torrentid"  >> /home/deluge/.config/deluge/Scripts/execute_script.log
resume $1
There are a number of things I want to change or added. From relatively minor things like wanting to fine tune how long the sleep period is (I'm not sure how quickly LabelPlus works). The other main feature I want to implement is some kind of if then argument that either runs to the recheck or skips it and goes straight to the resume depending on whether the torrent in question matches a given string... I'd really like that string to be either it's Label or LabelPlus label but I'm not sure that's possible, so I might just have to settle for the torrent name.

[EDIT] It's a good job I did post the script as it made me spot a typo.
Formula Juan
Member
Member
Posts: 12
Joined: Mon Oct 28, 2019 6:53 pm

Re: Script to unpause torrent after X seconds and then recheck (Execute Plugin)?

Post by Formula Juan »

After some bashing around, I've got the script working!

Here are the details of my setup.

0. Deluge's global setting is to add torrents in an unpaused state.
1. The torrents are added automatically by YaRSS2. The YaRSS2 feed is set to add torrents in a paused state.
2. The newly added torrent has a label and it's download location set according the the various Laabel and Sub-Label settings in my LabelPlus settings.
3. The Execute plugin is set to run a script when a new torrent is added. My deluged is run by a dedicated "deluge" user. The script itself and it's associated log file are located in a path that is accessible by the "deluge" user. For the time being, I have set the script's permissions as 777.

Code: Select all

#!/bin/bash

#variables
torrentid=$1
torrentname=$2
torrentpath=$3

sleep 5 #sleep so that LabelPlus can do it's stuff
deluge-console "recheck [ * |  $torrentid [$torrentid ...] ]"
echo  "Torrent Details: " "$torrentname" "$torrentpath" "$torrentid"  >> /home/deluge/media/execute_script.log
deluge-console "resume [ * |  $torrentid [$torrentid ...] ]"
I have successfully ran the script!... but use it at your own risk.
Post Reply