Jump to content

Examples of automatic handling of finished downloads (scripts)


Axman84

Recommended Posts

Hi all,

First off: thanks to the uTorrent team for an EXCELLENT function-rich, simple and lightweight piece of software. There should be more software developed this way.

In my quest to make my entertainment center setup(s) automated, I wanted to automatically handle my torrents. I got tired of all the manual but repetitive extracting, moving, copying, and deleting, so I created two batch scripts to handle this. One for new downloads and one for deleting old torrents, and they get parameters directly from uTorrent.

Under uTorrent preferences -> Advanced -> Run Program I have it set up like this:

For "Run this program when a torrent finishes", I have the following:

C:\scripts\torrentscript.bat "%D" "%N" "%L" "%K" "%F" >> torrentlog.txt

For "Run this program when a torrent changes state", I have the following:

C:\scripts\deletescript.bat "%D" "%N" "%S" "%K" "%F" >> deletelog.txt

The output of the scripts is piped into logfiles for debugging purposes.

Scripts follow in posts 2 and 3.

Note: These are Windows batch scripts (.bat files). I don't have much experience with win batch programming but I quickly realized that it certainly has its limitations, especially with respect to dealing with strings and quotation marks for example. If anyone decides to check this out and make a Unix/shell script version, I'd like to have it, as I may go that route if I continue to expand the scripts. Thanks!

Link to comment
Share on other sites

Here is the first script, torrentscript.bat, which handles newly downloaded torrents.

It is fairly customized for my use, so everything may not be entirely logical to everyone. Feel free to suggest changes, and of course ask questions if anything needs clarification.

Essentially it uses the label to determine the type of download, and extracts or copies files accordingly.

If type cannot be determined by label it checks for files to copy.

The "rem" comments in the scripts below are intended to do some explaining. The trickiest part is the label prefix logic - I use labels with slashes for shows to determine the destination path. So that for example a torrent with label "Shows\Boardwalk Empire" can be extracted/copied to D:\Shows\Boardwalk Empire.

Winrar needs to be installed for extraction of rars. I recommend reading the script in an editor such as Notepad++ to make it easier to read, with color coding and all.

Code:

@echo off
title Axmans torrent-file script
rem Parameter usage: fromdir torrent-name label kind [filename]
rem corresponds to uTorrents flags: %D %N %L %K %F
echo *********************************************
echo Run on %date% at %time%

set fromdir=%1
set name=%2
set label=%3
set kind=%4
set filename=%5
set savepartition=D:
set moviedir=%savepartition%\Movies
set musicdir=%savepartition%\Music
set label_prefix=""
echo Input: %fromdir% %name% %label% %kind% %filename%

rem Determine length of label string
echo.%label%>len
for %%a in (len) do set /a len=%%~za -2
rem This is to pick up if label begins with "Shows" (ex. "Shows\Boardwalk Empire")
if %len% geq 7 set label_prefix=%label:~1,5%
echo label_prefix = %label_prefix%

echo %date% at %time%: Handling torrent %name% >> handled_torrents.txt

rem If label is "Movies"
if %label%=="Movies" goto movies

rem If label starts with "Shows"
if %label_prefix%==Shows goto shows

rem If label is "Music"
if %label%=="Music" goto copymp3s

rem If there are mp3 files in fromdir and it is a multi-file torrent
if exist %fromdir%\*.mp3 if %kind%=="multi" goto copymp3s

rem Last resort
rem Double underscores so the folders are easier to spot (listed on top in explorer)
set todir=%savepartition%\__%name%
if %kind%=="single" goto copyfile
if %kind%=="multi" goto copyall

GOTO:EOF

rem xcopy switches:
rem S Copies directories and subdirectories except empty ones.
rem I If destination does not exist and copying more than one file, assumes that destination must be a directory.
rem L Displays files that would be copied. FOR DEBUG
rem Y Suppresses prompting to confirm you want to overwrite an existing destination file.

