Archived

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

Axman84

Examples of automatic handling of finished downloads (scripts)

Recommended Posts

I would like to add a warning when using this script, that if you use the network speed tester and have a delete script enabled, it will stop all seeding torrents (therefore their state is 11) and they will be deleted if that's what you have set..I just learned that the hard way haha.

Share this post


Link to post
Share on other sites

Hi All,

I'm new to bash scripts and stuff but am on my quest to a fully automated media centre.

I have been trying to implement this script in my set up to remove and delete torrents when completed.

For my set up I run filebot when a torrent completes, this extracts and organises my media and uses a "hardlink" so the torrent can remain active but my media be arranged as I would like.

Then I have used a variation of Axman's deletescritpt which is below, to remove the data from my torrent folder.

@echo off

title Deleting Torrents Script
rem Only run if state is finished (11), delete torrent with all files
if %3%=="11" goto continue
GOTO:EOF

:continue

rem Parameter usage: basedir torrent-name state kind [filename]
rem corresponds to uTorrents flags: %D %N %S %K %F %L
echo *********************************************
echo Run on %date% at %time%

set basedir=%1
set name=%2
set state=%3
set kind=%4
set filename=%5
set label=%6
echo Input: %basedir% %name% %state% %kind% %filename% %label%

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

call D:\tremove.bat

rem If label starts with "Shows"

if %label%=="TV-Shows" goto deleting
if %label%=="Films" goto deleting
GOTO:notdeleting
GOTO:EOF

:deleting
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:\TV 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

:notdeleting
echo File not a TV Show or Film
GOTO:EOF

My aim was to use the php scritpt found here: http://forum.utorrent.com/viewtopic.php?id=89110 to remove the torrent from utorrent when the ratio is met. As you can see I try to call another script called tremove.bat after the variables are set, which should then run the php script.

start C:\webserver\PHP\php.exe -f D:\Scripts\PHPRemove\remove.php
echo removed
exit

The php script runs from the CLI if I write php.exe D:\Scripts\PHPRemove\remove.php the script works and also if I make a batch script which contains call php.exe D:\Scripts\PHPRemove\remove.php

If anyone can see were I may have gone wrong that would be greatly appreciated. I'm pretty new to batch and php and have mainly be learning it to set this up.

Thanks

Share this post


Link to post
Share on other sites

I have revised the script from Axman84 to include plex updates , Debug Logs, and use Extractnow which detects everything in folder and extracts it

Same as Axman84 C:\Users\Admin\Desktop\utorrent.bat "%D" "%N" "%L" "%K" "%F"

Run when Torrent Finished

@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%
timeout /t 3 /nobreak
set fromdir=%1
set name=%2
set label=%3
set kind=%4
set filename=%5
set savepartition=S:
set moviedir=%fromdir%
set appsdir=%savepartition%\Extracted\Applications
set gamesdir=%savepartition%\Extracted\Games
set tvdir="%savepartition%\Extracted\HD TV"
set garytvdir="%savepartition%\Extracted\Gary TV"
rem set label_prefix=""
echo Input: %fromdir% %name% %label% %kind% %filename%

rem Determine length of label string
rem echo.%label%>len
rem 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")
rem if %len% geq 7 set label_prefix=%label:~1,5%
rem echo label_prefix = %label_prefix%

echo %date% at %time%: Torrent %name% with label %label% snagged >> "C:\Users\Admin\Desktop\Utorrent Logs\Grabbed_torrents.txt"

rem If label is "Movies"
if %label%=="HD Movies" goto HD_Movies

rem If label is "TV"
if %label%=="HD TV" goto HDTV

rem If label is "Applications"
if %label%=="Applications" goto Applications

rem If label is "PC Games"
if %label%=="PC Games" goto Games

rem If label is "Gary TV"
if %label%=="Gary TV" goto Gary_TV

rem Last resort
rem Double underscores so the folders are easier to spot (listed on top in explorer)
rem set todir=%savepartition%\Extracted\__%name%
if %kind%=="single" goto failed
if %kind%=="multi" goto failed
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.

:HD_Movies
echo **Movie
set todir=%moviedir%\%name%
echo todir = %todir%
rem If there are rar files in the folder, extract them.
rem if %kind%=="single" goto copyfile
rem if exist %fromdir%\*.mkv goto copymkvs
if exist %fromdir%\*.rar goto extractrar
echo Guess we didnt find anything
GOTO:EOF

:HDTV
echo **TV
set todir=%tvdir%\%name%
if %kind%=="single" goto copyfile
if exist %fromdir%\*.rar goto extractrar
echo Guess we didnt find anything
GOTO:EOF

:Gary_TV
echo **Gary_TV
set todir=%garytvdir%\%name%
if %kind%=="single" goto copyfile
if exist %fromdir%\*.rar goto extractrar
echo Guess we didnt find anything
GOTO:EOF

:Applications
echo **Applications
set todir=%appsdir%\%name%
rem if %kind%=="single" goto copyfile
rem if %kind%=="multi" goto copyall
goto extractrar
GOTO:EOF

