Post your execute plugin scripts!

Suggest, post, or discuss plugins for Deluge
FrankBlack
New User
New User
Posts: 9
Joined: Wed Jul 03, 2013 11:18 am

Re: Post your execute plugin scripts!

Post by FrankBlack »

jkaberg wrote:https://github.com/clinton-hall/nzbToMedia (written in python, should be compatible with windows and unix)

nzbToMedia orginated as a usual postprocess plugin for Sick-Beard but grow, now we try to support usenet and torrents with a "universal" solution

The program provides extraction and hardlinking support for torrents, aswell as calling CouchPotatoServer or Sick-Beard for post-processing

Feel free to help us out, its a dirty code but working most of the time :)
Seems like these scripts do a lot of stuff, how exactly should we use it in deluge?
Orrly
New User
New User
Posts: 4
Joined: Thu May 30, 2013 1:59 am

Re: Post your execute plugin scripts!

Post by Orrly »

This script should
1. create a directory from the torrent name in a "done" folder
2. makes a $torrentname.desktop file providing a symbol in the /done/$torrentname folder which you can click to open the website where you downloaded the file
3. if the torrent is a folder, it moves the torrentfiles to the folder made in step 1 and deletes the remaining empty folder
4. if not (torrent is a file), it copies the file in the done/$torrentname folder
5. ?????
6. Profit!!!!!!!!!!!!!!!!1111!

As some torrent names are awfully long, the script just takes the first 15 chars and discards the rest. If you don't like that just change tname15 to torrentname
Edited (new version!!)

Code: Select all

#!/bin/bash

# Script that starts when the torrent is finished.
# It copies the dl-files to the done/$tname15 folder
torrentid=$1
torrentname=$2
torrentpath=$3

# Be flexible - - shorten long silly torrentnames and provide variables
tname="${torrentname%.*}"
tname15="${tname:0:15}"

# Set working dir
# cd "~/downloads/torrents/"

# creating directory from torrent name
mkdir -p "/home/derp/downloads/torrents/done/$tname15"

# making .desktop file with a link to the dl site
echo -e "[Desktop Entry]\nVersion=1.0\nType=Link\nURL=http://mybelovedtorrentsite/search/?hash=$torrentid#results" > "/home/derp/downloads/torrents/done/$tname15/$tname15.desktop"

# If folder .part/$torrentname exists mv .part/$torrentname/* to done/$tname15; delete .part/$torrentname else move .part/$torrentname to done/$tname15 fi
if [ -d "/home/derp/downloads/torrents/.part/$torrentname" ]; then

    mv "/home/derp/downloads/torrents/.part/$torrentname/*" "/home/derp/downloads/torrents/done/$tname15"
    wait mv
    rmdir "/home/derp/downloads/torrents/.part/$torrentname"

else

mv "/home/derp/downloads/torrents/.part/$torrentname" "/home/derp/downloads/torrents/done/$tname15"
wait mv

fi
Let it execute it after a dl is done. The only problem may be that you can't force re-check the torrent. If anyone has a solution, integrated in Deluge, that would be great!

It works now, have fun with it :mrgreen:

Edit once again!
(as of 2013-09-04)
This is the script I use now. It works well for one site (can I mention it?) but you can easily change it :D The script lives in my ~/downloads/torrents/.scripts folder but can be placed somewhere else because the paths are absolute.

Code: Select all

#!/bin/bash

# Description: The script starts when a torrent is finished.
# It makes a folder named after the torrent. It then copies
# the files to the folder and creates a desktop link which
# points to the torrent on the torrentsite.

# Get the variables from Deluge:
torrentid=$1
torrentname=$2
torrentpath=$3

# Shortening long silly torrent names and provide variables for later use
tname="${torrentname%.*}"
tname25="${tname:0:25}"

# Set working dir ## does not work, using absolute pathnames -.-
# cd "~/downloads/torrents/"