:movies
echo **Movie
set todir=%moviedir%\%name%
echo todir = %todir%
rem If there are rar files in the folder, extract them.
rem If there are mkvs, copy them. Check for rars first in case there is a sample.mkv, then we want the rars
if %kind%=="single" goto copyfile
if exist %fromdir%\*.rar goto extractrar
if exist %fromdir%\*.mkv goto copymkvs
echo Guess we didnt find anything
GOTO:EOF

:shows
echo **Show
set todir=%savepartition%\%label%
if %kind%=="single" goto copyfile
if exist %fromdir%\*.rar goto extractrar
if exist %fromdir%\*.mkv goto copymkvs
echo Guess we didnt find anything
GOTO:EOF

:copymp3s
echo **Music
set todir=%musicdir%\%name%
if %kind%=="single" goto copyfile
echo Copy all mp3s from %fromdir% and subdirs to %musicdir%\%name%
xcopy %fromdir%\*.mp3 %todir% /S /I /Y
GOTO:EOF

:copyall
echo **Undefined
echo Copy all contents of %fromdir% to %todir%
xcopy %fromdir%\*.* %todir% /S /I /Y
GOTO:EOF

:copyfile
rem Copies single file from fromdir to todir
echo Copy %filename% from %fromdir% to %todir%
xcopy %fromdir%\%filename% %todir%\ /S /Y
GOTO:EOF

:copymkvs
echo Copy all mkvs from %fromdir% and subdirs to %todir%
xcopy %fromdir%\*.mkv %todir% /S /I /Y
GOTO:EOF

:extractrar
echo Extracts all rars in %fromdir% to %todir%.
rem Requires WinRar installed to c:\Program files
if not exist %todir% mkdir %todir%
"c:\program files\winrar\winrar.exe" x -ilog %fromdir%\*.rar *.* %todir%
GOTO:EOF

Link to comment
Share on other sites

This script, deletescript.bat, simply deletes the files of a torrent if it has reached the "Finished" state, i.e. has reached the seeding goal. At this point I dont need the files any more. The data was properly copied/extracted when the download finished anyways.

@echo off

title Axmans delete script

rem Only run if state is finished (11), delete torrent with all files

if not %3%=="11" exit

rem Parameter usage: basedir torrent-name state kind [filename]

rem corresponds to uTorrents flags: %D %N %S %K %F

echo *********************************************

echo Run on %date% at %time%

set basedir=%1

set name=%2

set state=%3

set kind=%4

set filename=%5

echo Input: %basedir% %name% %state% %kind% %filename%

echo %date% at %time%: Handling torrent %name% >> deleted_torrents.txt

echo **Deleting

if %kind%=="single" goto deletefile

if %kind%=="multi" goto deleteall

echo ERROR - Unrecognized kind (%kind%)

GOTO:EOF

:deletefile

echo Deleting file %basedir%\%filename%

del %basedir%\%filename%

GOTO:EOF

:deleteall

rem Simply some precautions here

if %basedir%=="D:\_Temp" exit

if %basedir%=="D:\Shows" exit

if %basedir%=="D:\Movies" exit

if %basedir%=="D:\Music" exit

if %basedir%=="D:\" exit

if %basedir%=="C:\" exit

echo Deleting directory %basedir% with all subcontent

rmdir /S /Q %basedir%

GOTO:EOF

Link to comment
Share on other sites

Again, do yourself a favor and read the scripts in an editor if you want to try to go through the logic.

Also, uTorrent 3.0 is required for this to work due to the parameters.

Some things I'd like to implement next is a way of sending notifications to my phone when handling a torrent. The script currently updates a log file with torrent name date and time, but thats it. I could use a command line email client and email myself, but all the outgoing servers I use (gmail for example) use TLS encryption and the simple command line email programs dont play well with encryption, so I'd have to set up an emailserver on my machine, which isnt worth the hassle imo.

All comments and improvement suggestions are most welcome!

Link to comment
Share on other sites

Those scripts are awesome! Thanks!

Miranda is a pretty garden-variety IM client, with the unique exception that it supports sending messages via the CLI, so it is great for this application. It is compatible with all of the major IM protocols (AIM, ICQ, etc) so it can message you on your phone over one of those. I have a private XMPP/Jabber network running in my office (OpenFire on W2K3) so that we can IM each other without the network being open to the public and spimmers and such, so I have utorrent/Miranda using that instead and I installed Xabber on my phone to receive the messages.

