Transmission post-processing script

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
devster
Posts: 417
Joined: 06 Jun 2017, 22:56

Transmission post-processing script

Post by devster »

Hello all, below is my script for transmission post-processing:

Code: Select all

#!/bin/bash -xu

# Input Parameters
TR_APP_VERSION="$TR_APP_VERSION"
TR_TIME_LOCALTIME="$TR_TIME_LOCALTIME"
TR_TORRENT_HASH="$TR_TORRENT_HASH"
TR_TORRENT_ID="$TR_TORRENT_ID"

ARG_PATH="$TR_TORRENT_DIR/$TR_TORRENT_NAME"
ARG_NAME="$TR_TORRENT_NAME"
ARG_LABEL="N/A"

# Configuration
CONFIG_OUTPUT="/mnt/antares/Media"

if [[ "$TR_TORRENT_DIR" =~ ^/mnt/usbhdd.* ]]
then
    exit 0
fi

# ignore if already symlinked
LINKS=($(find $ARG_PATH -type l))
if [[ ${#LINKS[@]} -gt 0 ]]
then
    exit 0
fi

transmission-remote -t ${TR_TORRENT_ID} -S

if [[ "$TR_TORRENT_DIR" =~ ^/mnt/bellatrix/downloads/tv_shows.* ]]
then
    /usr/bin/filebot -script fn:amc --action keeplink --output "$CONFIG_OUTPUT" --conflict skip \
        --filter '!readLines("/mnt/antares/scripts/tv_excludes.txt").contains(n)' \
        -non-strict --log-file amc.log --def subtitles=en artwork=y excludeList=".excludes" \
        ut_dir="$ARG_PATH" ut_kind="multi" ut_title="$ARG_NAME" ut_label="$ARG_LABEL" \
        exec="chmod 664 {quote file} ; docker exec <container> curl -s -w '\n' 'http://localhost:8081/api/v1/<api_key>?cmd=show.refresh&tvdbid={info.id}'" \
        --def @/mnt/antares/scripts/pushover.txt \
        --def movieFormat=@/mnt/antares/scripts/movieFormat.groovy \
        --def seriesFormat=@/mnt/antares/scripts/seriesFormat.groovy
else
   /usr/bin/filebot -script fn:amc --action keeplink --output "$CONFIG_OUTPUT" --conflict skip \
        --filter '!readLines("/mnt/antares/scripts/movie_excludes.txt").contains(n)' \
        --log-file amc.log --def subtitles=en artwork=y excludeList=".excludes" \
        ut_dir="$ARG_PATH" ut_kind="multi" ut_title="$ARG_NAME" ut_label="$ARG_LABEL" \
        exec="chmod 664 {quote file}" \
        --def @/mnt/antares/scripts/pushover.txt \
        --def movieFormat=@/mnt/antares/scripts/movieFormat.groovy \
        --def seriesFormat=@/mnt/antares/scripts/seriesFormat.groovy
fi

transmission-remote -t ${TR_TORRENT_ID} -s
Now I believe the path filters can definitely be optimized but I'm struggling to find an easier way. Suggestions?

Also I wanted to ask if it's possible to do something like the following for the exec script:

Code: Select all

# instead of
--def exec="chmod 664 {quote file} ; docker exec <container> curl -s -w '\n' 'http://localhost:8081/api/v1/<api_key>?cmd=show.refresh&tvdbid={info.id}'" 

# using
--def exec="/mnt/antares/scripts/after_rename.sh {quote file} {info.id}"
and inside after_rename.sh

Code: Select all

#!/bin/bash -xu
chmod 664 "${1}"
docker exec <container> curl -s -w "\n" "http://localhost:8081/api/v1/<api_key>?cmd=show.refresh&tvdbid=${2}"
Thanks.
Last edited by devster on 17 Nov 2017, 18:45, edited 1 time in total.
I only work in black and sometimes very, very dark grey. (Batman)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Transmission post-processing script

Post by rednoah »

Yes, you can definitely call your own scripts. The --def exec template will yield a String, and that String is executed just as if you typed it yourself in the console.

I highly recommend using custom scripts in the --def exec to make the command-line call as simple as possible and make the custom script testable without running the amc script.
:idea: Please read the FAQ and How to Request Help.
devster
Posts: 417
Joined: 06 Jun 2017, 22:56

Re: Transmission post-processing script

Post by devster »

Thanks for the suggestion, I'm in the process of writing one.

Is there a binding for the base folder for a tv show? What I'd be looking for is a reliable way to obtain e.g. /mnt/antares/Media/TV Shows/No Ordinary Family (2010) from this output:

Code: Select all

/mnt/antares/Media/TV Shows/No Ordinary Family (2010)/Season 1/No Ordinary Family - S01E14 - No Ordinary Double Standard [360p XviD - 2.0 MP3 - HDTV]-LOL.eng.srt
I only work in black and sometimes very, very dark grey. (Batman)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Transmission post-processing script

Post by rednoah »

{f.dir.dir} should give you the series folder in this case.
:idea: Please read the FAQ and How to Request Help.
Post Reply