Unrar and cleanup script - UPDATE 2013.05.24

Discussion of Transmission that doesn't fit in the other categories
killemov
Posts: 421
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by killemov » Sat Jul 21, 2012 11:41 am

Khabel wrote:Can you confirm a couple things for me please

Will there be any issues running this on unraid?
This is just a script. If all the commands are there then there will be no problems.
Khabel wrote:Can I move the keep file to the root dir so all torrents are kept?
Why not just comment out the torrent remove command instead?
Khabel wrote:Is it possible to use a sleep parameter so torrents are seeded for a certain period before removing?
The default is 1 hour. If you want to make it configurable, you will have to use a file per torrent as there is no way to pass custom parameters yet.
Khabel wrote:Thanks and great script
You're welcome and spread the word or well .. script.

globalrebel
Posts: 7
Joined: Wed May 16, 2012 2:07 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by globalrebel » Thu Aug 30, 2012 10:26 pm

Don't know if this thread is still watched, but I was wondering . . .

The script looks amazing, and I'm looking to implement it myself here if it can do one thing.

Currently I use FlexGet and have it send my torrents to Transmission with a set directory depending on the type of torrent I have.

If TV : /volume1/tranmission/download/Series/{{Series_Name}}/{{Series_Season}}/{{File_name}}

ex. : /volume1/transmission/download/Series/Mamma and Papa/Season 1/Mama.And.Papa.S1.E01

I would like to have the script take the current directory structure and just move it to a different root directory . .

ex. : /volume1/Video/TV/Series/Mamma and Papa/Season 1/Mama.And.Papa.S1.E01

I was thinking (or better yet told) that I might be able to do something like this. . . (See 5'th group down. Add mkdir and cd lines)

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="username"
  # Password for transmission remote.
  TR_PASSWORD="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="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}/"
  # 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
    mkdir /volume1/$TR_TORRENT_DIR
    cd $/volume1/$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
} &
While I know this will end up making a very long directory under '/Volume1/Video/' it should allow the program to do what I am hoping for . . . correct?

The output will now be . . .
For TV Shows
/Volume1/Video/transmission/download/TV/{{series_name}}/Series_season/File_name

Sorry, I'm not very good at this, but trying my best.

killemov
Posts: 421
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by killemov » Thu Sep 13, 2012 7:51 pm

Hey globalrebel, the added statements (an mkdir and a cd) have nothing to do with where the resulting files will end up. You have to assign a new path to DEST_DIR for that.

Good luck with that ...

ZaPHoN
Posts: 9
Joined: Sun Aug 19, 2012 5:54 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by ZaPHoN » Tue Sep 18, 2012 7:20 pm

How would I add "remove in x days (or seconds)" to this script?
Could someone assist please.

killemov
Posts: 421
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by killemov » Sat Sep 22, 2012 9:40 am

ZaPHoN wrote:How would I add "remove in x days (or seconds)" to this script?
Could someone assist please.
A delay of 1 hour before removing the torrent is in there already using the sleep command. Please read the manual page for sleep. Oh, and make sure transmission is not restarted during the sleep period because you might end up removing an unrelated torrent.

killemov
Posts: 421
Joined: Sat Jul 31, 2010 5:04 pm

Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov » Thu Jan 10, 2013 2:17 pm

Changelog
  • Use TR_TORRENT_HASH instead of TR_TORRENT_ID for referencing torrents. This will ensure the proper torrent is deleted after a restart of the daemon.

ccomly
Posts: 2
Joined: Wed Jan 16, 2013 6:26 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by ccomly » Wed Jan 16, 2013 7:13 pm

I would love a simplified remove when seed complete, "Finished". (just the torrent not the data)
trying to figure out how to do this.

transmission-remote -n user:password -l | grep Finished
will list the current finished seeded torrents.

how do i issue

transmission-remote -n user:password -r "Name of torrent without .torrent"

with the result of the first command input'ed correctly into the "Name of torrent without .torrent"
or if there is a simpler way to do it. Thanks.