# creating directory from torrent name
mkdir -p "/home/derp/downloads/torrents/done/$tname25"

# Fetching the the link ... 
hashlink="$(echo "http://some-torrent-site.ws/advanced_search/?hash=$torrentid")"

link2="$( lynx -source $hashlink | grep -o 'class="icon" />&nbsp;<a href=".*\Wtorrent' | grep -Po 'href="\K.*?(?=")' )"

# Making the .desktop file as a link to the dl-site
echo -e "[Desktop Entry]\nVersion=1.0\nType=Link\nURL=http://some-torrent-site.ws""$link2" > "/home/derp/downloads/torrents/done/$tname25/link2_$tname25.desktop"

# Moving the files in the folder created above
mv "/home/derp/downloads/torrents/.part/$torrentname" "/home/derp/downloads/torrents/done/$tname25"

# I don't know if I need this, but I can sleep good with it :)
wait mv
There are some things which need improvement.
  • you have to change teh directory manually in Deluge in order to force re-check the torrent (Deluge: Y U NO checkin' the torrent by yourself when ready??)
  • check if the torrent is a folder and if so, don't create a new one - just move it
  • and more ... :)
If you have ideas, contact me!
Last edited by Orrly on Wed Sep 04, 2013 4:02 pm, edited 1 time in total.
Opt-out of Prism, use free and open source software -> http://prism-break.org/
spanishfry

Re: Post your execute plugin scripts!

Post by spanishfry »

Hello, I'm attempting to execute a bash script which will automatically upload a completed torrent back to my sftp site via lftp. I'm close to finished, but if I use $torrentpath it will send the contents of my seedbox's directory, if I use $torrentname or $torrentpath/$torrentname then the script will not execute. Can someone please assist? Thank you in advance

Code: Select all

#!/bin/bash

login=x
pass=x
host=sftp://x
local_dir=/home/spanishfry/files/completed
remote_dir=/Downloads/completed
torrentid=$1
torrentname=$2
torrentpath=$3

trap "rm -f /tmp/synctorrent.lock" SIGINT SIGTERM

if [ -e /tmp/synctorrent.lock ]
then
  echo "Synctorrent is running already."
  exit 1
else

  touch /tmp/synctorrent.lock

  lftp -u $login,$pass $host << EOF
#  set ftp:ssl-allow no
  set mirror:use-pget-n 5
  mirror -c -R -P5 --log=delugesync.log $torrentpath $remote_dir
  exit
EOF
  rm -f /tmp/synctorrent.lock
  exit 0
fi
Orrly
New User
New User
Posts: 4
Joined: Thu May 30, 2013 1:59 am

Re: Post your execute plugin scripts!

Post by Orrly »

I had some similar problems. Maybe you want to try quotes and absolute paths... solved most of my problems ;)
Have you looked at the script above your post?
Opt-out of Prism, use free and open source software -> http://prism-break.org/
armitatz
New User
New User
Posts: 4
Joined: Tue Jun 03, 2014 5:44 pm

Re: Post your execute plugin scripts!

Post by armitatz »

I try to run the script mkvdts2ac3 in order to automatically convert the dts track to ac3 because my setup can't play dts.
So the script I try to run is

Code: Select all

#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
sudo bash /home/pi/mkvdts2ac3.sh -d -i -m -n -p 18 --new $torrentpath/$torrentname | at 02:00
I try to set to run at 2:00 because the script takes 1+hour on the pi. Also it takes 100% of the cpu and xbmc becomes unresponsive. At 2:00 everybody is sleeping so it is ok...
I also modified the original mkvdts2ac3 script with a different working directory because /tmp fills up with big files.
mkvdts2ac3: https://github.com/JakeWharton/mkvdts2ac3
It runs from the command line but I will test it today with two files so I will post the results.

