Transmission post download script (Unpack& email with HTML feature)


Recommended Posts

Hi guys.

 

A month ago I bought unraid and started exploring.

I am new to linux (first time ever installed one) and I started to play with it a little.

 

I saw some post torrent d/l script for unraring with limited functionality.

It could either email you or unpack but not both...

The output was massy, not detailed and lacked customization.

 

I wanted a full complete script for my needs, so I made one.

I am a programmer (.NET) so I know the logic, but hell it was tough getting used to such strict coding...

 

I decided to share because I love the unMenu and I love what your are doing to help unraid!

 

Here is my script for post download, it features:

* Unpacking *.rar, *.001 and *.zip (assuming unrar/unzip are avilable)

* Log the proccess to a specified file (Append/Overwrite/Dont log )

* Sending email notification (or dont) of the LOG or HTML version of the log (can choose) to "root" (assuming sendmail/mail installed)

  The log also provides the unpacking info of unrar/unzip (see picture at then bottom)

* Customizing the unpacker arguments.

* Customizing extraction point, can be in torrent folder or any other fixed point.

* Customizing extraction directory, can be the nothing or a new folder which can be the torrent name or a fixed name.

* Deep scan, searchs sub directories and extract them, if chosen to (usfull when downloading a boxset)

 

The HTML output is quite neat, I liked it.

 

Please help me improve this, it might have some bugs but it is working fine for me, tested it live on 10 torrents.

 

You can test it by setting the TEST_MODE variable to true and suppling path and torrent at the script or at command line.

 

Script attched as TransmissionPostDL.txt below.

Thank you ALL!

52187183.jpg

TransmissionPostDL.txt

Link to comment

Glad to see you contributing back...

 

Only issue I see is that the directory you are testing is on the cache drive and named

.Downloads

while the transmission package as distributed by unMENU has it at torrents/download on /mnt/disk1.

/mnt/disk1/torrents/download

 

If nothing else, the capitalization is different. (as is the leading period but that is used to keep the "mover" script from moving the directory.)

 

Might want to make the directory easier to change or to supply as a command line parameter.

 

You did a few things different than I's seen in the past in other shell scripts, but they're not wrong, just different.  (besides, I've only been coding in unix shell since 1980... so I'm sure I've not been exposed to every style possible.  ;D)

 

Joe L.

PS. Glad you like unMENU.  I like it too... but then, I'm biased.  ;)

Link to comment

Hi,

 

Thank you for response and help.

 

I did give an option to override it but only in debug (test) mod, which is when you will run the script through the command line manually.

(Its actually good if you want to extract a directory of archives that did not come from Transmission)

I really didnt give the argument option but it asks you for a path if you dont want the default (while in test mode)

 

Your saying to allow debug mod by command line parameter?

lets say "sh script.sh "TORRNET_NAME" "TORRENT_DIR", if they are null then no test mode otherwise force test mode?

 

 

btw, I also gave the option to set the extraction directory...

 

Anyway, I used alot of variables (found in the USER VAR section of the secript) to allow full customization.

 

I think I documented alot, tough again Im new to this and I dont know the standart for documentation.

 

As for writing it differently, well I guesss seince I have 0 experience here... :) but its working lol :)

Anyway, Thank for commenting and letme know if im wrong.

 

Thank you

 

 

Link to comment

Hi,

 

Thank you for response and help.

 

I did give an option to override it but only in debug (test) mod, which is when you will run the script through the command line manually.

(Its actually good if you want to extract a directory of archives that did not come from Transmission)

I really didnt give the argument option but it asks you for a path if you dont want the default (while in test mode)

 

Your saying to allow debug mod by command line parameter?

lets say "sh script.sh "TORRNET_NAME" "TORRENT_DIR", if they are null then no test mode otherwise force test mode?

Clearly I'm not a transmission user.  I can see now this script is intended to be used by entering its name in the configuration field on the unMENU transmission config variables edit screen.  I did not make the connection until you mentioned it being passed as an exported variable.

btw, I also gave the option to set the extraction directory...

 

Anyway, I used alot of variables (found in the USER VAR section of the secript) to allow full customization.

Yes, you did.  It is just that many unMENU users do not have your level of experience in editing documents on unRAID.  To make it easier, many coders use "getopts" to parse command line arguments.  (Look at my preclear_disk.sh script for a lot of examples of optional parameters)