blacke4dawn
Posts: 552
Joined: Sun Dec 13, 2009 10:44 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by blacke4dawn » Wed Jan 16, 2013 8:54 pm

ccomly wrote:I would love a simplified remove when seed complete, "Finished". (just the torrent not the data)
trying to figure out how to do this.

transmission-remote -n user:password -l | grep Finished
will list the current finished seeded torrents.

how do i issue

transmission-remote -n user:password -r "Name of torrent without .torrent"

with the result of the first command input'ed correctly into the "Name of torrent without .torrent"
or if there is a simpler way to do it. Thanks.
Quick and crude way, someone could probably improve it a bit:

Code: Select all

transmission-remote -n user:pw -l | grep Finished | awk '{ print $1 }' | xargs -I '{}' transmission-remote -n user:pw -t'{}' -r

ccomly
Posts: 2
Joined: Wed Jan 16, 2013 6:26 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by ccomly » Wed Jan 16, 2013 11:46 pm

blacke4dawn wrote:
ccomly wrote:I would love a simplified remove when seed complete, "Finished". (just the torrent not the data)
trying to figure out how to do this.

transmission-remote -n user:password -l | grep Finished
will list the current finished seeded torrents.

how do i issue

transmission-remote -n user:password -r "Name of torrent without .torrent"

with the result of the first command input'ed correctly into the "Name of torrent without .torrent"
or if there is a simpler way to do it. Thanks.
Quick and crude way, someone could probably improve it a bit:

Code: Select all

transmission-remote -n user:pw -l | grep Finished | awk '{ print $1 }' | xargs -I '{}' transmission-remote -n user:pw -t'{}' -r
thanks a bunch seems to work, also thanks for pointing to xargs and awk.

killemov
Posts: 421
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov » Thu Feb 28, 2013 8:38 am

@cconly, blacke4dawn:
Your solutions have nothing to do with the unrar-and-cleanup script, which runs when a torrent is complete.

In the script there's is the line:

Code: Select all

          transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t $TR_TORRENT_HASH --remove-and-delete
Why not just replace that with:

Code: Select all

          transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t $TR_TORRENT_HASH --remove

blacke4dawn
Posts: 552
Joined: Sun Dec 13, 2009 10:44 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by blacke4dawn » Sat Mar 02, 2013 8:37 am

killemov wrote:@cconly, blacke4dawn:
Your solutions have nothing to do with the unrar-and-cleanup script, which runs when a torrent is complete.

In the script there's is the line:

Code: Select all

          transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t $TR_TORRENT_HASH --remove-and-delete
Why not just replace that with:

Code: Select all

          transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t $TR_TORRENT_HASH --remove
The way he worded it sounded like he wanted them removed when they where done seeding and not "just" done downloading.

dochyde
Posts: 3
Joined: Thu Mar 14, 2013 4:10 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by dochyde » Thu Mar 14, 2013 4:13 pm

I get this error I do not understand why?
Haven't touched the script except edit the log location.

Code: Select all

posttorrent.sh: line 19: syntax error near unexpected token `then'
posttorrent.sh: line 19: `  if [ -e "$SRC_DIR/keep" ]; then'
Anybody knows what's wrong?

dochyde
Posts: 3
Joined: Thu Mar 14, 2013 4:10 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by dochyde » Thu Mar 14, 2013 4:21 pm

I think I found my pb, it's the copy/paste.
I don't understand why people don't simply post the file itself as c/p has so much issues.

I am using SELECT ALL and right click and selecting copy.
Then I go on my Linux terminal using nano and just paste...and apparently there are some bad caracters in the script. :/

Can someone please post the script in a file please.

killemov
Posts: 421
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov » Thu Mar 14, 2013 8:54 pm

Tried it again myself and ... It's just your fingers being twitchy. :evil:

dochyde
Posts: 3
Joined: Thu Mar 14, 2013 4:10 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by dochyde » Thu Mar 14, 2013 9:22 pm

I have not managed to c/p it either with nano or vi without getting errors.

to bad for me I guess.

Thanks for your time. ;)

Post Reply