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 »

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 »

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 »

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: 535
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov »

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 »

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 »

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: 535
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov »

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: 535
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov »

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 »

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 »

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: 535
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by killemov »

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 »

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: 535
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2013.05.24

Post by killemov »

Changelog
  • Make sure only FILES with .rar suffix are processed, NOT FOLDERS.
pigr8
Posts: 1
Joined: Tue Jul 09, 2013 4:11 pm

Re: Unrar and cleanup script - UPDATE 2013.05.24

Post by pigr8 »

hi killermov! i was working on your script in order to get a hardlink function if the torrent are not rar files.

i read few post ago that you wrote this:

Code: Select all

if [[ "$TR_TORRENT_PARAMETER" =~ "EXTRACT" ]]; then
    ...
    if [ ${#RAR_FILES} -gt 0 ]; then
        ...
    else
        cp -val $SRC_DIR $DEST_DIR
        echo $NOW "Copied $TR_TORRENT_NAME" >> $LOG_FILE
    fi
fi
i tried to add those lines and if complete a torrent with rar files it extract correctly to my destination folder, if the torrent is a simpli file (exe, mkv, avi, *) it does nothing :(

my challenge was to add a filter option for file with a particular extension (editable maybe, like all video files or all iso files and so on) and if the torrent is a rar folder extract and copy to $DEST_DIR, if is a direct file just hardlink (with cp -val) to $DEST_DIR

no clue so far
Khabel
Posts: 5
Joined: Wed Jul 04, 2012 10:00 pm

Re: Unrar and cleanup script - UPDATE 2013.01.10

Post by Khabel »

killemov wrote:
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

I've added the extra part but the copy fails, possibly due the spaces in the folder name, even though the $SRC_DIR and $DEST_DIR are within quotes e.g. DEST_DIR="${TR_TORRENT_DIR}/Movies/${TR_TORRENT_NAME}/"

The error when I run the copy manually is cp: target `AC3.AVCHD.iCandy' is not a directory
It's chopping the end of the torrent name off

Any ideas?
Post Reply