I think I documented alot, tough again Im new to this and I dont know the standart for documentation.

I like comments in the code that describe what is being done rather then describing the specific line of code.

A comment that says "increment x by 1" is almost useless if it is above a statement that clearly says "let x = x + 1"

A comment that says "increment x by 1 because we are faking a non-zero based array" is a LOT more helpful for those following what you've done.

 

Other than that, I don't know if there is a "standard"

As for writing it differently, well I guesss seince I have 0 experience here... :) but its working lol :)

Anyway, Thank for commenting and letme know if im wrong.

 

Thank you

Yes, it works... that is why I say I learned a different way of coding some logic.

 

In bash shell you can see if a command is in your search path by typing

which xxxxx

(where xxxxx = the command name)

So

which winrar

will return

which: no winrar in (/usr/local/sbin:/usr/sbin:/sbin:./:/usr/local/bin:/usr/bin:/bin)

to the stderr output if it does not exist. and more importantly, the exist status will be set to "1" (as the command is not in the search path)

 

If it did exist, the exit status would be set to "0" and stdout would print

/usr/bin/winrar

 

You used "find" (probably because of your knowledge of the ms-dos command of the same name).

 

There was nothing specifically wrong with what you did, you just used "find" in a way I would not because I knew other ways to test if the file existed.

If the file is in a specific place you can use

if [ -x /usr/bin/winrar ]

then

  .........

fi

 

the -x option to the "test" command is specifically to test if the command at the path given is executable.

 

Fortunately, for me if I need to tackle a .net program, or for you to tackle a shell script, google can turn up lots of examples.

 

Hopefully you'll be able to follow along on a lot of what I've coded in "awk" and "shell" in coding unMENU and its set of utilities.  Most of it is pretty well commented.

 

I'm going to be learning how to code an "android" app next.  (in a few more hours a Motorola smart phone will be officially mine as a Christmas present)

 

Joe L.

Link to comment

Thank you for enriching my knowladge, I will explore your scripts for furthere use and just for fun :)

 

I have never programed for android but from what Iv seen/heard (and its not much) I think its mostly JAVA so you shouldnt have much trouble...

Jave is easy as net... (putting the IDE aside)

Youll have to explore the framework... but as you said google is the worldst best place to find answers...

 

btw, is threre an IDE for shell scripting, I love it when intellisence makes life easier and writing that script in Notepad++ didnt help much, tough writing it in native notepad is by far a nightmare.

 

Link to comment

I  have to be missing something here.  I can not get the script to run even in test mode.  t the command prompt i enter the script name and it goes right back to a command prompt.  I have made sure the permissions are set correctly and changed the variable in the script true for testing but it is not running.  thoughts?

Link to comment

instead of writing the path and name in the promet do it directly in the script...

 

Also, make sure the DIR is the directory where the torrent directory is and NAME is the actual torrent directory name.

 

For example, if you download all torrents to /mnt/disk1/downloads

and you download the torrent Windows7.Free.Icons

 

Then dir = /mnt/disk1/downloads and Name = Windows7.Free.Icons

 

Also, make sure unrar/unzip is present, write the log path for logging (and check it) and also mail is installed.

 

Keep us posted.

 

Link to comment

Made the changes

TR_TORRENT_NAME=Stone #Torrent name here (this is the directory/filename inside TR_TORRENT_DIR below

TR_TORRENT_DIR=/mnt2/diskX/complete #the root directory for torrents

 

Have it running but i am getting

 

Starting scan in the root of the torrent.

 

Found archive: /mnt2/diskX/complete/Stone/Stone.part01.rar ./Stone.part02.rar ./Stone.part03.rar ./Stone.part04.rar ./Stone.part05.rar ./Stone.part06.rar ./Stone.part07.rar ./Stone.part08.rar

Unpaking to: /mnt2/diskX/complete/Stone/Stone

UNRAR 3.71 beta 1 freeware Copyright © 1993-2007 Alexander Roshal

No files to extract

Could not find an archive of type RAR, 001 or ZIP.

 

thoughts

 

Link to comment

Hi

 

Multiple rar archive in the format you have (XX.part0.rar, part1.rar etc..) is not supported in my script.

 

I gave support for rar, r01 etc...

 

this needs a simple alter, I just dont have the time to do it and debug it to work 100%, if someone else wants to help It will be appreciated...

Work is taking all my time :)

 

But in all other cases it works...

 

Link to comment
  • 11 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.