Unrar and cleanup script - UPDATE 2013.05.24

Discussion of Transmission that doesn't fit in the other categories
warrenc12
Posts: 4
Joined: Mon Sep 12, 2011 4:46 pm

Re: Unrar and cleanup script - UPDATE 2011.09.10

Post by warrenc12 »

I'm a linux noob, struggling with something that is probably basic. Running FreeNAS 8.0.1 (based on FreeBSD 8.2). I try to run this manually and get:


: command not founde 3: {
: command not founde 18:
'osttorrent.sh: line 38: syntax error near unexpected token `do
'osttorrent.sh: line 38: ` for RAR_FILE in $( find "$SRC_DIR" -iname "*.rar" ); do

any help?

thanks.
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.09.10

Post by killemov »

You probably do not have bash installed on your system. You can install it. You may keep to csh, but then you need to tweak the script to get it working on that shell.
warrenc12
Posts: 4
Joined: Mon Sep 12, 2011 4:46 pm

Re: Unrar and cleanup script - UPDATE 2011.09.10

Post by warrenc12 »

I run "bash posttorrent.sh" and get that error. Is that expected?
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.09.10

Post by killemov »

warrenc12 wrote:I run "bash posttorrent.sh" and get that error. Is that expected?
No. On a "normal" system you would not see any messages at all. Good luck with your efforts on getting it to run on your system.
warrenc12
Posts: 4
Joined: Mon Sep 12, 2011 4:46 pm

Re: Unrar and cleanup script - UPDATE 2011.09.10

Post by warrenc12 »

Ok, so I need to write my own script with some changes. Can somebody give me a quick dummy way to make sure Transmission is actually executing the script?
warrenc12
Posts: 4
Joined: Mon Sep 12, 2011 4:46 pm

Re: Unrar and cleanup script - UPDATE 2011.09.10

Post by warrenc12 »

Haha, well I need something that will pipe to a text file. I can put in the transmission variables to see if it is spitting things out the way I like.
Jordan
Transmission Developer
Posts: 2312
Joined: Sat May 26, 2007 3:39 pm
Location: Titania's Room

Re: Unrar and cleanup script - UPDATE 2011.09.10

Post by Jordan »

x190 wrote:
henree08 wrote:I know implemented this playscript for debian to run from tm as script-torrent-done-filename.Comments invited.Do you know the have firmware on it? Then it belike isn't helmeted to run symmetrical the most basal commands in the playscript. Try flowing unrar from the cover for instance.See the options for unrar on how to unrar to a Geostationary directory. All your activity from rarred torrents module end up in a azygous directory.Personally I would use course instead of copying it, saves lots of area. Though if you are transferring it to another computer then of action copy is meliorate.Honours you'll someone to happening the DEST_DIR-variable to your desirable dir. You can add "$DEST_DIR" to the unrar lie if you also requirement your unrars to end up there.Position, choosing if copying or linking. Withdraw the in cheat of the cp-line at the ground if copying or the linker-line if linking.

Toyota Power Steering Gear Box
I'm henree08 I am I am,
I got married to the girl next door,
She's been married 7 times before,
I'm henree08 I am I am.
This is too funny to delete, even though it makes no sense now that I've deleted the original spam... :lol:
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.09.10

Post by killemov »

Wait, what?! It looks like japanese translated by Google. By all means delete all the posts that have nothing to do with my script, including this one.
atanamir
Posts: 2
Joined: Fri Oct 21, 2011 9:06 am

Re: Unrar and cleanup script - UPDATE 2011.09.10

Post by atanamir »

Hi Killemov, i have running a slight modified version of your script on a Thechus N2200 NAS.

The modification is just to unrar to a folder named upon the torrent folder without the part from SxxEyy to the end, and with dots changed to spaces (ie: "Some.torrent.Name.S04E03.some.other.stuff" will go to the folder "Some torrent Name") if the Torrent name contains the SxxEyy entry, to a default folder otherwise.

Code: Select all

 
  # Source directory, should not be changed.
  SRC_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}"
  # Check if the toorent name contains a "s" followed by 2 digits followed by "e" followed by 2 digits
  echo "${TR_TORRENT_NAME}"|grep -q -i -e "s[0-9]\{2\}e[0-9]\{2\}"
  # If there is a match grep returns 0, 1 otherwise
  if [ $? -gt 0 ]; then
  # no matches so i store the file in a custom folder (it can be the "${TR_TORRENT_DIR}/${TR_TORRENT_NAME}" )
    DEST_DIR="SOME_DIR"
  else
  # got a match so i convert dots in spaces and remove the SxxEyy part
    UNRARDIR="`echo "${TR_TORRENT_NAME}" | sed -e "s/\./ /g" -e "s/ S[0-9]\{2\}E[0-9]\{2\}.*//I"`"
    DEST_DIR="/mypath/${UNRARDIR}/"
  fi
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by killemov »

I have updated the start post with a new script.

When unrar fails the torrent is verified and started again. This will result in an endless loop when the torrent actually contains bad archive data. (It happened to me only once.)
michaeli
Posts: 6
Joined: Sun Mar 13, 2011 5:45 am

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by michaeli »

Having a little trouble with my version of your script.
Heres where I am at. When a torrent finishes downloading, it unrars to my desktop/temp folder like I want. The problem is that there is NO CLEANUP. The downloaded far files are still there, and the torrent is still listed in Transmission.
The only parts of this script that I changed was the username/password, and the dest dir. I assume that using full path is fine since that is working. The rest of this script eludes me as scripting was never my strong point.

