Unrar and cleanup script - UPDATE 2013.05.24

Discussion of Transmission that doesn't fit in the other categories
GAPP
Posts: 2
Joined: Mon Mar 25, 2013 11:37 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by GAPP » Mon Mar 25, 2013 11:47 pm

Hello,

Script looks really good, but since I'm such a newbie at this I'm a little afraid to implement it before I know a few things.

Can you toggle it, so it doesnt actually delete the rarfiles after the extracting is done? I use a FTP ratio community, so they would get really angry if someone just downloaded the files and delete it right after.

Also, will it extract it in the same folder as the rars are in?

Lastly, I'm using ReadyNAS Ultra 2, I assume it works with it?

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

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov » Wed Mar 27, 2013 7:49 pm

GAPP wrote:Hello,

Script looks really good, but since I'm such a newbie at this I'm a little afraid to implement it before I know a few things.
Yeah, I just finished slapping some lipstick on her. :wink:
Can you toggle it, so it doesn't actually delete the rarfiles after the extracting is done? I use a FTP ratio community, so they would get really angry if someone just downloaded the files and delete it right after.
Sure, just give me your account data and I will edit it for you. (Or put a file named "keep" in the top folder of your torrent. Or find "--remove-and-delete" in the script and replace it with "--remove".)
Also, will it extract it in the same folder as the rars are in?
No, but DEST_DIR="$SRC_DIR" might do the trick.
Lastly, I'm using ReadyNAS Ultra 2, I assume it works with it?
You haven't read the first post or you you have a hard time understanding it, right? But wouldn't that make your initial compliment just a bit ... insincere?

In short: @alln00bs: You need to find some things out for yourselves!

GAPP
Posts: 2
Joined: Mon Mar 25, 2013 11:37 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by GAPP » Thu Mar 28, 2013 1:42 am

You're right. It did come off a little insincere. What I meant was, that I read throughout that people was really pleased with your work, so I assumed it was really good. In reality I'm not the best at this, but I'm trying. I guess I could figure it out with time, but feel like it's better ask instead of doing something stupid.

So its important that the torrents doesnt get removed and the rars get deleted by themselves. I need to do that manually, because some things I download is from there.

Code: Select all

{
    "alt-speed-down": 50, 
    "alt-speed-enabled": false, 
    "alt-speed-time-begin": 540, 
    "alt-speed-time-day": 127, 
    "alt-speed-time-enabled": false, 
    "alt-speed-time-end": 1020, 
    "alt-speed-up": 50, 
    "bind-address-ipv4": "0.0.0.0", 
    "bind-address-ipv6": "::", 
    "blocklist-enabled": true, 
    "blocklist-url": "http://list.iblocklist.com/?list=bt_level1", 
    "cache-size-mb": 200, 
    "dht-enabled": false, 
    "download-dir": "/c/media/BitTorrent", 
    "download-queue-enabled": true, 
    "download-queue-size": 5, 
    "encryption": 1, 
    "idle-seeding-limit": 30, 
    "idle-seeding-limit-enabled": false, 
    "incomplete-dir": "/c/media/BitTorrent/Incomplete", 
    "incomplete-dir-enabled": true, 
    "lazy-bitfield-enabled": true, 
    "lpd-enabled": false, 
    "max-peers-global": 200, 
    "message-level": 1, 
    "open-file-limit": 32, 
    "peer-congestion-algorithm": "", 
    "peer-limit-global": 240, 
    "peer-limit-per-torrent": 60, 
    "peer-port": 51413, 
    "peer-port-random-enabled": 0, 
    "peer-port-random-high": 65535, 
    "peer-port-random-low": 1024, 
    "peer-port-random-on-start": false, 
    "peer-socket-tos": "default", 
    "pex-enabled": true, 
    "pidfile": "/var/run/transmission-daemon.pid", 
    "port-forwarding-enabled": true, 
    "preallocation": 2, 
    "prefetch-enabled": 0, 
    "proxy": "", 
    "proxy-auth-enabled": false, 
    "proxy-auth-password": "", 
    "proxy-auth-username": "", 
    "proxy-enabled": false, 
    "proxy-port": 80, 
    "proxy-type": 0, 
    "queue-stalled-enabled": true, 
    "queue-stalled-minutes": 30, 
    "ratio-limit": 2, 
    "ratio-limit-enabled": true, 
    "rename-partial-files": true, 
    "rpc-authentication-required": false, 
    "rpc-bind-address": "0.0.0.0", 
    "rpc-enabled": true, 
    "rpc-password": "xxxxxxxxxxxxxxxxxx", 
    "rpc-port": 8181, 
    "rpc-url": "/transmission/", 
    "rpc-username": "admin", 
    "rpc-whitelist": "*", 
    "rpc-whitelist-enabled": true, 
    "scrape-paused-torrents-enabled": true, 
    "script-torrent-done-enabled": true, 
    "script-torrent-done-filename": "/c/addons-config/Transmission/email_alert", 
    "seed-queue-enabled": false, 
    "seed-queue-size": 10, 
    "speed-limit-down": 100, 
    "speed-limit-down-enabled": false, 
    "speed-limit-up": 5, 
    "speed-limit-up-enabled": true, 
    "start-added-torrents": true, 
    "trash-original-torrent-files": false, 
    "umask": 0, 
    "upload-limit": 100, 
    "upload-limit-enabled": 0, 
    "upload-slots-per-torrent": 14, 
    "utp-enabled": false, 
    "watch-dir": "/c/media/BitTorrent/sources/", 
    "watch-dir-enabled": 1
}