The main downside to Miranda is that the configuration dialogue is anything but intuitive. It takes some patience to find your way around and set up. It works great once you get it going, though.

Link to comment
Share on other sites

  • 1 month later...

Axman, first off thanks a lot for this script.

It really solved some headaches I had.

Maybe you may have a clue, why it works for tv shows, but doesn't work for Movies - they seem to be not copied at all.

What I've changed in you script is that I set a fixed movie dir, which is completely different from TV Shows dir, but on the same drive.

This line:

set moviedir=%savepartition%\Movies

was changed to:

set moviedir=C:\Users\user\videos\Movies

I suspect that may have caused issues, though don't understand what to change to make it work.

In the log file it's showing that it tries to copy the movie file to let's say:

C:\Users\user\videos\Movies\"name.name.of.the.torrent.BRrip.avi"

But after that there goes line

"Guess nothing was found"

Could it be that it fails to create a directory with the same name as the torrent's name?

I've set same shared permissions for both directories, should be no issue with that.

Same situation with the movies those have multiple files in the log file it says

"0 files copied"

Any advice where to look for problems?

Link to comment
Share on other sites

  • 2 months later...

Axman84, Thank you for a fantastic script - seriously well done. Has really helped me create a custom version using some of your methods.

For yours or anyone elses info I used

"C:\Program Files\theRenamer\theRenamer.exe" -fetch

At the end of my TV routine to automatically rename downloaded eps. Works a treat.

Thanks again mate

Link to comment
Share on other sites

  • 2 weeks later...

which version of "the renamer" are you using? I am having problem with the auto rename function (there is a paw you have to click in version 7.57)

Axman84, Thank you for a fantastic script - seriously well done. Has really helped me create a custom version using some of your methods.

For yours or anyone elses info I used

"C:\Program Files\theRenamer\theRenamer.exe" -fetch

At the end of my TV routine to automatically rename downloaded eps. Works a treat.

Thanks again mate

Link to comment
Share on other sites

  • 3 weeks later...

Hey as I found this post so useful I thought I'd share the changes I made so it might help others. I had a slightly different requirement as most of my download goes into the same containing folder.