Note #1: I use the options to create new files because if you overwrite the originals the torrent files change so errors occure.
Note #2: The script needs 1) ffmpeg 2) mkvtoolnix 3) rsync and 4) at to be installed
Note #3: A time delay would be useful for the execute plugin. There might be jobs that take too much time or cpu and it could be useful to program them at a time where the pi is not needed.
armitatz
New User
New User
Posts: 4
Joined: Tue Jun 03, 2014 5:44 pm

Re: Post your execute plugin scripts!

Post by armitatz »

Well the script didn't worked :(
However I updated it and tested it and the new version works.

Code: Select all

#!/bin/bash

torrentid=$1
torrentname=$2
torrentpath=$3
if [ -d "${torrentname}" ] ; then
        for  filename in $torrentpath/$torrentname/*.mkv
        do
        echo "sudo bash /home/pi/mkvdts2ac3.sh -d -i -m -n -p 18 --new "$filename | at 01:00
        done
else
        if [ -f "${torrentname}" ]; then
        echo "sudo bash /home/pi/mkvdts2ac3.sh -d -i -m -n -p 18 --new "$torrentpath/$filename | at 01:00
        fi
fi
The changes are after I noticed something. I thought that the execute plugin calls once for every file. But if a torrent has a directory with files like
/dir
---file1.mkv
---file2.srt
---other file
then the variable torrentname has the name of the directory (/dir) and not the files in it. So a loop for every file inside the directory is needed. Also an extra check is needed to check if the torrentname is a directory or a filename.
I will test for a few more days and I will report back. However this script has a flaw because of the way the execute script works. Since it is called only once sometimes it reports a filename and some times a directory depending on the torrent. It would be better if it was called every time a file is completed. This way it would only report a filename and there would be no need for the directory/filename check. Also it would be called only for the selected for downloading files. Now there is no way to tell if a file is a valid file or not.
For example let's see the following scenario
a torrent which has a directory and some files
/torrent
...file1.mkv
...file2.mkv
...file3.srt
...file4.txt
Now let's say that I selected for download the file1.mkv and file3.srt. file2.mkv will be created because it might have some chunks of data common and so will file4.txt. The above script has no way to tell if file2.mkv is valid and will add it to the queue. If execute script was called for every finished file then it would be called twice for the valid filenames only.
armitatz
New User
New User
Posts: 4
Joined: Tue Jun 03, 2014 5:44 pm

Re: Post your execute plugin scripts!

Post by armitatz »

new version :

Code: Select all

#!/bin/bash
#
# Script for transcoding a mkv file with dts to a mkv file with ac3 sound.
# It is supposed to be called from the execute script of torrent programm Deluge
# Example : /home/pi/TransDTS
# time1 and time2 define the time window at which the script will transcode the file
# time1 and time2 must be at 24 hour format
#
# If the script gets called inside the time window it will be executed immediately
# If the script gets called outside the time window it will be executed at time -time1-
# If you want it to run always at call time use tim1=00:00 tim2=23:59
#
# example tim1=01:00 tim2=13:59
# This command defines a time window from 01:00am until 13:59pm
# If deluge finishes the torrent within this time then it will be executed immediately
# If deluge finishes the torrent outside the time window then the transcoding will
# start at 01:00
#
# The script calls the mkvdts2ac3 script written by JakeWharton
# https://github.com/JakeWharton/mkvdts2ac3
#

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

# set the time window
# Change these values as you wish
# **********************
tim1="01:00"
tim2="07:59"
# **********************

typeset -i exnow=0

# Initial mkvdts2ac3 command line. Refer to mkvdts2ac3 documentation
# for other options
command1="bash /home/pi/mkvdts2ac3.sh -d -i -m -n -p 18 --new "

# if we are in the time window then exnow becomes 1
st1=`date --date "$tim1" +%H%M`
x1=10#`date -d $st1 +%s`

st2=`date --date "$tim2" +%H%M`
x2=10#`date -d $st2 +%s`

typeset -i tim3=10#$(date +"%H%M")
x3=10#`date -d $tim3 +%s`

if ((x3 >= x1)) && ((x3 <= x2)) ; then
        exnow=1
fi

# Create initial torrent directory + torrent name
dir1="$torrentpath/$torrentname"

# Check if torrent name is a directory
if [ -d "$dir1" ] ; then
#       if torrent name is a directory then loop inside the directory for every *.mkv file
        for  filename in "$dir1"/*.mkv
        do
                # Create mkvdts2ac3 final command with absolute paths
                c="$command1\"$filename\""
#               Save the command to a file
                echo "$c" > "$dir1"/job.txt
#               Check if we are inside the time window
                if ((exnow)) ; then
#                       If inside the time window execute now the previous saved job
                        at -f "$dir1"/job.txt now
                else
#                       if outside the time window then execute later the saved job
                        at -f "$dir1"/job.txt $tim1
                fi
#               Clear job file
                rm "$dir1"/job.txt
        done
else
#       if torrent name is a file then check the time
        if [ -f "${dir1}" ]; then
                # Save the command to a file
                echo "$command1""\"""$dir1""\"" > "$torrentpath"/job.txt
                if ((exnow)) ; then
#                       If inside the time window execute now the previous saved job
                        at -f "$torrentpath"/job.txt now
                else
#                       if outside the time window then execute later the saved job
                        at -f "$torrentpath"/job.txt $tim1
                fi
#               Clear job file
                rm "$torrentpath"/job.txt
        fi
fi
This script uses two variables "tim1" and "tim2". You can use them to define a time window from tim1 until tim2. If a torrent finishes inside the time window then it is executed immediately. If it finishes outside the time window it will run at tim tim1. You can change the two values to any time yu like to suit your needs.
I have tested the script for 4 days now with a few torrents but if you find any problems feel free to ask. Also it is my first bash script ever so be kind with any errors :)
Don't forget to make it executable and install "at" with

Code: Select all

apt-get install at
Peterjs

Re: Post your execute plugin scripts!

Post by Peterjs »

Got a relatively simple Bash script to symlink completed files to another location.

Code: Select all

#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3

sudo ln -s $torrentpath/$torrentname /mnt/example/movies/$torrentname
PS. Remember to modify permissions for deluge user.
heiss
New User
New User
Posts: 1
Joined: Tue Dec 02, 2014 5:20 am

Re: Post your execute plugin scripts!

Post by heiss »

With deluge 1.3.8+ there is now a torrent remove execute trigger. Here's a simple script move the torrent file/directory to a different folder on remove (I have no idea what this does if you use the "remove torrent with data" option though:

Code: Select all

#!/usr/bin/env python
import sys, os, shutil

torrent_id   = sys.argv[1]
torrent_name = sys.argv[2]
save_path    = sys.argv[3]

output_directory = "/path/to/removed/folder"

source      = os.path.join(save_path, torrent_name)
destination = os.path.join(output_directory, torrent_name)

# Check the source file/directory exists
if not os.path.exists(source):
   print "Path "+source+" does not exist."
   exit(1)

# Check that destination doesn't already exist
if os.path.exists(destination):
   print "Path "+destination+" already exists.  Aborting."
   exit(1)

# move the file

print "Moving "+source+" to "+destination
retcode = shutil.move(source, destination)

if retcode:
   print "Move failed"
   exit(1)                                                                                                                                                                        
                                                                                                                                                                                  
exit(0)
Slasher

Re: Post your execute plugin scripts!

Post by Slasher »

This is mine - to copy the file to my VU+ Duo

Code: Select all

#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3

cp -r "$torrentpath/$torrentname" "/media/vuduo/media/sda1/movie/"
However, it doesn't always seem to work. Yes, the folder is mounted. I was wondering if anyone could help me correct it please? It worked when I tested it, but I started a download last night before going to bed, locked my pc and it didn't copy the file across on completion for some reason.
Post Reply