Script Torrent Done Synology

Ask for help and report issues not specific to either the Mac OS X or GTK+ versions of Transmission
Post Reply
larza
Posts: 5
Joined: Tue Oct 23, 2012 6:27 pm

Script Torrent Done Synology

Post by larza »

Hi,

I have tried to use a script that unpacks and sorts my downloaded torrents and should be triggered after a download is complete. However I haven´t managed and was hoping to get some assistance. :)

I have changed the settings.json as follows:

Code: Select all

"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/volume1/transmission/milhouse.sh",
Nothing happens and I cannot locate the logfile, it is not in /var/log as I would assume after searching the forums. Anyone know where it might be on synology? I use the version provided by synocommunity.com, 2.72-1.
larza
Posts: 5
Joined: Tue Oct 23, 2012 6:27 pm

Re: Script Torrent Done Synology

Post by larza »

No answers here.. :) So I made a workaround, for future reference and If anyone else experience the same issue. Please find it at: viewtopic.php?f=1&t=13981
larza
Posts: 5
Joined: Tue Oct 23, 2012 6:27 pm

Re: Script Torrent Done Synology

Post by larza »

Still having trouble getting Transmission to launch a script after completed download.

I have changed the settings.json as follows:

Code: Select all

"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/volume1/transmission/milhouse.sh",
Script is not launched. I run Transmission prepacked from Synocommunity, version 2.72-1.

Playing around a bit I tried to obtain a logfile, so therefore shut down Transmission in package center and launched it through CLI instead, with command:

Code: Select all

./transmission-daemon -g "/volume1/@appstore/transmission/var" -e "/volume1/transmission/logtrans.log"
This to trigger log file being created. The path for settings file is the same.. To my surprise the script was all of a sudden launched upon completed download?!

This leads to a few questions, how can it be that the script is not launched when app is started through package center with the same settings.json? Anyone know where to find what command is being used when launching an app through package center? Very strange.. :)
JJTagy
Posts: 40
Joined: Sun Jul 29, 2012 3:15 am

Re: Script Torrent Done Synology

Post by JJTagy »

Could it be an execution permission issue with the user you run the daemon with?
larza
Posts: 5
Joined: Tue Oct 23, 2012 6:27 pm

Re: Script Torrent Done Synology

Post by larza »

JJTagy wrote:Could it be an execution permission issue with the user you run the daemon with?
It seems like you are correct! :)

I finally found a solution for using scripts with transmission on synology.

The issue seems to be permissions, as mentioned in several other forums.. Even though I tried setting "Transmission" as owner it hasn´t helped, might be something with rights connected to running scripts. However, if I run Transmission as root, everything works fine.

Took me a while though to find out how applications are triggered through Package center. What you should to is:

1. Stop Transmission in package center
2. Edit file /var/packages/transmission/scripts/start-stop-status, change to RUNAS="root".
3. Launch Transmission again.

Now, if you have settings.json set to trigger a script it works!
markozupancic
Posts: 1
Joined: Sun May 05, 2013 5:38 pm

Re: Script Torrent Done Synology

Post by markozupancic »

After upgrading to DSM 4.2 this did not work for me anymore.

Everything worked if I run it manually as a root, but when run automatically after transmission downloaded file, there was an error:
****************************************************************************************************************************
ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Error grabbing grapes -- /volume1/@appstore/filebot/data/grape/grapes/resolved-caller-all-caller-working38.xml (Permission denied)

java.lang.RuntimeException: Error grabbing grapes -- /volume1/@appstore/filebot/data/grape/grapes/resolved-caller-all-caller-working38.xml (Permission denied)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
...

****************************************************************************************************************************

I also did "chmod -R 775 grape" on folder, but did not help.

I had to change USER="transmission" -> USER="root" as well.

This is what the beginning of "start-stop-status" file now looks like.

****************************************************************************************************************************
#!/bin/sh

# Package
PACKAGE="transmission"
DNAME="Transmission"

# Others