:Games
echo **Games
set todir=%gamesdir%\%name%
if %kind%=="single" goto copyfile
goto extractrarr
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%
if not exist %todir% mkdir %todir%
if %label%=="HD TV" goto Extract_TV
if %label%=="HD Movies" goto Extract_Movies
if %label%=="Gary TV" goto Extract_GaryTV
if %label%=="Games" goto Extract_Games
if %label%=="Applications" goto Extract_Applications
rem "C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir% /target "s:\Extracted\Gary TV\"
rem echo %date% at %time%: Torrent %name% with label %label% to dir %todir% >> "C:\Users\Admin\Desktop\Utorrent Logs\Extracted_torrents.txt"
GOTO:EOF

:Extract_TV
"C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir% /target "s:\Extracted\HD TV\{ArchiveFolderName}"
GOTO Plex_Update

:Extract_Movies
"C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir% /target "{ArchiveFolderName}"
GOTO Plex_Update

:Extract_GaryTV
"C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir%" /target "s:\Extracted\Gary TV\{ArchiveFolderName}"
GOTO Plex_Update

:Extract_Games
"C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir% /target "s:\Extracted\Games\{ArchiveFolderName}"
GOTO:EOF

:Extract_Applications
"C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir% /target "s:\Extracted\Applications\{ArchiveFolderName}"
GOTO:EOF

:extractrar2
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 -o+ -ilog %fromdir%\*.rar *.* %todir%
echo %date% at %time%: Torrent %name% with label %label% to dir %todir% >> "C:\Users\Admin\Desktop\Utorrent Logs\Extracted_torrents.txt"
GOTO Plex_Update


:failed
echo %date% at %time%: Torrent %name% with label %label% >> "C:\Users\Admin\Desktop\Utorrent Logs\Failed.txt"
GOTO:EOF


:Plex_Update
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%=="HD TV" goto Refresh_TV
if %label%=="HD Movies" goto Refresh_Movies
if %label%=="Gary TV" goto Refresh_GaryTV
GOTO:EOF

:Refresh_TV
"C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe" --scan --section 1
GOTO:EOF

:Refresh_Movies
"C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe" --scan --section 3
GOTO:EOF

:Refresh_GaryTV
"C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe" --scan --section 4
GOTO:EOF

If anyone needs any help customizing I can lend a hand

Credit for Script goes to Axman84 for the Original Script

Share this post


Link to post
Share on other sites

Burningfire.. this is awesome!!

I was looking for something like this.. But if you could help me customizing it a bit, i would be really, really happy!!

My server is running on a debian based linux system, so what are my options?

What i need is, that the script copies the downloaded files to a folder, individually for each label, when the download had finished...

So for the label "familyguy"

the files would be copied to /media/tv/Family Guy/

And for the label "movie"

the files would be copied to /media/movie/

and so on...

Nothing needs to be extracted or postprocessed in any way. (or if its not too difficult, then how can extraction be included, but deactivated, to start with? (my mediacenter uses XBMC, and xbmc supports playback of mediafiles inside rar files...)

Would this be possible with your script?

Looking forward to hear from you..! :-)

Share this post


Link to post
Share on other sites

Everything possible :)

Just somethings needed to help with efficient scripting that I need from you

1. Where files are downloaded to ? ie. Same folder of different folders

2. Do you want the files that are downloaded Moved / Moved then Extracted or Just extracted.

3. Type of file formats expected to be encountered? ie.. .rar/.mkv/avi.mp4.zip

Depending on those answers I should be able to give you something simple you can edit and build upon.

Warning my Linux is rusty but still works last time I checked ....

Also if you wanted to you can run Utorrent using Wine to possibly make thing easier for you

Share this post


Link to post
Share on other sites

Updated Version

Changes:

:Cleaned up unused code

:Extracted Files will Maintain Directory Structure of where they are downloaded to

@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%
timeout /t 3 /nobreak
set fromdir=%1
set name=%2
set label=%3
set kind=%4
set filename=%5
set savepartition=S:
set moviedir=%fromdir%
set appsdir=%savepartition%\Extracted\Applications
set gamesdir=%savepartition%\Extracted\Games
set tvdir="%savepartition%\Extracted\HD TV"
set garytvdir="%savepartition%\Extracted\Gary TV"
rem set label_prefix=""
echo Input: %fromdir% %name% %label% %kind% %filename%

rem Determine length of label string
rem echo.%label%>len
rem 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")
rem if %len% geq 7 set label_prefix=%label:~1,5%
rem echo label_prefix = %label_prefix%

echo %date% at %time%: Torrent %name% with label %label% snagged >> "C:\Users\Admin\Desktop\Utorrent Logs\Grabbed_torrents.txt"

rem If label is "Movies"
if %label%=="HD Movies" goto HD_Movies

rem If label is "TV"
if %label%=="HD TV" goto HDTV

rem If label is "Applications"
if %label%=="Applications" goto Applications

rem If label is "PC Games"
if %label%=="PC Games" goto PC_Games

rem If label is "Gary TV"
if %label%=="Gary TV" goto Gary_TV

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.

