Post your execute plugin scripts!

Suggest, post, or discuss plugins for Deluge
mhertz
Compulsive Poster
Compulsive Poster
Posts: 750
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Post your execute plugin scripts!

Postby mhertz » Thu Nov 17, 2016 8:14 pm

Have you specifically run the test script I posted through deluge's execute plugin? I don't mean running manually what you wrote above. It's to figure out if it's a deluge plugin bug or not?

My hunch is that it's probably just needed to do e.g.

torrentid="$1"
torrentname="$2"

In your original script.

Sorry, I can't test as am currently running qbittorrent-nox and not deluge(I go back and fourth often as can't decide fully, lol), and with that app's execute functionality I also have to play around with double-quotes in various arrangements to get it to work right with spaces in names/paths, though it's a shell-scripting issue and not app related. (I'm currently working on an execute script for that app which mimicks deluge's labelplus plugin's autolabels functionality to auto move downloaded content into different paths based on file-extensions, like *.(mkv|mp4|avi) into ~/video and music into ~/music etc. and cleanup/delete useless crap like *.(txt|nfo) etc)

romprod
New User
New User
Posts: 9
Joined: Mon Jun 29, 2015 8:56 pm

Re: Post your execute plugin scripts!

Postby romprod » Thu Jan 12, 2017 10:06 am

Hi,

Is there a way to see the output of this plugin when it launches a .bat file from windows.

It's a royal PITA trying to debug my script blind folded! :)

Thanks.

saadbruno
New User
New User
Posts: 2
Joined: Thu Feb 09, 2017 10:51 pm

Re: Post your execute plugin scripts!

Postby saadbruno » Thu Feb 09, 2017 11:06 pm

I have a few scrips now.

The first one is to download subtitles for completed torrents using Subliminal.

Code: Select all

#!/bin/bash
#Script to run subliminal on newly downloaded torrents and generate a log file.

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

subliminal --opensubtitles <user> <passwd> --legendastv <user> <passwd> download -w 1 -l pt-BR -a 1h -v "$torrentpath"


The second and third ones are to send a notification to my phone (using IFTTT's Maker Channel) when a torrent is added and completed. I use that because we run Deluge on a shared Raspberry Pi in the house (and I like to know when people add stuff to it).

Torrent added:

Code: Select all

#!/bin/bash
# Send IFTTT notification when torrent is added.

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

curl -X POST -H "Content-Type: application/json" -d '{"value1":"'"$torrentid"'","value2":"'"$torrentname"'","value3":"'"$torrentpath"'"}' https://maker.ifttt.com/trigger/deluge_add/with/key/<ifttt_key>


IFTTT Maker Channel config:
Event Name: deluge_add
Notification: Torrent Added! Name: "{{Value2}}"

Torrent completed:

Code: Select all

#!/bin/bash
# Send IFTTT notification when torrent is completed.

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

curl -X POST -H "Content-Type: application/json" -d '{"value1":"'"$torrentid"'","value2":"'"$torrentname"'","value3":"'"$torrentpath"'"}' https://maker.ifttt.com/trigger/deluge_complete/with/key/<ifttt_key>

IFTTT Maker Channel config:
Event Name: deluge_complete
Notification: Torrent Downloaded! Name: "{{Value2}}" Path: "{{Value3}}" At: {{OccurredAt}}

jameswhatson
New User
New User
Posts: 1
Joined: Wed May 23, 2018 9:06 am

Re: Post your execute plugin scripts!

Postby jameswhatson » Wed May 23, 2018 9:11 am

WhatsApp Messenger is the most convenient way of quickly sending messages on your mobile phone to any contact or friend on your contacts list. The only requirement is that the other people must have the app installed on their own device.

https://7downloads.com/whatsapp-apk-download

Paul.C
New User
New User
Posts: 1
Joined: Fri Mar 15, 2019 2:05 am

Re: Post your execute plugin scripts!

Postby Paul.C » Fri Mar 15, 2019 2:16 am

https://gist.github.com/paul-chambers/71ef48e40449ec73eef95430b9e4e6c7

Deluge script to link a copy of a completed torrent into a second folder
Intended to be run at torrent completion, using the 'torrent complete' event in the 'Execute' plugin.

The basic idea is to hardlink the files that deluge has just finished downloading into a second directory. This allows you to configure deluge to automatically pause or delete torrents when they reach a given seed ratio, while also keeping a copy around for other reasons. For example, SyncThing could be used to propagate new downloads to a remote machine to be processed further. When processing has finished, and the file is deleted/moved out of the Syncthing folder, the remote Syncthing will propagate a deletion back to the original Syncthing (on the machine running deluge).

The end result is that the lifetime of files involved both in deluge's seeding process and the 'forward to somewhere else' process (e.g. via Syncthing) are decoupled, and can safely execute in parallel without needing to be aware of what the other is doing. And yet the net result is that the files will still be cleaned up automagically when both have finished their respective tasks.

The script also automatically 'unrars' the download if it finds a .rar file in the second copy, while leaving the 'seeding' copy untouched.

qandayen
New User
New User
Posts: 1
Joined: Sun Oct 06, 2019 9:38 pm

Re: Post your execute plugin scripts!

Postby qandayen » Sun Oct 06, 2019 10:02 pm

Hello!

My first post here, and I will share my execute plugin.

My current setup is a Hyper-V server with an arch linux VM running, among others, deluge container.

In order to seed I use the local SATA HDD drive, but the final destination is a Synology NAS.

For TV shows and movies I use automatization (sickrage/couchpotato), the problem is how to copy the downloaded files (usually manually added torrents) that are not processed by sickrage/couchpotato.

- Move from deluge to the NAS is not an option.
- Copy completed plugin can´t work with labels, which will affect to all torrents.

In order to solve this I made a PowerShell solution that is kind of weird but it works for my needs.

- First I move all the finished torrents with no label to a folder (deluge takes care of this) --> /tempf/downloads/others
- Then execute plugin runs a super small shell script that basically waits 10 minutes (to give deluge enough time to move the files) and then it creates a file that will be used by the powershell script as an indication that a new torrent has been downloaded:

Code: Select all

#!/bin/bash
sleep 10m
touch /config/newtorrent.exist

- The powershell script runs every five minutes on crontab, but only process files/folders if newtorrent.exist exists.

Code: Select all

*/5 * * * * /bin/pwsh /path/to/script/copyfinishedtorrents.ps1

- And finally the powershell script:

Code: Select all

# Set variables
$torrentdownloadfolder="/tempf/downloads/others"
$torrentdestinationfolder="/home/deluge/others"

# Checks if new torrents have been downloaded
if ((Test-Path "/home/deluge/config/newtorrent.exist") -eq $true)
{
    Remove-Item "/home/deluge/config/newtorrent.exist"
    # Gets files/folders in local HDD download folder
    $torrentdownloadfiles = Get-ChildItem $torrentdownloadfolder
    # Gets files/folders in remote NAS destination folder
    $torrentnasfiles = Get-ChildItem $torrentdestinationfolder
    # Compare both locations and returns the files and folders that are not present (in both directions)
    $torrentfilediffs = Compare-Object -ReferenceObject $torrentdownloadfiles -DifferenceObject $torrentnasfiles
    $torrentfilediffs | ForEach-Object {
        $torrentparameters = @{
            'Path' = $_.InputObject.Fullname
                   }
         $torrentpath = $torrentparameters.path
        if ($_.SideIndicator -eq '<=') # The copy can be in the other direction by using => instead of <=
            {
              Copy-Item $torrentpath -Destination $torrentdestinationfolder -Recurse # Copy the files/folders available on the HDD that are not present on the NAS
            }
        }
}

Clear-Variable torrent*


- One thing I´m still missing is that if something is deleted from the NAS it will be copy again in a future run of the script, I will probably update the script adding a file where the paths for already copied torrents are stored.

- I´m not an expert on Powershell (yet xD), sorry if this is a little bit messy.

- Good news! This can be run in Powershell core, which means that is multiplatform (Windows, Linux, Mac, etc). Of course the paths need to be changed.

Any suggestions or questions are more than welcome :)

GostLy
New User
New User
Posts: 4
Joined: Sun Oct 27, 2019 6:47 am

Re: Post your execute plugin scripts!

Postby GostLy » Sun Oct 27, 2019 8:11 pm

I ran into a problem accessing files after they were downloaded because of permission problems so I created this simple script to change the ownership of files after they get downloaded. This way I don't have to manually change the ownership every time and I'm sure there's more than one way to deal with this but I figured this was an easy way.

So the script changes ownership of downloaded files and prints the information out to a log file. Not necessary but I like to use logs to know that things are running like they should.

changeOwnership.sh

Code: Select all

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

user=XXXX
group=XXXX
outputLog=/home/$user/deluge.scripts/scripts.log

echo -e `date`"::Changed ownership: $torrentpath/$torrentname (now owner is user: $user group: $group)" with id:$torrentid >> "$outputLog"
sudo chown -R $user:$group "$torrentpath/$torrentname"

mhertz
Compulsive Poster
Compulsive Poster
Posts: 750
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Post your execute plugin scripts!

Postby mhertz » Sun Oct 27, 2019 8:37 pm

I've made and use following bash-script for a long time, which suits my needs, and previously it removed crap like nfo's and samples etc, but lately i've instead just moving the video-files out of there subfolder and into destination, as I always delete movies/series when i've seen them and so prefer not having subfolders e.g. for each episode sometimes in a series etc.

So, if there are mkv, mp4 or avi files contained anywhere in the torrent, then video is moved to '~/video' and possible samples are deleted first, so not included, and then finally subs are retrieved from opensubtitles afterwards, and leftover files/dirs deleted.

Code: Select all

#!/bin/bash

if [ -d "$3/$2" ]; then
   find "$3/$2" -type f \( -iname "*sample*.avi" -o -iname "*sample*.mp4" -o -iname "*sample*.mkv" \) -delete
   find "$3/$2" -type f \( -iname "*.avi" -o -iname "*.mp4" -o -iname "*.mkv" \) -exec OpenSubtitlesDownload.py -l dan {} \;
   find "$3/$2" -type f \( -iname "*.avi" -o -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.srt" -o -iname "*.idx" -o -iname "*.sub" \) -exec mv {} ~/video \;
   rm -rf "$3/$2"
else
   if [ ${2: -4} == ".mkv" ]; then
      mv "$3/$2" ~/video
      OpenSubtitlesDownload.py -l dan "~/video/$2"
   elif [ ${2: -4} == ".mp4" ]; then
      mv "$3/$2" ~/video
      OpenSubtitlesDownload.py -l dan "~/video/$2"
   elif [ ${2: -4} == ".avi" ]; then
      mv "$3/$2" ~/video
      OpenSubtitlesDownload.py -l dan "~/video/$2"
   elif [ ${2: -4} == ".MKV" ]; then
      mv "$3/$2" ~/video
      OpenSubtitlesDownload.py -l dan "~/video/$2"
   elif [ ${2: -4} == ".MP4" ]; then
      mv "$3/$2" ~/video
      OpenSubtitlesDownload.py -l dan "~/video/$2"
   elif [ ${2: -4} == ".AVI" ]; then
      mv "$3/$2" ~/video
      OpenSubtitlesDownload.py -l dan "~/video/$2"
   fi
fi

I believe I first made it when using rtorrent, where labelplus deluge-plugin wasen't available of course, which could auto-label files from file-extension and move files conditionally, but when changing back to deluge again(as more aggressive peering), I might as well adapt it and use it still, instead of needing label-plus, and also because it did more for me, e.g. getting subs and removing crap and subfolders.

It can easily be built upon, and so e.g making a section for music which instead of mkv, mp4 and avi, then matches for flac, mp3, aac, ogg etc and moves to '~/music' dir, but I currently only use youtube-playlists for listening to music, so don't use such personally. Or, exe for apps and pdf for ebooks/docs etc.

This works no matter if torrent is single file only, or dir with multiple files/sub-dirs.

I just wanted to have an automated system for when selecting a magnet-link or torrent, and based on content gets sorted properly, without me needing to first select a label first or saving torrent to specific dir which is then sorted accordingly.

Ohh, off-topic, but if you like me love terminal-apps, then here's two of my favorite terminal torrent-searching-apps where you can select to download the searched result also, e.g I have it setup to be loaded automatically into deluged through deluge-console:

https://github.com/vikstrous/pirate-get (tpb only)
https://gitlab.com/radek-sprta/Mariner (tpb and many others too)

snowybunting
New User
New User
Posts: 1
Joined: Sat Dec 07, 2019 1:30 am

Re: Post your execute plugin scripts!

Postby snowybunting » Sat Dec 07, 2019 7:21 pm

Paul.C wrote:https://gist.github.com/paul-chambers/71ef48e40449ec73eef95430b9e4e6c7

Deluge script to link a copy of a completed torrent into a second folder
Intended to be run at torrent completion, using the 'torrent complete' event in the 'Execute' plugin.


This is a cool solution. The unrar is really handy, and while I stopped using Syncthing and had to add an "rsync" line to get the file from the seedbox to my home computer, your script helped me figure that out. Thanks for posting it.

doccie
New User
New User
Posts: 1
Joined: Mon Jun 22, 2020 1:57 pm

Re: Post your execute plugin scripts!

Postby doccie » Mon Jun 22, 2020 3:57 pm

Guess I will add my newly created scripts as well :)

I have 3 scripts that all tie into one main script. These are geared towards usage with a Plex Media Server. The plex_init script is called on Torrent Completed.

  1. plex_change_permissions - changes permissions of the newly created folder to 777
  2. plex_tidy_filenames - replaces any spaces and other unwanted characters by a '.'
  3. plex_rescan_library - forces Plex Media Scanner to perform a rescan to automatically add the movie to the library
  4. plex_init - ties together all three scripts above and adds some `sleep` commands in between to make sure everything has successfully finished before moving on to the next script

Note: my plex_init.sh script is the parent script so all variables ($torrentpath, $torrentname, $torrentid, $outputLog) are shared with that script. If you want to use these scripts individually, you'll need to declare those variables in the individual scripts.

plex_change_permissions
This script recursively changes the permissions of the folder and the files contained within to 777

Code: Select all

#!/bin/bash
user=pi
mode=777

echo -e `date`" - Changed Permissions: $torrentpath/$torrentname (new permissions: $mode)" with id:$torrentid >> "$outputLog"
sudo chmod -R 777 "$torrentpath/$torrentname"


plex_tidy_filenames
More for my OCD rather than serving any real functional purpose. This will rename the folder in which the torrent was saved.
For instance:
"A Farewell To Arms 1932_(720p)_[BluRay] x264-x0r" will become
"A.Farewell.To.Arms.1932.720p.BluRay.x264-x0r"

The script removes any brackets ('[', ']', '(', ')'), underscores and spaces. It's not perfect, but it does the trick for me.

Code: Select all

#!/bin/bash

# Remove special characters
# Will remove "[", "]", "(", ")", "_" and spaces
newname=$(echo "$torrentname" | sed -r 's/[]\[ _()]+/./g')

# Remove trailing dots
newname=$(echo "$newname" | sed 's/\.$//')


echo -e `date`" - Tidied filename: $torrentname (new name: $newname)" with id:$torrentid >> "$outputLog"
mv "$torrentpath/$torrentname" "$torrentpath/$newname"


plex_rescan_library
This script forces a rescan of the Plex Media Scanner, note that you may need to change the location of the library path.

Code: Select all

#!/bin/bash
export LD_LIBRARY_PATH=/usr/lib/plexmediaserver

echo -e `date`" - Started library scan" >> "$outputLog"
/usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan


plex_init
You could potentially just add the three scripts above individually to the Execute plugin, but I feel my current setup gives me a little bit more control over the order in which each script is executed and when. Also, it allows me to only declare the variables once, instead of having to declare them individually for each script.

Code: Select all

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

outputLog=/var/log/deluge/scripts.log
currentdir="${0%/*}"

echo -e `date`" - Started plex init scripts for $torrentpath/$torrentname" >> "$outputLog"

# Change Permissions
source "$currentdir"/plex_change_permissions.sh

# Change Tidy Filenames
sleep 5
source "$currentdir"/plex_tidy_filenames.sh

# Trigger Plex Rescan
sleep 5
source "$currentdir"/plex_rescan_library.sh


I only recently got started with Deluge, so I'd appreciate any feedback if there are better ways of achieving this :)


Return to “Plugins”

Who is online

Users browsing this forum: No registered users and 1 guest