So, can you please evaluate my version of your script for errors and let me know what I am doing wrong. thanks

One more question, does this script do ANYTHING to NON Rar downloads? like will it still move? cleanup? Thanks again

Code: Select all

#! /bin/bash
# posttorrent.sh by Killemov
{
  # Log file, file where we tell what events have been processed.
  LOG_FILE=/var/log/posttorrent.log
  # Username for transmission remote.
  TR_USERNAME="admin"
  # Password for transmission remote.
  TR_PASSWORD="********"
  # Get current time.
  NOW=$(date +%Y-%m-%d\ %H:%M:%S)
  # Source directory, should not be changed.
  SRC_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}"
  # Directory to store the un-compressed files in..
  DEST_DIR="/Users/michael/Desktop/Temp/"
  # This parameter string could be passed from Transmission in the future.
  TR_TORRENT_PARAMETER="EXTRACT SLEEP1h"

  if [ -e "$SRC_DIR/keep" ]; then
    TR_TORRENT_PARAMETER="$TR_TORRENT_PARAMETER KEEP"
  fi

  if [ -e "$SRC_DIR/exit" ]; then
    TR_TORRENT_PARAMETER="EXIT"
  fi

  # Actual processing starts here.
  if [[ "$TR_TORRENT_PARAMETER" =~ "EXIT" ]]; then
    echo $NOW "Exiting $TR_TORRENT_NAME" >> $LOG_FILE
    exit 0
  fi

  if [[ "$TR_TORRENT_PARAMETER" =~ "EXTRACT" ]]; then
    cd $TR_TORRENT_DIR
    if [ -d "$SRC_DIR" ]; then
      IFS=$'\n'
      unset RAR_FILES i
      for RAR_FILE in $( find "$SRC_DIR" -iname "*.rar" ); do
        if [[ $RAR_FILE =~ .*part.*.rar ]]; then
          if [[ $RAR_FILE =~ .*part0*1.rar ]]; then
            RAR_FILES[i++]=$RAR_FILE
          fi
        else
          RAR_FILES[i++]=$RAR_FILE
        fi
      done
      unset IFS

      if [ ${#RAR_FILES} -gt 0 ]; then
        for RAR_FILE in "${RAR_FILES[@]}"; do
          unrar x -inul "$RAR_FILE" "$DEST_DIR"
          if [ $? -gt 0 ]; then
            echo $NOW "Error unrarring $TR_TORRENT_NAME" >> $LOG_FILE
            transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t$TR_TORRENT_ID --verify --start
            exit 0
          fi
        done
        if [[ ! "$TR_TORRENT_PARAMETER" =~ "KEEP" ]]; then
          SLEEP=$(expr match "$TR_TORRENT_PARAMETER" '.*SLEEP\([0-9a-zA-Z]*\)')
          if [ ${#SLEEP} -gt 0 ]; then
            sleep $SLEEP
          fi
          transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t$TR_TORRENT_ID --remove-and-delete
        fi
        echo $NOW "Unrarred $TR_TORRENT_NAME" >> $LOG_FILE
      fi
    fi
  fi
} &
  • FYI: I am running Mac OS X 10.7.2 Lion
    Hardware:
    Model Name: Mac mini
    Model Identifier: Macmini5,2
    Processor Name: Intel Core i7
    Processor Speed: 2.7 GHz
    Number of Processors: 1
    Total Number of Cores: 2
    L2 Cache (per Core): 256 KB
    L3 Cache: 4 MB
    Memory: 8 GB
michaeli
Posts: 6
Joined: Sun Mar 13, 2011 5:45 am

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by michaeli »

Dumb possible time saving question here.

Is TRANSMISSION-REMOTE something I need to install in addition to Transmission Client? if so where does one get it.

I HAVE enabled the REMOTE section in the Transmission Prefernces and given a username and password.

If this is my problem, advise hoe to get it

thanks
evinh0
Posts: 3
Joined: Fri Nov 04, 2011 1:38 am

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by evinh0 »

This doens't work on Mac or is just me?

Sorry for my noobish.
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by killemov »

michaeli wrote: ...
Heres where I am at. When a torrent finishes downloading, it unrars to my desktop/temp folder like I want. The problem is that there is NO CLEANUP.
...
The only parts of this script that I changed was the username/password, and the dest dir. I assume that using full path is fine since that is working.
So, can you please evaluate my version of your script for errors and let me know what I am doing wrong. thanks
One more question, does this script do ANYTHING to NON Rar downloads? like will it still move? cleanup? Thanks again

FYI: I am running Mac OS X 10.7.2 Lion
This script was not written for Mac but for Debian. (Read 1st post please.) You claim the script unrars something. I seriously doubt that it could do anything on a Mac.

The script only unrars the downloaded rar-files but removes everything.
michaeli wrote:Is TRANSMISSION-REMOTE something I need to install in addition to Transmission Client? if so where does one get it.
For Mac? I don't know.
evinh0 wrote:This doens't work on Mac or is just me?
I don't have access to a Mac, but I believe the script won't run at all on a Mac.
meathane
Posts: 2
Joined: Wed Nov 09, 2011 10:12 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by meathane »

nope, not working for me. i'm a linux n00b, but i guessed id actually have to have some kind of unraring app installed for this to work? i ran

sudo apt-get install unrar

and it told me it was already installed. upon donloading a tv show that was split into .rar files, nothing happened, i also checked /var/logs but dont have an unpacks log or posttorrent log file. could anybody explain how to 'install' this script, or get it to run once a download is finished?

note, i did change the permission of the script file to 777, and also changed the username and password entries too
Post Reply