lewsut
Posts: 3
Joined: Wed Apr 10, 2013 7:16 am

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by lewsut » Wed Apr 10, 2013 7:22 am

I saw mention a manual somewhere on the last 8 pages, for use of the Keep/Exit files and so on. Where does that live?

All I wish to do is unrar when a download finishes (to a new directory), preserve the files for seeding indefinitely (in the complete directory), well until I remove them manually.

I'm sure this can't be hard, I just can't seem to get the required behaviour.

Thanks for your time.

Khabel
Posts: 5
Joined: Wed Jul 04, 2012 10:00 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by Khabel » Thu Apr 11, 2013 1:48 am

If the torrent doesn't need unraring what do I need to add so the file is copied to a different location instead?

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

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov » Sat Apr 13, 2013 1:39 pm

lewsut wrote:I saw mention a manual somewhere on the last 8 pages, for use of the Keep/Exit files and so on. Where does that live?
Start post updated. Use a "keep" control file.
Khabel wrote:If the torrent doesn't need unraring what do I need to add so the file is copied to a different location instead?
:?: The torrent file itself? The content? Some rar-specific files?
The script contains linux commands. Look for information on cp or mv, for example.

Khabel
Posts: 5
Joined: Wed Jul 04, 2012 10:00 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by Khabel » Sat Apr 20, 2013 3:53 am

killemov wrote:The torrent file itself? The content? Some rar-specific files?
The script contains linux commands. Look for information on cp or mv, for example.
Sorry, should have made myself a bit clearer. If the torrent only contains one file e.g. movie.mkv and no rars where abouts in your script would I place the copy command to copy the mkv file to another location?

For example:
if [[ "$TR_TORRENT_PARAMETER" =~ "EXTRACT" ]]; then
do stuff
else
cp -R $SRC_DIR $DEST_DIR
echo $NOW "Copied $TR_TORRENT_NAME" >> $LOG_FILE
fi

lewsut
Posts: 3
Joined: Wed Apr 10, 2013 7:16 am

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by lewsut » Sun Apr 21, 2013 4:32 pm

killemov, Does the Keep file have the same effect as commenting out the transmission-remote --remove-and-delete line?

Edit: I guess not as stuff gets removed keep file or not?

Thanks.

Khabel wrote:Sorry, should have made myself a bit clearer. If the torrent only contains one file e.g. movie.mkv and no rars where abouts in your script would I place the copy command to copy the mkv file to another location?
What I do that seems to work is below, i'm not so good at this kind of thing but like I say works for me and In think it's what you want to do?

Added

else
cp -r "$TR_TORRENT_NAME" "$DEST_DIR"
cp "$TR_TORRENT_NAME" "$DEST_DIR"

Code: Select all

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_HASH --verify --start
            exit 0
          fi
        done
	
		else
		 cp -r "$TR_TORRENT_NAME" "$DEST_DIR"
		 cp "$TR_TORRENT_NAME" "$DEST_DIR"	
		
		 
        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_HASH --remove-and-delete
        fi
        echo $NOW "Unrarred $TR_TORRENT_NAME" >> $LOG_FILE
      fi
    fi
  fi
} &

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

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov » Mon Apr 22, 2013 7:44 am