:HD_Movies
echo **Movie
set todir=%moviedir%\%name%
echo todir = %todir%
rem If there are rar files in the folder, extract them.
rem if %kind%=="single" goto copyfile
rem if exist %fromdir%\*.mkv goto copymkvs
goto extractrar
echo Guess we didnt find anything
GOTO:EOF

:HDTV
echo **TV
set todir=%tvdir%\%name%
if %kind%=="single" goto copyfile
goto extractrar
echo Guess we didnt find anything
GOTO:EOF

:Gary_TV
echo **Gary_TV
set todir=%garytvdir%\%name%
if %kind%=="single" goto copyfile
goto extractrar
echo Guess we didnt find anything
GOTO:EOF

:Applications
echo **Applications
set todir=%appsdir%\%name%
rem if %kind%=="single" goto copyfile
rem if %kind%=="multi" goto copyall
goto extractrar
GOTO:EOF

:PC_Games
echo **Games
set todir=%gamesdir%\%name%
if %kind%=="single" goto copyfile
goto extractrar
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%
if %label%=="HD TV" goto Extract_TV
if %label%=="HD Movies" goto Extract_Movies
if %label%=="Gary TV" goto Extract_GaryTV
if %label%=="PC Games" goto Extract_PC_Games
if %label%=="Applications" goto Extract_Applications
GOTO:EOF

:Extract_TV
"C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir% /target "s:\Extracted\{ArchiveFolderStructure}"
GOTO Plex_Update

:Extract_Movies
"C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir% /target "{ArchiveFolderName}"
GOTO Plex_Update

:Extract_GaryTV
"C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir%" /target "s:\Extracted\{ArchiveFolderStructure}"
GOTO Plex_Update

:Extract_PC_Games
"C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir% /target "s:\Extracted\{ArchiveFolderStructure}"
GOTO:EOF

:Extract_Applications
"C:\Program Files (x86)\ExtractNow\extractnow.exe" %fromdir% /target "s:\Extracted\{ArchiveFolderStructure}"
GOTO:EOF

:failed
echo %date% at %time%: Torrent %name% with label %label% >> "C:\Users\Admin\Desktop\Utorrent Logs\Failed.txt"
GOTO:EOF


:Plex_Update
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%=="HD TV" goto Refresh_TV
if %label%=="HD Movies" goto Refresh_Movies
if %label%=="Gary TV" goto Refresh_GaryTV
GOTO:EOF

:Refresh_TV
"C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe" --scan --section 1
GOTO:EOF

:Refresh_Movies
"C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe" --scan --section 3
GOTO:EOF

:Refresh_GaryTV
"C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe" --scan --section 4
GOTO:EOF

Share this post


Link to post
Share on other sites

I tried this version does not work

http://s3.nwgat.net/lftp-win/lftp%204.4.10%20win32.7z

lftp 4.4.10 win32

Error on line 15

Please guide

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

Share this post


Link to post
Share on other sites

Hey Burningfire. Thanks for the reply.

1. At the moment my files are only downloaded to the folder i specify. But if i had a script, i would download them to this temporary folder:

/torrent/temp/

And then i would like the files to be extracted to either:

this folder for tv shows: (each tv show in its own folder - depending on the label i give it)

/torrent/tv/family guy/

or

/torrent/tv/White Collar/

And for movies (all movies go in the same folder, but in their own folders:

/torrent/movie/

2. I would very much like the files to be only extracted. I need to keep a good seed ratio, so i will delete the original files myself, when they are ready for it. :)

3. Format types, that are expected are rar/mkv/srt/avi/mp4/mpg

That is all i can think of right now. If there is anything else, please let me know.

So could i change some of the folder paths, and filenames encountered later on if i would need to?

I'm really looking forward to see what you come up with! Once again, thanks so much for your help!!!!

By the way...I will remember what you said about Wine..but for now i have Utorrent working pretty good on my Debian setup..:)

Share this post


Link to post
Share on other sites

Sorry to Necro but I'm trying to figure something out and its not too dissimilar to what the OP is doing.

 

Current Setup:
UT2..2.1 on W7(Migrating to 08R2 box)

RSS feed for 90% of my content

Not using lables

 

When a torrent finishes I currently run a script which checks if its TV and then calls xcopy to start copying it into \Dropbox\Tv then closes. Its kind of hacked together, but it works perfectly and when I turn on my laptop my "to be watched" stuff instantly starts syncing. Super.

 

What I want to do:
Implement a second script to be called after the TV->Dropbox one that cleans up my download directory and sorts content out. Right now I have \Incomplete\ and \Complete\ only, what I'm moving to is \Incomplete\ \Complete\ AND \TV\[show]\, \Movies\ and \Misc\. With infinite seeding. 

This basically means implementing UT's "Set Download Location..." button into a script so that the files move as per my rules and UT follows them and the seed is continued. Plex and my FTP server will do the rest from there. Anything that doesnt match can be left in \Complete\ and I'll move it manually.

 

In summary, is there any way to call UT and get it to do the move, or can I implement it by copying the files, updating utorrents resume.dat and then deleting the source files? Would this require rebooting UT every time?

 

Thanks,

Scratch

Share this post


Link to post
Share on other sites