Post your execute plugin scripts!

Suggest, post, or discuss plugins for Deluge
CSB
Leecher
Leecher
Posts: 66
Joined: Fri Dec 03, 2010 1:55 am

Post your execute plugin scripts!

Postby CSB » Sat Jan 01, 2011 1:37 am

There should really be a place for people to post the scripts that they use with the execute plugin, since I'm sure a lot of us might be doing the same thing, or similar... or maybe just to give each other some ideas...

I think this one is pretty clever... I use PS3MediaServer to stream to my PS3, and have it sort by date, such that new stuff is always on top... however is things are downloaded after PS3MS starts, they end up being appended (to the bottom). This is pretty wonky, so my solution is, whenever a file finishes downloading, restart the PS3MS service, but only if the PS3 isn't connected. I also have this run as an hourly cronjob, so if the PS3 is connected when a download finishes, the "re-ordering" doesn't wait until the next download to happen.

Code: Select all

#!/usr/bin/python
import os
import subprocess
import sys

p1 = subprocess.Popen(["netstat", "-tunv"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["grep", ":5001"], stdin=p1.stdout, stdout=subprocess.PIPE)

if os.waitpid(p2.pid, 0)[1]:
#       print "restarting PS3M"
        pstop = subprocess.Popen(["/etc/init.d/PS3MediaServer", "stop"], stdout=subprocess.PIPE)
        os.waitpid(pstop.pid,0)
        pstart = subprocess.Popen(["/etc/init.d/PS3MediaServer", "start"], stdout=subprocess.PIPE)
        os.waitpid(pstart.pid,0)
#       print "PS3M restarted"
#else:
#       print "connections found"


The following is a simple script to send a prowl alert whenever a torrent completes.

Code: Select all

#!/bin/bash
curl -k https://prowl.weks.net/publicapi/add -F apikey=X -F application="Deluge" -F event="Torrent Completed" -F description="$2" &


The next two scripts work together...
The first one is run on torrent completion, and if a torrent is being downloaded to "/*/*/Files/", it makes a symlink to it in "/media/2TB/New Files"
The second runs on a daily cronjob, and removes any links in "/media/2TB/New Files/" that are over 6 days old.
The net effect, clearly, is that "/media/2TB/New Files/" contains symlinks to all of the new downloads (less than 6 days old)

Code: Select all

#!/usr/bin/python
import sys
import os
if sys.argv[3].split('/')[3] == 'Files':
        os.system("ln -s \""+sys.argv[3]+sys.argv[2]+"\" /media/2TB/New\ Files/")

Code: Select all

#!/bin/bash
find /media/2TB/New\ Files/ -mtime +6 -type l -exec rm {} \;
find -L /media/2TB/New\ Files/ -type l -delete
Last edited by CSB on Sun Jan 16, 2011 10:21 pm, edited 1 time in total.

keepitcomplicated
Member
Member
Posts: 29
Joined: Wed Sep 29, 2010 1:40 pm

Re: Post your execute plugin scripts!

Postby keepitcomplicated » Sun Jan 16, 2011 1:26 pm

This script that adds new downloads as a symlink is brilliant! could you explain to me a little more how you used it? :roll:

joelstitch

Re: Post your execute plugin scripts!

Postby joelstitch » Mon Apr 18, 2011 5:57 pm

This script is to make the computer shutdown after a torrent is completed.

1. Open gedit and paste this in it:

Code: Select all

#!/bin/bash
DL=`conkyDeluge |grep Downloading`
while [ "$DL" != "" ] ;do
DL=`conkyDeluge |grep Downloading`
# echo "not yet"
sleep 10
done

#gtk warning
#zenity --info --text="computer will shutdown in 20 seconds"
#sleep 20

#GTK warning better version
#wait time = 100 x 0.2 = 20
(for a in `seq 1 100` ; do echo $a; sleep 0.2; done) | zenity --auto-close --auto-kill --progress --text=" Shutting down\n click cancel to stop" --title="Shutdown"

#echo now shutdown
halt
and save it as shutdown.sh


2. Open Deluge and click on Edit > Preferences > Execute

3. On Event choose Torrent Complete and on Command write the address for the .sh file you just created. In my case is /home/name/Desktop/shutdown.sh

4. Click on Apply

Jaxon
Member
Member
Posts: 11
Joined: Tue Sep 01, 2009 3:52 am

Re: Post your execute plugin scripts!

Postby Jaxon » Tue May 24, 2011 3:48 am

I use this to automatically copy/extract anything within a directory (I use the series label to move them to a different spot) into a sync folder. If you use this, your SOURCE folder needs to have a .done subdirectory.

Code: Select all

#!/bin/bash

DEST=
SOURCE=
IFS=$(echo -en "\n\b")

#sleep 10s

cd $SOURCE || { echo "Can't change to ${SOURCE}"; exit 1; }

#cd $SOURCE

for show in *
do
    echo $show
    if [[ ! -f .done/${show} ]]; then
        filetype=$(file -b --mime-type ${show})

        if [[ $filetype == video/x-msvideo ]]; then
            cp "$show" "$DEST"
        elif [[ $filetype == application/x-rar ]]; then
            unrar x $show $DEST
        elif [[ $filetype == application/x-directory ]]; then
            for rarfile in $(find $show -iname "*.r00")
            do
                unrar x $rarfile ${DEST}
            done

            for rarfile in $(find $show -iname "*.part02.rar")
            do
                unrar x $rarfile ${DEST}
            done
        fi

        if [[ $? -eq 0 ]]; then
            touch .done/${show}
        else
            touch ${DEST}ERROR-${show}
        fi
    fi
done

for mark in $(ls -1 ${SOURCE}.done)
do
    if [[ ! -a ${SOURCE}${mark} ]]; then
        rm ${SOURCE}.done/${mark}
    fi
done

nickeh
Member
Member
Posts: 32
Joined: Sun Oct 05, 2008 11:18 pm

Re: Post your execute plugin scripts!

Postby nickeh » Tue Jun 14, 2011 12:23 pm

I use these two scripts to alert XBMC when torrents are added and then when they are downloaded it tells XBMC to update the video library.

On add:

Code: Select all

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

title="Deluge: Torrent added"
message="Torrent: $torrentname"

xbmc-send -a "Notification($title, $message)"


On downloaded:

Code: Select all

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

title="Deluge: Torrent Downloaded"
message="Torrent: $torrentname, updating library"

xbmc-send -a "Notification($title, $message)"
xbmc-send -a "UpdateLibrary(video)"

kicks66

Re: Post your execute plugin scripts!

Postby kicks66 » Sat Oct 01, 2011 4:21 pm

nickeh wrote:I use these two scripts to alert XBMC when torrents are added and then when they are downloaded it tells XBMC to update the video library.

On add:

Code: Select all

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

title="Deluge: Torrent added"
message="Torrent: $torrentname"

xbmc-send -a "Notification($title, $message)"


On downloaded:

Code: Select all

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

title="Deluge: Torrent Downloaded"
message="Torrent: $torrentname, updating library"

xbmc-send -a "Notification($title, $message)"
xbmc-send -a "UpdateLibrary(video)"


This is something I want to add into my Deluge/xbmc set up. However, I currently have a .bat file which copies the downloaded files and puts them through theRenamer, is it possible to have a delay before these two are launched? And is there a way to have them as part of the same .bat file?

aristidesfl
New User
New User
Posts: 8
Joined: Sat Jul 07, 2012 4:46 am
OS or Distro: Ubuntu

Re: Post your execute plugin scripts!

Postby aristidesfl » Tue Jul 10, 2012 12:35 am


rednoah
New User
New User
Posts: 4
Joined: Sun Apr 11, 2010 3:36 pm

Re: Post your execute plugin scripts!

Postby rednoah » Wed Feb 06, 2013 9:38 am

Still FileBot, but much more simple now:
http://filebot.sourceforge.net/forums/v ... 3382#p3382

ricksebak
Member
Member
Posts: 12
Joined: Wed Jan 02, 2013 2:11 am
OS or Distro: Ubuntu 12.04

Re: Post your execute plugin scripts!

Postby ricksebak » Sun Feb 10, 2013 2:31 am

Good thread.

I made this the other day. It goes through my torrent download directory and looks for directories where 90% of their size is taken up by a video file. Then it deletes everything other than that video file (to clean up stupid nfo files, sample video files, readme files, subtitle files, etc). It should basicly accomplish the same thing as flexget's main_file_only option, but for torrents which weren't downloaded through flexget.

Code: Select all

#!/usr/bin/python

# User defined variables go here:

path = "/path/to/torrent/downloads/"
videoextensions = ["mkv", "avi", "mp4"]
logfile = "/path/to/some/logfile"

# That's all

import os
import os.path
import datetime

# Declare some functions first

# Get the file size of all the files in a list
def totaldirsize(path):
        dirsize = 0
        for file in os.listdir(path):
                dirsize += os.stat(path + "/" + file)[6]
        return dirsize

# Get the file size of an individual file
def filesize(fullpath):
        filesize = os.stat(fullpath)[6]
        return filesize


# Make a list of everything in the user specified path
toplist = os.listdir(path)

# Remove non-directories from toplist
for item in toplist:
        if os.path.isdir(path + "/" + item) == False:
                toplist.remove(item)

# Find which dirs have a show, put them in showlist
showlist = []
for dir in toplist:
        for file in os.listdir(path + "/" + dir + "/"):
                if file.lower()[-3:] in videoextensions:
                        showlist.append(path + "/" + dir)
                        break

# Get the size of each dir, and determine if a video is 90% of that size
ninetydirs = []
for dir in showlist:
        dirsize = totaldirsize(dir)
        # Get the size of each file and test it
        for file in os.listdir(dir + "/"):
                if filesize(dir + "/" + file) > dirsize * .9 and \
                file.lower()[-3:] in videoextensions and \
                os.path.isfile(dir + "/" + file):
                        ninetydirs.append(dir + "/")
                        break


# Remove all the files which aren't videos from the directories which
# have videos and the videos make up 90% of their size

for dir in ninetydirs:
        dirsize = totaldirsize(dir)
        for file in os.listdir(dir):
                if filesize(dir + "/" + file) < dirsize * .1 and \
                os.path.isfile(dir + "/" + file):
                        os.remove(dir + "/" + file)
                        with open(logfile, "a+") as log:
                                log.write(datetime.datetime.now().strftime("%b %d %Y %H:%M:%S")+ " Deleted " + dir + file + "\n")


jkaberg
New User
New User
Posts: 3
Joined: Fri Feb 15, 2013 8:53 am
OS or Distro: Windows

Re: Post your execute plugin scripts!

Postby jkaberg » Fri Feb 22, 2013 12:09 pm

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 :)


Return to “Plugins”

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests