Execute Plugin and Labels

General support for problems installing or using Deluge
Post Reply
darkcircuituk
New User
New User
Posts: 3
Joined: Fri Feb 27, 2015 12:29 pm

Execute Plugin and Labels

Post by darkcircuituk »

Hey all,
I'm a big fan of Deluge, I run it on 4 different machines and it has worked flawlessly up till now. In Ubuntu I am trying to get the deluge Execute plugin to talk nicely with filebot and although the vast majority of the script works great, I am hitting a problem when trying to get the label I specified with the label plugin. Does anyone have any knowledge on how to get the label within a bash script? I blindly hoped that argument 4 might be the label but nope; I have put my script below in-case it helps.

Code: Select all

#!/bin/bash
TORRENT_ID=$1
TORRENT_NAME=$2
TORRENT_PATH=$3
TORRENT_LABEL=$4

filebot -script fn:amc --output "/media/NAS" --log-file filebot.log --action test --conflict override -non-strict --def music=y artwork=n clean=y "seriesFormat=Videos/TV Shows/{n.replace(':','- ')}/Season {s}/{'S'+s.pad(2)}{'E'+e.pad(2)} - {t.replace(':','- ')}"  "ut_dir=$TORRENT_PATH/$TORRENT_NAME" "ut_kind=multi" "ut_title=$TORRENT_NAME" "ut_label=$TORRENT_LABEL"
Thanks for any help
darkcircuituk
New User
New User
Posts: 3
Joined: Fri Feb 27, 2015 12:29 pm

Re: Execute Plugin and Labels

Post by darkcircuituk »

No-one has pulled out labels from deluge in a post processing script?
noze2000

Re: Execute Plugin and Labels

Post by noze2000 »

+1 on this.

Sync'ing from my download (seed)box to my local NAS works great.
But I would like to not have a constand xtra opy of my downloads (need to unpack for media center Sickrage/(plex) which means that i need two copies if I am to stop a constant syncing from seedbox to local machine).

This would help a lot
darkcircuituk
New User
New User
Posts: 3
Joined: Fri Feb 27, 2015 12:29 pm

Re: Execute Plugin and Labels

Post by darkcircuituk »

I did a bit of digging and found a script in a 2 year old thread that claims it can retrieve the label from a torrent, but I haven't been able to get it working. In the hope that someone can help, or that you have more luck with it than me, here it is:

getLabel.py

Code: Select all

#!/usr/bin/python

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

# Set up the logger to print out errors
from deluge.log import setupLogger
setupLogger()

d = client.connect()

torrent_id = sys.argv[1]

def on_connect_success(result):
    def on_get_torrent_status(torrent):
        print torrent["label"]
        client.disconnect()
        reactor.stop()

    client.core.get_torrent_status(torrent_id, ["label"]).addCallback(on_get_torrent_status)

d.addCallback(on_connect_success)

def on_connect_fail(result):
        print result
        reactor.stop() 

d.addErrback(on_connect_fail)

reactor.run()
postprocessingscript:

Code: Select all

LABEL=$(/home/***/MyScripts/getLabel.py $torrentid)
sndo37
New User
New User
Posts: 9
Joined: Mon Aug 10, 2015 1:34 am

Re: Execute Plugin and Labels

Post by sndo37 »

Another +1 on this. Deluge is fantastic, and the plugins are great, but I would LOVE to have to option to copy completed on a per-label basis.

Not sure if anyone is still working on the basic label plugin, but adding a "Copy" option (in addition to the pre-existing "Move" option) would save a ton of headaches for me, and probably others too:)
Weenyhead

Re: Execute Plugin and Labels

Post by Weenyhead »

Little late to this party, but in case someone finds this page like I did, here's the solution I came up with:

Set a different "move to location" (directory) for each label.
Then in your execute script you can check that directory (the path variable).

example:

Code: Select all

#!/bin/bash

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

if [ $torrentpath == "/home/vpn/Downloads/complete/tv" ] ; then
    # do something to tv downloads
elif [ $torrentpath == "/home/vpn/Downloads/complete/movie" ] ; then
    # do something to movie downloads
else
    # do something with all other downloads
fi
Hope that helps :)
PixelBurst
New User
New User
Posts: 1
Joined: Wed May 30, 2018 9:19 am

Re: Execute Plugin and Labels

Post by PixelBurst »

Weenyhead wrote:Little late to this party, but in case someone finds this page like I did, here's the solution I came up with:

Set a different "move to location" (directory) for each label.
Then in your execute script you can check that directory (the path variable).

example:

Code: Select all

#!/bin/bash

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

if [ $torrentpath == "/home/vpn/Downloads/complete/tv" ] ; then
    # do something to tv downloads
elif [ $torrentpath == "/home/vpn/Downloads/complete/movie" ] ; then
    # do something to movie downloads
else
    # do something with all other downloads
fi
Hope that helps :)
To expand on the late party - I've just set up exactly what OP wants using your post as guidance, so thank you! I thought I'd come and share the finished result to hopefully help others.

So just like Weenyhead said, you can achieve this pretty easily with the example here for an if, elif, else, fi scipt with the downloaded location as the variable, rather than trying to do it on a per label basis. I choose to also package the filebot commands into .sh scripts for ease of use, but you can do it how you like.

Code: Select all

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PATH="/snap/bin:$PATH"
export DISPLAY=:0

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

if [[ $torrentpath == "/media/storage/Downloads/TVToProcess" ]] ; then
     bash /home/pixelburst/bin/tv.sh
     bash /home/pixelburst/bin/cleantv.sh
elif [[ $torrentpath == "/media/storage/Downloads/AnimeToProcess" ]] ; then
     bash /home/pixelburst/bin/anime.sh
     bash /home/pixelburst/bin/cleananime.sh
elif [[ $torrentpath == "/media/storage/Downloads/MoviesToProcess" ]] ; then
     bash /home/pixelburst/bin/movies.sh
     bash /home/pixelburst/bin/cleanmovies.sh
else
    :
fi
So this is the main script, the one you point at from the execute plugin. As you can see I have tv.sh, anime.sh and moviessh downloading into 3 different folders as set up via RSS and watched folders - hence this script looks for them upon a torrent completing to check the path. If it matches TVToProcess/AnimeToProcess/MoviesToProcess it then executes the relevant script. For examples sake, we'll say it matches TVToProcess.
else
:
is very important here as it essentially tells it to do nothing if a completed torrent don't match those folders.

tv.sh looks like this -

Code: Select all

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PATH="/snap/bin:$PATH"
export DISPLAY=:0
filebot -rename "/media/storage/Downloads/TVToProcess" --format "/media/storage/Media/TV Shows/{n}/Season {s.pad(2)}/{n} - {s00e00} - {t}" -non-strict -r --db TheTVDB
this does the filebot renaming - modify the script and format for each desired. Then finally it runs cleantv.sh which looks like so -

Code: Select all

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PATH="/snap/bin:$PATH"
export DISPLAY=:0
filebot -script fn:cleaner --def exts="/jpg|jpeg|png|gif|nfo|xml|htm|html|log|srt|sub|idx|md5|sfv|txt|rtf|url|db|dna|log|tgmd|json|data|srv|srr|nzb|z|aria*|torrent|par\d+|part\d+/" /media/storage/Downloads/TVToProcess
this cleans up any leftovers. Easy!
Brando47
New User
New User
Posts: 2
Joined: Wed Jun 05, 2019 1:25 pm

Re: Execute Plugin and Labels

Post by Brando47 »

Late to the party :lol: figured I'd join up and contribute my extension on the information/ideas I got from this thread, forgive me for any mistakes as I'm new to linux/bash but gave it a crack and it's working great. Basically I've used labels in Deluge and set it to move completed movies or tv shows into their own respective folders as Weenyhead suggested, I've even semi-automated this for say a regularly downloaded TV show to auto-label (using LabelPlus plug in). If you're doing this for FileBot, worst case if I forget to label it goes into an unsorted folder and is processed by the Deluge AMC script provided by rednoah just as he's given it essentially (with no label input).

Code: Select all

#!/bin/bash
#PATH=/usr/local/bin/

# Input Parameters
ARG_ID="$1"
ARG_NAME="$2"
ARG_PATH="$3"
ARG_FILEPATH="$3/$2"
ARG_LABEL=$(echo $ARG_PATH | grep -P -o "(?<=(\/volume1\/torrents\/complete\/))(Movie|TV)") #finds the first instance of "movie" or "tv" in the filepath of the input
test -z "$ARG_LABEL" && ARG_LABEL="N/A" #test for empty label in case of error or no label given in deluge

# my filebot amc command:
filebot -script fn:amc --output "/volume2/video/" --action copy --conflict auto -non-strict --log-file "/volume2/video/logs/amc.log" --def ignore=".*\.iso" minFileSize=0 minLengthMS=0 subtitles=en skipExtract=n extractFolder="/volume1/torrents/temp/" deleteAfterExtract=n clean=y unsorted=y music=y artwork=y excludeList="/volume2/video/logs/filebotExclude.txt" ut_dir="$ARG_PATH" ut_kind="multi" ut_title="$ARG_NAME" ut_label="$ARG_LABEL"
imp4ler
New User
New User
Posts: 1
Joined: Sun Dec 19, 2021 10:07 pm

Re: Execute Plugin and Labels

Post by imp4ler »

Or just

Code: Select all

#!/usr/bin/env python
# coding: utf

label_conf_path = '/home/username/.config/deluge/label.conf'

import sys
import json

torrent_id = sys.argv[1]

with open(label_conf_path, 'r') as f:
    contents = f.read()
contents = contents.split('"torrent_labels":')[1][:-1]
labels = json.loads(contents)

if torrent_id in labels:
    mine_to_filebot_label_map = {
        'sonarr': 'tv',
        'radarr': 'movie',
        'games':  'other'
        }
    print( mine_to_filebot_label_map.get(labels[torrent_id], labels[torrent_id]) )
else:
    print( 'N/A' )
and in bash just

Code: Select all

ARG_LABEL=`python /home/username/bin/label.py "$ARG_ID"`
or something.
Post Reply