Unrar and cleanup script - UPDATE 2013.05.24

Discussion of Transmission that doesn't fit in the other categories
Post Reply
boondoklife
Posts: 12
Joined: Tue Oct 25, 2011 4:30 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by boondoklife » Sat Jan 14, 2012 4:25 am

Was reading through the script and it looks interesting, but could you tell me where $TR_TORRENT_ID and $TR_TORRENT_NAME come from? Are these passed to the script from the daemon as parameters some how?

gunzip
Posts: 272
Joined: Wed May 05, 2010 2:12 am

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by gunzip » Sat Jan 14, 2012 8:17 pm

yes those are special environmental variables passed to the script on completion of a torrent. see the wiki for all the listing:

https://trac.transmissionbt.com/wiki/Scripts

they are valid for any script you might use.

dexusno
Posts: 3
Joined: Tue Jan 31, 2012 10:28 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by dexusno » Tue Jan 31, 2012 10:37 pm

Hi!

I'm relatively new to linux scripting, and was wondering if it is possible to get the script to only unrar files IF the file is in a given folder?

I have set up some automation on tv-series download with a watch folder for new .torrent files.. I would like the script to unrar these tv series and movies that end up in the default download dir, but not if I specify another destination dir.

E.g. Everytime my script put a .torrent file in the watch-folder, Transmission downloads the files from that torrent, and puts them in the "/transmission/data" folder. I would like the script to unrar these to another folder, and leave the originals to be seeded.

However.. If I decide to manually add a torrent to transmission with a different destination folder, e.g "/transmission/data2" I would like the script to do nothing..

Is this possible?

Thanks for all help,

dexusno

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

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by killemov » Mon Feb 06, 2012 12:46 am

Slightly modified answer from Unrar script for JUST the default download dir?. Put this before the actual processing comment line.

Code: Select all

if [ "$TR_TORRENT_DIR" != "/transmission/data" ]; then
    TR_TORRENT_PARAMETER="EXIT"
fi
You can control some behavior when you put a file the named "keep" or "exit" in the torrent's folder.

JRRandall
Posts: 2
Joined: Thu Mar 08, 2012 1:31 am

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by JRRandall » Thu Mar 08, 2012 2:25 am

I have a simple bash script to extract .rar and .zip files that I thought I would share. Basically it will create a subfolder named "extracted" inside the torrent directory, and places the extracted files there. It also prints status messages to a log file if you'd like. Other archive formats besides zip and rar can be added easily to the formants and comands arrays. Enjoy! Disclaimer: some of the original code I obtained from another torrent client (Deluge I think).

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

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

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by killemov » Tue Mar 13, 2012 11:35 am

Why put that in this thread? It adds unzip but removes cleanup. Oh, and have you tested it with spaces in the file names?

JRRandall
Posts: 2
Joined: Thu Mar 08, 2012 1:31 am

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by JRRandall » Sat Mar 31, 2012 7:31 pm

Because it adds unzip and you can easily add more archive formats if you wish (though I don't recall seeing much more than .rar and .zip in torrents... maybe .7z?) And yes it supports spaces in filenames! It doesn't do cleanup but it could be added. I just delete the original once I'm done seeding so cleanup wasn't a big deal to have for me. YMMV just thought I'd share a nice concise script that does the job wonderfully each time. :D

boondoklife
Posts: 12
Joined: Tue Oct 25, 2011 4:30 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by boondoklife » Sun Apr 01, 2012 12:01 am

@ JRRandall Good work on making your own script, but you may wanna look into checking for .part[0-9]+.rar files (I wrote that in regular expression format as it is easy to represent that way). If you don't account for this then the script will try to unrar each part of the rared file (ex. foo.part01.rar, foo.part02.rar, foo.partn.rar)

You can check the original script for some info on that. I too wrote my own script a while back that handles zip and rars, it really is due for an update, just have to get the time to do so.

dinjo_jo
Posts: 7
Joined: Sat Aug 06, 2011 2:44 am

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by dinjo_jo » Tue May 15, 2012 3:55 pm

Ok Seems like when there are multiple folders inside folders and if i download only some folders of it the extract script does not work

I tried to simulate the script but seems like the iname is not able find the rar archive , also tried the file to recognize the type and its recognizing the type of file but find can't

Code: Select all

file wind-sparta-pt2.r00
wind-sparta-pt2.r00: RAR archive data, v14, flags: Archive volume, os: Win32

Code: Select all

[root@DINJO /media/Data/data/torrents]$  find "/media/Data/data/torrents/Spartacus.Gods.of.the.Arena.S01" -iname "*.rar"
/media/Data/data/torrents/Spartacus.Gods.of.the.Arena.S01/Spartacus.Gods.of.the.Arena.Pt.III./wind-sparta-pt3.rar
/media/Data/data/torrents/Spartacus.Gods.of.the.Arena.S01/Spartacus.Gods.of.the.Arena.Pt.IV./wind-sparta-pt4.rar
/media/Data/data/torrents/Spartacus.Gods.of.the.Arena.S01/Spartacus.Gods.of.the.Arena.Pt.VI./wind-sparta-pt6.rar
/media/Data/data/torrents/Spartacus.Gods.of.the.Arena.S01/Spartacus.Gods.of.the.Arena.Pt.II./wind-sparta-pt2.rar
/media/Data/data/torrents/Spartacus.Gods.of.the.Arena.S01/Spartacus.Gods.of.the.Arena.Pt.V./wind-sparta-pt5.rar

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

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by killemov » Tue May 15, 2012 6:25 pm

This is a known issue. I encountered only one similar case before and found it to be too rare to handle it. A workaround might be to place a file named "keep" within the torrents' folder.

livings124
Transmission Developer
Posts: 3141
Joined: Fri Jan 13, 2006 8:08 pm

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by livings124 » Wed May 16, 2012 12:05 am

dingo_jo: Transmission is not to be used for piracy. User banned.

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

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by globalrebel » Fri May 18, 2012 2:41 pm

I feel horrible for asking this . . Can anyone show me (outside of this thread) how to create this script in Transmission and how to execute it.

I just purchased the DS212J and setup the Transmission program and LOVE IT! The ONLY thing that I need this to do is unzip the files after it has finished downloading. I would like it to unzip it to a folder with the same name as the file (within the same folder that holds all the rar's).

I have read the entire thread, and I kind of understand the idea behind this. But, I'm a n00b to this and only need this one thing, before my NAS does everything perfect for me.

(I know everyone here is much better at this and it would be GREATLY appreciated!! I would probably even do a how-to after the fact for anyone else who may come upon this! PLEASE help.)

megatrond
Posts: 1
Joined: Thu May 24, 2012 10:11 am

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by megatrond » Thu May 24, 2012 10:12 am

Will this work on OSX, calling it from the regular Transmission GUI upon torrent completion?

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

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by killemov » Sat Jun 16, 2012 8:00 am

megatrond wrote:Will this work on OSX, calling it from the regular Transmission GUI upon torrent completion?
Please read the start post again, especially the dependencies section. It will not work on OSX as-is.

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

Re: Unrar and cleanup script - UPDATE 2011.10.24

Post by Khabel » Wed Jul 04, 2012 10:11 pm

Can you confirm a couple things for me please

Will there be any issues running this on unraid?
Can I move the keep file to the root dir so all torrents are kept?
Is it possible to use a sleep parameter so torrents are seeded for a certain period before removing?


Thanks and great script

Post Reply