INSTALL_DIR="/usr/local/${PACKAGE}"
PATH="${INSTALL_DIR}/bin:/usr/local/bin:/bin:/usr/bin:/usr/syno/bin"
USER="root"
TRANSMISSION="${INSTALL_DIR}/bin/transmission-daemon"
PID_FILE="${INSTALL_DIR}/var/transmission.pid"
RUNAS="root"


start_daemon ()
...

****************************************************************************************************************************


And this is the "TransmissionFilebot.sh" script that I run.
****************************************************************************************************************************
#!/opt/bin/bash

#
#Transmission script
#Postprocess download script
#http://www.filebot.net/script.html
#http://www.filebot.net/scripts/
#

filebot -script "/volume1/MyMultimedia/Tools/Filebot/TransmissionScripts/amc.groovy" "$TR_TORRENT_DIR/$TR_TORRENT_NAME" --output "/volume1/MyMultimedia/" --encoding windows-1250 --action copy --conflict skip -non-strict -no-analytics --log all --log-file "/volume1/MyMultimedia/Transmission/filebotDefaultLog.txt" --def subtitles=sl artwork=y xbmc=xbmc plex=localhost gmail=username:password mailto=whateveryouremailis@whateveryouremailis.com pushover=pushoverUserID >> /volume1/MyMultimedia/Transmission/filebotLog.txt

echo "Downloaded \"$TR_TORRENT_NAME\" in directory \"$TR_TORRENT_DIR/$TR_TORRENT_NAME\" on $TR_TIME_LOCALTIME" >> /volume1/MyMultimedia/Transmission/transmissionLog.txt

****************************************************************************************************************************
mad_cow
Posts: 1
Joined: Thu May 09, 2013 11:09 am

Re: Script Torrent Done Synology

Post by mad_cow »

I had similiar problems as you have, but solved it in a different (more upgrade-proof way)
Specifically, I wanted to run the renamer in Couchpotato. But it seems that the renamer was not running after finishing a download, probably due to similiar issues as you described here.

Instead of altering the transmission package I simply wrote a script that is started by the synology taskplanner. It checks every X hours to see if new downloads have been finished

a fair warning:
my script contains a portion that clears my download directory. I have disabled it in the code below as a precaution. As always use it only if you really know what you're doing and, of course I do not take any responsibility for any possible screw ups due to this script.

Here is my script

Code: Select all

#!/bin/sh

##  Script for tranmission on synology
##  Problems:
##  * The custom package of tranmission on synology machines does not run scripts after completion [1]
##  * Couchpotato Server does not appear to activate the postprocessing once a torrent has finished downloading
##
##  Solution: 
##  * In the synology taskplanner I set up a task to run every 2 hours to run this script
##
##  Script:
##  1) check which torrents are finished downloading
##  2) remove completed torrents from transmission
##  3) run Couchpotato renamer if completed torrents are found
##  4) If there are no torrents in torrent list, clean up download directory
##     !!This option is disabled by default, because it uncareful usage may delete all data!! 
##
##  Prerequisites:
##  * Synology machine (currently tested on Synology DS411j, DSM 4.2-3211)
##  * Transmission & Couchpotato Server (SPK's obtained from SynoCommunity repository)
##  * Enable Couchpotato Renamer, but set so that it never runs [3]
##
##  Warning: Regarding 4)
##  * My transmission downloads to a temporary directory. Movies that have finished downloading are
##    moved to $DOWNLOADDIR. Thus if all movies have been processed this folder contains no more movies and can be safely deleted
##  * the Couchpotato renamer will need some time to process. Therefor do not set up the taskplanner to run to often. Every 1 or 2 hours is sufficient
##
##  references: 
##  [1] https://forum.transmissionbt.com/viewtopic.php?f=2&t=13970
##  [2] https://forum.transmissionbt.com/viewtopic.php?f=2&t=11468
##  [3] https://couchpota.to/forum/viewtopic.php?f=5&t=1631&sid=af6538d4f17f23081fd5f46e9f889db1#p7330
##
## Forum Post on this script can be found:
## https://forum.transmissionbt.com/viewtopic.php?f=2&t=13970&p=64792#p64792
##
##  date: 9 may 2013