I specify the absolute position for the log in the my call (utorrent preferences > Advanced > Run Program > Run this program when torrent finishes:

C:\Development\Scripts\utorrent\torrentscript.bat "%D" "%N" "%L" "%K" "%F" >> C:\Development\Scripts\utorrent\torrentlog.txt

I've made the sub label parsing more robust for different length labels. I don't currently do much with the suffix but it's there if you need it.

I also copy over the subs folder manually and the nfo file as too many downloads annoyingly didn't have the nfo in the rar,

I also do some post processing to update my plex media server (if you're not using it then why not?!?!) I do nearly all my downloading using newsgroups with sickbeard, couchpotato and SABnzbd. These uTorrent scripts are just for problem episodes or movies, MMA, training and software. To update Plex I use wget which is part of GNUwin http://gnuwin32.sourceforge.net/packages/wget.htm This can all be deleted if you do not require it.

This is not perfect, there is code that I don't really make use of currently but it's there as I will be changing in the future. There's certainly bits that could be cleaner so expect to get a little dirty. Obviously you'll need to update the script with your locations. Most of the variables are up top in the "Set Variables" section, please change to your requirements.

@echo off
title Jamie's torrent-file script
rem Based on: http://forum.utorrent.com/viewtopic.php?id=110024
rem Parameter usage: fromdir torrent-name label kind [filename]
rem corresponds to uTorrents flags: %D %N %L %K %F
echo *********************************************
echo Run on %date% at %time%

set fromdir=%1
set name=%2
set label=%3
set kind=%4
set filename=%5
set savepartition=F:\Media
set gamesavedir=C:\Users\Jamie\Downloads\Completed
set sickbeardscript="C:\Development\Scripts\utorrent\autoProcessTV\sabToSickBeard.py"
set wget="C:\Program Files\GnuWin32\bin\wget.exe"
set winrar="c:\program files\winrar\winrar.exe"
set torrentlog=C:\Development\Scripts\utorrent\torrentlog.txt
set handledlog=C:\Development\Scripts\utorrent\handled_torrents.txt
set sickbeardlog=C:\Development\Scripts\utorrent\SickbeardLog.txt
set errorlog=C:\Development\Scripts\utorrent\ErrorLog.txt
set label_prefix=""

echo Input: %fromdir% %name% %label% %kind% %filename%

rem Check if the label has a sub label by searching for \
if x%label:\=%==x%label% goto skipsublabel
rem Has a sub label so split into prefix and suffix so we can process properly later
echo sub label
for /f "tokens=1,2 delims=\ " %%a in ("%label%") do set label_prefix=%%a&set label_suffix=%%b
rem add the removed quote mark
set label_prefix=%label_prefix%"
set label_suffix="%label_suffix%
echo.prefix : %label_prefix%
echo.suffix : %label_suffix%
goto:startprocess

:skipsublabel
echo Skipped Sub Label
goto:startprocess

:startprocess
echo %date% at %time%: Handling %label% torrent %name% >> %handledlog%

rem Process the label
if %label%=="Movies" goto known
if %label%=="AV" goto known
if %label%=="MMA" goto known
if %label%=="Software" goto known
if %label%=="UNPACK" goto known
if %label_prefix%=="Training" goto known
if %label%=="Games" goto other
if %label%=="TV" goto TV


rem Last resort
rem Double underscores so the folders are easier to spot (listed on top in explorer)
echo Last Resort
set todir=%savepartition%\Unsorted\__%name%
if %kind%=="single" goto copyfile
if %kind%=="multi" goto copyall
GOTO:EOF

:known
echo **Known Download Type - %label%
set todir=%savepartition%\%label%\%name%
echo todir = %todir%
GOTO:process

:other
rem Handle downloads that aren't going into my main save directory
rem add as required
echo **Other Download Type - %label%
if %label%==Games set todir=%gamesavedir%\%name%
echo todir = %todir%
GOTO:process

:TV
echo **Known Download Type - %label%
REM as it's TV I need to keep the directory name to give sickbeard the best chance of successfully processing
REM Strip out the last part of directory name and use it to create the todir name
for /D %%i in (%fromdir%) do set todir=%savepartition%\Unsorted\%%~ni%%~xi
echo todir = %todir%
GOTO:process

:process
rem If there are rar files in the folder, extract them.
rem If there are mkvs, copy them. Check for rars first in case there is a sample.mkv, then we want the rars
if %kind%=="single" goto copyfile
if exist %fromdir%\*.rar goto extractrar
if exist %fromdir%\*.mkv goto copymkvs
if %kind%=="multi" goto copyall
echo Guess we didnt find anything
GOTO:EOF

:copyall
echo **Type unidentified so copying all
echo Copy all contents of %fromdir% to %todir%
xcopy %fromdir%\*.* %todir% /S /I /Y
GOTO:POSTPROCESSING

:copyfile
rem Copies single file from fromdir to todir
echo Single file so just copying
echo Copy %filename% from %fromdir% to %todir%
xcopy %fromdir%\%filename% %todir%\ /S /Y
GOTO:POSTPROCESSING

:copymkvs
echo Copy all mkvs from %fromdir% and subdirs to %todir%
xcopy %fromdir%\*.mkv %todir% /S /I /Y
GOTO:POSTPROCESSING

:extractrar
echo Extracts all rars in %fromdir% to %todir%.
rem Requires WinRar installed to c:\Program files
if not exist %todir% mkdir %todir%
IF EXIST %fromdir%\subs xcopy %fromdir%\subs %todir% /S /I /Y
IF EXIST %fromdir%\subtitles xcopy %fromdir%\subtitles %todir% /S /I /Y
call %winrar% x %fromdir%\*.rar *.* %todir% -IBCK -ilog"%todir%\RarErrors.log"
IF EXIST %fromdir%\*.nfo xcopy %fromdir%\*.nfo %todir% /S /I /Y
GOTO:POSTPROCESSING

:POSTPROCESSING
rem If the file is media Then update Plex.
rem Not used for other file types at this point but it might be expanded
rem update the plex section. For more info see http://wiki.plexapp.com/index.php/PlexNine_AdvancedInfo#Terminal_Commands
if %label%=="MMA" call %wget% -O NUL http://localhost:32400/library/sections/11/refresh?deep=1
if %label%=="Movies" call %wget% -O NUL http://localhost:32400/library/sections/3/refresh?deep=1
if %label%=="TV" GOTO:tvpostprocessing
GOTO:EOF

:tvpostprocessing
echo
echo ****************BEGIN SICKBEARD PROCESSING >> %sickbeardlog%
echo %date% at %time%: Handling %name% from %todir% >> %sickbeardlog%
call python %sickbeardscript% %todir% >> %sickbeardlog%
REM Check the sickbeard log for errors
REM Count the number of lines so we can show just the last line in the main log
for /f "tokens=3" %%i in ('find /v /c "Wont@findthisin#anyfile" %sickbeardlog%') do set countoflines=%%i
set /a countoflines=countoflines-1
echo Sickbeard processing result:
echo | more +%countoflines% < %sickbeardlog%

REM Check the last line again to check result
SET sbresult=SUCCEEDED
echo | more +%countoflines% < %sickbeardlog% | FIND "Processing succeeded" > NUL
IF ERRORLEVEL 1 SET sbresult=FAILED
ECHO Sickbeard processing %sbresult%
REM The sickbeard processing failed so write to the error log and open the file
IF %sbresult%==FAILED ECHO %date% at %time%: Sickbeard processing %sbresult%. Handling %filename% from %todir%. Check the main logs >> %errorlog%
IF %sbresult%==FAILED start notepad %errorlog%
REM Update Plex TV section
call %wget% -O NUL http://localhost:32400/library/sections/10/refresh?deep=1
GOTO:EOF

Link to comment
Share on other sites

also does anyone know how to run multiple scripts in utorrent at once? for instance one to rename the files using "therenamer" and then one to move them to my htpc?

<<programming noob

As you can probably see from my code you use 'call' so:

call C:\scripts\script.bat

Link to comment
Share on other sites

HI,

I'm working on a program to handle downloads in uTorrent

The program will be maintained here http://code.google.com/p/utorrent-sorter/

Some features I plan on implementing are:

automatic sorting of files into appropriate directories for my media servers // Currently working though limited

automatic deletion of torrents after seeding

automatic deletion of torrents that fail to download

Please give me some more Ideas of common tasks or features that would be cool

Link to comment
Share on other sites

HI,

Some features I want are:

Checksums to verify itegrity

Trigger anti-virus scan

automatic sorting of files into appropriate directories for my media servers

automatic deletion of torrents after seeding //plan on using uTorrent to seed to a ratio and then deleting //torrent when %S == 11(finished)

automatic deletion of torrents that fail to download

I'm not really your man for this but I do have to say that many of your goals are already reached with uTorrent out of the box. Checksums are part of the bitorrent protocol. Your anti-virus should be checking all downloads as standard.

For the rest you can use this work as a basis for deleting the torrents. http://forum.utorrent.com/viewtopic.php?pid=659028 I'm sure you can work out the sorting from the scripts above.

Good luck

Link to comment
Share on other sites

  • 2 weeks later...

Thanks a lot for the posts !!! .. Modified to sort by tracker

echo *********************************************

echo Run on %date% at %time%

set fromdir=%1

set name=%2

set tracker=%3

set savepartition=D:

set moviedir=%savepartition%\BT

echo Input: %fromdir% %name% %tracker%

echo %date% at %time%: Handling torrent %name% >> handled_torrents.txt

rem trimming the tracker information

set tracker_prefix=%tracker:~1,12%

echo %tracker_prefix%

rem If Tracker contains "http://tamil"

if "%tracker_prefix%"=="http://tamil" goto movies

echo Sorry

GOTO:EOF

:movies

echo **Movie

set todir=%moviedir%\%name%

echo todir = %todir%

xcopy %fromdir%\*.* %todir% /S /I

GOTO:EOF

Link to comment
Share on other sites

  • 3 weeks later...

I'm a noob.. well not toally a noob but damned if I don't feel like one right now. Having major issue getting a bat to run after the state changes. I've seen a lot on this but no straight up defininitive answers unless i'm that clueless.. My bat runs fine if I drop it in the created directory and run it. If it's called on I see it triggering but I get file not found. Any help would be greatly appreciated. (probably save a brother from pulling out what's left of his hair too).

Link to comment
Share on other sites

  • 3 weeks later...

I would love to be able to move files to specific directories after they finish downloading, based on the tracker. I usually have three categories; movies, music, and tv-shows. Is there anyway i can accomplish this using a script? Or even a better option will be first to label them based on the tracker, then move them to directories.

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...

hate to resurrect old thread but im curious about this script, attempted using it and modifying it, but when it comes to downloading a torrent that has more than one subdirectory such as a 2CD or a boxset such as a season it just copies over the files but does not extract the rar files, and im not entirely sure how to actually get it working

pastebin link to script

http://pastebin.com/QpG64vdh

Link to comment
Share on other sites

  • 2 weeks later...

I use a seedbox, so I want to start a FTP script that automatically upload a finished torrent back to my home server. I have found an excellent client named "lftp" for this purpose as it allows parallel upload and recursive functionality. Script supports both multi and single file torrents. This script assumes you have a label set, you might have errors without it.

Command in µTorrent:

C:\Utils\Scripts\ftp.vbs %K "%D" "%N" %L "%F"

Script:

'save as ftp.vbs
Dim path,label,cmd,nm,file,tp,host,user,pass,dir,drive,login,lftp,wd, context
host = "myHostOrIP"
user = "myUsername"
pass = "myPassword"
login = user & ":" & pass & "@" & host
lftp = "C:\Utils\lftp\lftp.exe"
wd = "C:\"

tp = WScript.Arguments.Item(0) 'single/multi
dir = WScript.Arguments.Item(1)
drive = LCase(Mid(dir, 1, 1))
path = "/cygdrive/" & drive & Right(dir,Len(dir)-2)
path = Replace(Replace(path,"\","/")," ","\ ")
nm = Replace(Replace(WScript.Arguments.Item(2),"\","/")," ","\ ")
file = path & "/" & Replace(Replace(WScript.Arguments.Item(4),"\","/")," ","\ ")
label = WScript.Arguments.Item(3)

If tp = "single" Then
context = "cd /" & label & "; put " & file
Else
'multifile
context = "mirror -R -v --parallel=3 --depth-first " & path & " /" & label & "/" & nm
End If

cmd = "ftp://" & login & " -e " & chr(34) & "set ftp:nop-interval 1; set net:timeout 5; "& context & "; quit" & chr(34)

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute lftp, cmd, wd, "runas", 1
Set objShell = Nothing

Link to comment
Share on other sites

  • 3 weeks later...

Firstly, thanks for the script! I have modified it slightly to work for me, I have no idea how the label part works unfortunately. The rest of it is pretty straight forward, I wish I could work it out because I'd like to do the same with music as what is being done with shows. ie rather than shows\showname\season. I would like music\artist\album, not a big deal I do a bit of manual work with music anyway.

I also send myself an email once a torrent is finished seeding so that I know to remove it from utorrent (working on automating this) using stunnel and blat. It works well.

Emailing from cmd line - http://phonefullofbooks.wordpress.com/2011/10/07/adding-e-mail-notification-to-utorrent-when-a-download-finishes/

I also run utorrent on my xbmc and when the scripts would run it would make the cmd line window active, to get around this you invoke the command line from a vbs script. Just grab the script from the following thread and then where you have specified the scripts in utorrent just refer to the vbs first. You will see what I mean.

http://filebot.sourceforge.net/forums/viewtopic.php?t=215&p=1561

Thanks again!

Link to comment
Share on other sites

I recently wrote a powershell script that also sends me an e-mail when a torrent is finished. For those who are interested, I'll share it :).

First, I created a file named TorrentFinished.html with tags like !Title!, that can later be replaced by the script. You can create it yourself, to make it look the way you like, or you can use this HTML code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 0px;
border-color: green;
border-collapse: collapse;
}
table.gridtable th {
border-width: 0x;
padding: 8px;
border-style: solid;
border-color: green;
background-color: green;
align: left;
}
table.gridtable td {
border-width: 0px;
padding: 8px;
border-style: solid;
border-color: white;
background-color: #ffffff;
}
</style>
</head>
<body bgcolor="black">
<table class="gridtable">
<colgroup>
<col/>
<col/>
</colgroup>
<tr><th align="left">Variable</th><th align="left">Value</th></tr>
<tr><td>Title:</td><td>!Title!</td></tr>
<tr><td>Directory:</td><td>!Dir!</td></tr>
<tr><td>Filename:</td><td>!Name!</td></tr>
<tr><td>PreviousState:</td><td>!PreviousState!</td></tr>
<tr><td>Label:</td><td>!Label!</td></tr>
<tr><td>Tracker:</td><td>!Tracker!</td></tr>
<tr><td>Status message:</td><td>!StatusMessage!</td></tr>
<tr><td>Hex encoded info-hash:</td><td>!HexInfoHash!</td></tr>
<tr><td>State:</td><td>!State!</td></tr>
<tr><td>Kind of torrent:</td><td>!Kind!</td></tr>
</table>
</body></html>

Then, I created a script named TorrentFinished.ps1. I only tested this with Gmail. If you want to use it, you'll have to change 'username' into whatever your username is. Same goes for 'password'. If you don't use Gmail, you'd also have change the "smtp.gmail.com", and probably the port (check here). You also need to adjust the path to TorrentFinished.html. The code:

Param(
[alias("f")]
$Name,
[alias("d")]
$Dir,
[alias("n")]
$Title,
[alias("p")]
$PreviousState,
[alias("l")]
$Label,
[alias("t")]
$Tracker,
[alias("m")]
$StatusMessage,
[alias("i")]
$HexInfoHash,
[alias("s")]
$State,
[alias("k")]
$Kind)

$EmailFrom = “username@gmail.com”
$EmailTo = “username@gmail.com”
$Pass = "mypassword"
$Subject = “Torrent Finished Downloading!”
$EmailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )
$emailMessage.Subject = "Torrent Finished Downloading!"
$emailMessage.IsBodyHtml = $true
$emailMessage.Body = get-content "C:\Scripts\TorrentFinished.html"
$emailMessage.Body = $emailMessage.Body -replace "!Title!", $Title
$emailMessage.Body = $emailMessage.Body -replace "!Dir!", $Dir
$emailMessage.Body = $emailMessage.Body -replace "!Name!", $Name
$emailMessage.Body = $emailMessage.Body -replace "!PreviousState!", $PreviousState
$emailMessage.Body = $emailMessage.Body -replace "!Label!", $Label
$emailMessage.Body = $emailMessage.Body -replace "!Tracker!", $Tracker
$emailMessage.Body = $emailMessage.Body -replace "!StatusMessage!", $StatusMessage
$emailMessage.Body = $emailMessage.Body -replace "!HexInfoHash!", $HexInfoHash
$emailMessage.Body = $emailMessage.Body -replace "!State!", $State
$emailMessage.Body = $emailMessage.Body -replace "!Kind!", $Kind

$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“username”, $Pass);
$SMTPClient.Send($emailMessage)

In the "Run this program when a torrent finishes:", I put the following command (replace "D:\Scripts\TorrentFinished.ps1" with the correct path.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy unrestricted -file "D:\Scripts\TorrentFinished.ps1" -Name "%F" -Dir "%D" -Title "%N" -PreviousState "%P" -Label "%L" -Tracker "%T" -StatusMessage "%M" -HexInfoHash "%I" -State "%S" -Kind "%K"

I also have an app called 'Tasker' on my Android, that allows me to play a custom sound based on the subject of an e-mail :).

Hopefully someone finds this useful.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...