Transmission - Script to move completed downloads to directories, or how to create script?

  • I'm sure a script is already out there, but have no luck with Googling. I just want the script to monitor the folder, and once it completes, move it to to correct path, either Movies or TV. I do not want Transmission to download to the Movie/TV Folder, I want it to complete, and then move it.


    At the very least, what type of script is used. Is it Python? I have no idea, but wouldn't mind learning a thing or 2 and writing it myself or adjusting an existing script.

    • Offizieller Beitrag

    When transmission finishes a torrent it passes the following environmental variables to the done script


    TR_TORRENT_DIR (example /media/7f2d80ba-2a7c-4708-b601-673b304243fa/downloads)
    TR_TORRENT_NAME (example Arrow.S04E16.HDTV.x264-LOL)
    TR_TORRENT_ID (this is the numeric id that gets displayed at transmission-remote -l), is a number example 15)


    With those vars you can do whatever you want either by bash shell, php, or using the transmission api using transmission-remote binary.
    You can get the id by executing transmission-remote localhost:9091 -n admin:password -l
    Example (this is dirty, i'll move the file when is finished an i'll probably report an error in the webUI that data went missing)


    Bash
    #!/bin/bash 
    
    
    destinationPath="/media/7f2d80ba-2a7c-4708-b601-673b304243fa/MySeries/"
    mv "${TR_TORRENT_DIR}"/"${TR_TORRENT_NAME}" "${destinationPath}"


    this other for example will use the transmission-remote binary using API, the torrent will be kept in transmission seeding but at a different destination


    Bash
    #!/bin/bash 
    
    
    destinationPath="/media/7f2d80ba-2a7c-4708-b601-673b304243fa/MySeries/"
    transmission-remote localhost:9091 -n admin:password -t "${TR_TORRENT_ID}" --move "${destinationPath}"


    Now testing this is a PITA for a person that doesn't know scripting would be waiting every time for the torrent to finish to watch the script doing the job. So your script would have to look like this


    Bash
    #!/bin/bash 
    
    
    TR_TORRENT_DIR=${TR_TORRENT_DIR:-$1}
    TR_TORRENT_NAME=${TR_TORRENT_NAME:-$2}
    TR_TORRENT_ID=${TR_TORRENT_ID:-$3}
    destinationPath="/media/7f2d80ba-2a7c-4708-b601-673b304243fa/MySeries/"
    
    
    transmission-remote localhost:9091 -n admin:password -t "${TR_TORRENT_ID}" --move "${destinationPath}"


    So now you can test your script without waiting for transmission to finish a job, you go to the folder where the script is then you executed like this


    ./myscript "/media/7f2d80ba-2a7c-4708-b601-673b304243fa/downloads" "Arrow.S04E16.HDTV.x264-LOL" "14"


    The script will pass the positional arguments (path [1], folder name [2] and id [3]) to the expected transmission variables.

  • Hi

    I'm struggling with a simple script for Transmission


    I use OMV 7, plugin Compose, docker Transmission


    Transmission does not run the script, in any way at all


    In "script-torrent-done-filename" i pointed out both the full path and the short ones - there is no effect


    Code: path options
     "script-torrent-done-filename": "/config/scrypt_transmission.sh",
     "script-torrent-done-filename": "/srv/dev-disk-by-uuid-c5f538f7-67a3-4989-9054-9e4bb0f609ad/appdata/transmission/config/scrypt_transmission.sh",


    Code: ACL
    $ getfacl scrypt_transmission.sh
    # file: scrypt_transmission.sh
    # owner: root
    # group: users
    user::rwx
    user:appuser:rwx
    user:gobanow:rwx
    group::rwx
    mask::rwx
    other::---


    the script is located in the config folder along with the settings.json file


    I added the #DEBUG line, but it does not reach it)) it just won't start, the file scrypt_transmission.sh.log is not being created


    The script is run manually over ssh on behalf of the "appuser" user (docker belongs to the "appuser" user).



    maybe the problem is in the container? but torrents download well



    in which direction should I look?

    Am I probably missing some little thing?


    the version of Compose and Transmission are up to date


    thanks

  • Host side paths can not be seen by a container unless there is a volume defining the linkage between inside and outside the container.

    --
    Google is your friend and Bob's your uncle!


    OMV AMD64 7.x on headless Chenbro NR12000 1U 1x 8m Quad Core E3-1220 3.1GHz 32GB ECC RAM.

  • What is $PWD when the script is to be called? Your script uses $PWD ./scrypt_transmission.sh, but are you really were you need to be at that moment? Is the creation of that log the only way you're determining if the script is being called? Shoot... is the option in transmission enabled?

  • Host side paths can not be seen by a container unless there is a volume defining the linkage between inside and outside the container.

    Yes, I understand, but is "config" specified correctly in the container? And the script is inside the folder /config/scrypt_transmission.sh


    Is there a problem with this option?


    Code
    "script-torrent-done-filename": "/config/scrypt_transmission.sh"


    But the path is specified in the container:


    Code
    - /srv/dev-disk-by-uuid-c5f538f7-67a3-4989-9054-9e4bb0f609ad/appdata/transmission/config:/config
  • These paths have no meaning inside the container:


    dir_films="/srv/dev-disk-by-uuid-adf7f6ad-7293-40a5-ae37-5fcd81cd72af/media/Films/"
    dir_serials="/srv/dev-disk-by-uuid-adf7f6ad-7293-40a5-ae37-5fcd81cd72af/media/Serials/"

    --
    Google is your friend and Bob's your uncle!


    OMV AMD64 7.x on headless Chenbro NR12000 1U 1x 8m Quad Core E3-1220 3.1GHz 32GB ECC RAM.

  • Wait, the script calls itself without any flags. Are you experiencing recursion?


    What is $PWD when the script is to be called? Your script uses $PWD ./scrypt_transmission.sh, but are you really were you need to be at that moment?

    yes, I am really here if I run the script manually from the console


    if I specify the full path, the script is also manually started


    Code
    $ pwd
    /srv/dev-disk-by-uuid-c5f538f7-67a3-4989-9054-9e4bb0f609ad/appdata/transmission/config
    $ /srv/dev-disk-by-uuid-c5f538f7-67a3-4989-9054-9e4bb0f609ad/appdata/transmission/config/scrypt_transmission.sh


    Zitat

    Is the creation of that log the only way you're determining if the script is being called? Shoot... is the option in transmission enabled?

    I don't know how else to check(



    Shoot... is the option in transmission enabled?


    Yes, if that's what you mean


    Code
        "script-torrent-done-enabled": true,
        "script-torrent-done-filename": "/config/scrypt_transmission.sh",


    Wait, the script calls itself without any flags. Are you experiencing recursion?

    but I didn't understand

    this, I still don't get to the inside of the script to deal with them in practice, if that's what you're talking about)

  • These paths have no meaning inside the container:


    dir_films="/srv/dev-disk-by-uuid-adf7f6ad-7293-40a5-ae37-5fcd81cd72af/media/Films/"
    dir_serials="/srv/dev-disk-by-uuid-adf7f6ad-7293-40a5-ae37-5fcd81cd72af/media/Serials/"


    I have not reached the inside of the script, so far I am solving the problem only with its launch)

    thank you for this moment, I will take into account, I will fix the path on "/media/Films/" as specified in the container

  • yes, I am really here if I run the script manually from the console

    But you're not the one executing it, transmission is.


    but I didn't understand

    this

    You've stated that script is named scrypt_transmission.sh You have listed that the first line of that script is ./scrypt_transmission.sh &>./scrypt_transmission.sh.log When the script is called, and the $PWD is that of the scripts location, the script will call itself over and over and over... I don't see how it can work with that file name unless the $PWD is _NOT_ the same. Here's the most probable options:


    A. You've stated the wrong filename.


    B. Transmission's $PWD is the same as the script when Transmission calls it, putting Transmission or at least 1 thread into an infinite loop until the stack is smashed.


    C. Transmission watches its child processes and babysits them.


    D. Transmission $PWD is not in the same directory as the script.


    Excluding A, I'm guessing it's either B or D


    Replace that top line with this line, see if that helps:

    exec &> >(tee "./scrypt_transmission.sh.log")

  • B. Transmission's $PWD is the same as the script when Transmission calls it, putting Transmission or at least 1 thread into an infinite loop until the stack is smashed.

    yes, most likely there was this option!)


    olduser thank you so much for your time!


    the script has started and is working)


    I changed that line as you advised


    maybe it will be useful to someone (it was enough for my needs) - a simple script for Transmission (I put the download in the "Serials" folder by default, but if the "file" is downloaded, the script will move it to the "Films" folder)



    olduser and gderf thanks again

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!