Khabel wrote:
killemov wrote:The torrent file itself? The content? Some rar-specific files?
The script contains linux commands. Look for information on cp or mv, for example.
Sorry, should have made myself a bit clearer. If the torrent only contains one file e.g. movie.mkv and no rars where abouts in your script would I place the copy command to copy the mkv file to another location?

For example:

Code: Select all

if [[ "$TR_TORRENT_PARAMETER" =~ "EXTRACT" ]]; then
 [i]do stuff[/i]
else
    cp -R $SRC_DIR $DEST_DIR
    echo $NOW "Copied $TR_TORRENT_NAME" >> $LOG_FILE
fi
That could work. Or you could add another keyword to $TR_TORRENT_PARAMETER. I think it would be simpler if you use the copy command within the extract block, but when no rar files were found.

Code: Select all

if [[ "$TR_TORRENT_PARAMETER" =~ "EXTRACT" ]]; then
    ...
    if [ ${#RAR_FILES} -gt 0 ]; then
        ...
    else
        cp -R $SRC_DIR $DEST_DIR
        echo $NOW "Copied $TR_TORRENT_NAME" >> $LOG_FILE
    fi
fi

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

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov » Mon Apr 22, 2013 7:48 am

lewsut wrote:killemov, Does the Keep file have the same effect as commenting out the transmission-remote --remove-and-delete line?

Edit: I guess not as stuff gets removed keep file or not?
Yes, that should work also. But remember: "keep" != "Keep".

lewsut
Posts: 3
Joined: Wed Apr 10, 2013 7:16 am

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by lewsut » Mon Apr 22, 2013 1:04 pm

killemov wrote:Yes, that should work also. But remember: "keep" != "Keep".
My bad! thanks for that.

Dan_Aykroyd
Posts: 2
Joined: Sat Apr 27, 2013 3:31 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by Dan_Aykroyd » Sat Apr 27, 2013 3:41 pm

Hi everybody!

I've been using this script to auto extract torrents after finished:

Code: Select all

#!/bin/bash
formats=(zip rar)
commands=([zip]="unzip -u" [rar]="unrar -o- e")
extraction_subdir='extracted'

torrentid=$TR_TORRENT_ID
torrentname=$TR_TORRENT_NAME
torrentpath=$TR_TORRENT_DIR

log()
{
    logger -t transmission-extractarchives "$@"
}

log "Torrent complete: $@"
cd "${torrentpath}"
for format in "${formats[@]}"; do
    while read file; do
        log "Extracting \"$file\""
        cd "$(dirname "$file")"
        file=$(basename "$file")
        # if extraction_subdir is not empty, extract to subdirectory
        if [[ ! -z "$extraction_subdir" ]] ; then
            mkdir "$extraction_subdir"
            cd "$extraction_subdir"
            file="../$file"
        fi
        ${commands[$format]} "$file"
    done < <(find "$torrentpath/$torrentname" -iname "*.${format}" )
done
What I wonder is, what should I modify in the extraction script to allow it to extract each file to a subfolder? Becase as it is, the "extracted" folder gets messy with all kind of assorted files from every downloaded torrent. I mean:

Example:
I download an abc.rar file
It should extract to extracted\abc\<file 1, file 2, etc>
Instead of (how now does it) extracted\<file 1, file 2, etc>

Thanks!

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

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov » Tue Apr 30, 2013 7:34 am

Please refrain from using this topic for anything other than questions about or suggestions for the script in the first post.

@Dan_Aykroyd: I might have helped you out if you posted this in its own topic.

Dan_Aykroyd
Posts: 2
Joined: Sat Apr 27, 2013 3:31 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by Dan_Aykroyd » Sat May 11, 2013 1:28 am

OK, you've been very helpful, sorry to ask a question from a script that was on this thread and not about your awesome OP script. :roll:

Nvm, I'm using TorrentExpander, I think you all should do the same

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

Re: Unrar and cleanup script - UPDATE 2013.05.24

Post by killemov » Fri May 24, 2013 2:06 pm

Changelog
  • Make sure only FILES with .rar suffix are processed, NOT FOLDERS.

Post Reply