# Inputs
USER=tranmissionuser
PASSWORD=transmissionpassword
TRANSMISSION="/usr/local/transmission/bin/transmission-remote --auth "$USER":"$PASSWORD
COUCHPOTATOURL=localhost
COUCHPOTATOPORT=5050
COUCHPOTATOAPI=couchpotatoapi
DOWNLOADDIR="/volume1/Download/Movies"

# Initialize
MARKFORREMOVE=""
RUNCOUCHPOTATOPOSTPROCESS="FALSE"
echo "++++++ CHECK TORRENTS & RUN COUCHPOTATO RENAMER IF NEEDED +++++"

# Check torrentlist for completed torrents
TORRENTLIST=`$TRANSMISSION --list | sed -e '1d;$d;s/^ *//' | cut -s -d" " -f 1 | sed "s/[^0-9]//"`

for TORRENTID in $TORRENTLIST
  do
  DL_COMPLETED=`$TRANSMISSION --torrent $TORRENTID --info | grep "Percent Done: 100%"`
  STATE_STOPPED=`$TRANSMISSION --torrent $TORRENTID --info | grep "State: Stopped\|Finished\|Idle"`
  if [ "$DL_COMPLETED" != "" ] && [ "$STATE_STOPPED" != "" ]; then
    echo "Torrent #$TORRENTID: completed."
    MARKFORREMOVE=$MARKFORREMOVE" "$TORRENTID
    RUNCOUCHPOTATOPOSTPROCESS="TRUE"
  else
    echo "Torrent #$TORRENTID: not completed. Ignoring."
  fi
  done

# Remove completed torrents from list
if [ "$MARKFORREMOVE" != "" ]; then
  echo "Remove Torrents: "$MARKFORREMOVE
fi  
for TORRENTID in $MARKFORREMOVE
  do  
  $TRANSMISSION --torrent $TORRENTID --remove
  done

# Activate Couchpotato renamer  
if [ $RUNCOUCHPOTATOPOSTPROCESS == "TRUE" ]; then
  echo Run Couchpotato renamer
  # start couchpotato postprocessing script
  curl http://$COUCHPOTATOURL:$COUCHPOTATOPORT/api/$COUCHPOTATOAPI/renamer.scan/
  printf "\n"
fi

# clean up directory if no torrents in list 
if [ "$TORRENTLIST" == "" ]; then
  echo "No torrents in list: clearing Movie Download folder"
  # Alter This Line if you are ABSOLUTELY SURE about clearing a directory!!!
  echo "rm -r "$DOWNLOADDIR"/*"
fi


echo "++++++++++++++++++++++++++ FINISHED ++++++++++++++++++++++++++"
soulcreeper
Posts: 1
Joined: Sat Aug 02, 2014 9:41 am

Re: Script Torrent Done Synology

Post by soulcreeper »

That looks amazing! I'm definitely gonna use that on mine.

Any chance this can be modified to grab movies only?

I know Transmission on Sinology doesn't take groups, but maybe we can find something that identifies movies? or maybe only torrents from certain sources.
jpancer85
Posts: 1
Joined: Thu Dec 24, 2015 12:08 pm

Re: Script Torrent Done Synology

Post by jpancer85 »

HI,
Script looks interesting! I just stumbled accross it after trying to get Transmission to do exactly what your script should do.

I just wanted to know if you have made any updates to the script since it was written and also if I need to fill out anything in the section:

# Initialize
MARKFORREMOVE=""

I am also a little bit of a noob when it comes to the script programming. Could you clarify how you would need to modify the line:

# Alter This Line if you are ABSOLUTELY SURE about clearing a directory!!!
echo "rm -r "$DOWNLOADDIR"/*"

if I want to use the auto delete feature of the script?

Thank you!
Post Reply