Lynkz83

uTorrent Batch File

Sep 14th, 2012
441
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rem uTorrent Automatic Download Handler
  2. rem Author Lynkz83
  3. rem Inspiration: Axman84 Thread: http://forum.utorrent.com/viewtopic.php?id=110024
  4. rem Setup this batch file passes the following variables from uTorrent to CMD Prompt:
  5. rem "%D" "%N" "%L" "%K" "%F"
  6. rem In order to use, create new folder C:\uScripts\ and place this file in to it.
  7. rem Open uTorrent and and browse to the created folder and type
  8. rem "C:\uScripts\uTorrent ADH.bat" "%D" "%N" "%L" "%K" "%F" >> C:\uScripts\Logs\torrentlog.txt
  9. echo Run on %date% at %time%
  10. Title uTorrent Automatic Download Handler
  11.  
  12. set fromdir=%1
  13. set name=%2
  14. set label=%3
  15. set kind=%4
  16. set filename=%5
  17. set savepartition=G:\Media
  18. set winrar="c:\program files\winrar\winrar.exe"
  19. set torrentlog=C:\uScripts\Logs\torrentlog.txt
  20. set handledlog=C:\uScripts\Logs\handled_torrents.txt
  21. set errorlog=C:\uScripts\Logs\ErrorLog.txt
  22. set label_prefix=""
  23.  
  24. echo Input: %fromdir% %name% %label% %kind% %filename%
  25.  
  26. rem Check if the label has a sub label by searching for \
  27. if x%label:\=%==x%label% goto skipsublabel
  28.  
  29. rem Has a sub label so split into prefix and suffix so we can process properly later
  30. echo sub label
  31. for /f "tokens=1,2 delims=\ " %%a in ("%label%") do set label_prefix=%%a&set label_suffix=%%b
  32.  
  33. rem add the removed quote mark
  34. set label_prefix=%label_prefix%"
  35. set label_suffix="%label_suffix%
  36. echo.prefix  : %label_prefix%
  37. echo.suffix  : %label_suffix%
  38. goto:startprocess
  39.  
  40. :skipsublabel
  41. echo Skipped Sub Label
  42. goto:startprocess
  43.  
  44. :startprocess
  45. echo %date% at %time%: Handling %label% torrent %name% >> %handledlog%
  46.  
  47. rem Process the label
  48. if %label_prefix%=="Movies" goto known
  49. if %label_prefix%=="TV" goto known
  50. if %label_prefix%=="Games" goto known
  51. if %label_prefix%=="Music" goto known
  52. if %label_prefix%=="Animation" goto known
  53. if %label_prefix%=="Applications" goto known
  54. if %label%=="Books" goto known
  55. if %label%=="OpenTracker" goto known
  56.  
  57. rem Last Resort
  58. rem This field is for anything that doesnt match the above labels processing
  59. echo Last Resort
  60. set todir=%savepartition%\%label%\__%name%
  61. if %kind%=="single" goto copyfile
  62. if %kind%=="multi" goto copyall
  63. GOTO:EOF
  64.  
  65. :known
  66. echo **Known Download Type - %label%
  67. set todir=%savepartition%\%label%\%name%
  68. echo todir = %todir%
  69. GOTO:process
  70.  
  71. :process
  72. rem If there are rar files in the folder, extract them.
  73. rem If there are mkvs, copy them. Check for rars first in case there is a sample.mkv, then we want the rars
  74. if %kind%=="single" goto copyfile
  75. if exist %fromdir%\*.rar goto extractrar
  76. if exist %fromdir%\*.mkv goto copymkvs
  77. if %kind%=="multi" goto copyall
  78. if exist %fromdir%\cd1\*.rar goto :unpack_CD1_rar
  79. echo Guess we didnt find anything
  80. GOTO:EOF
  81.  
  82. :copyall
  83. echo **Type unidentified so copying all
  84. echo Copy all contents of %fromdir% to %todir%
  85. xcopy %fromdir%\*.* %todir% /S /I /Y
  86. GOTO:EOF
  87.  
  88. :copyfile
  89. rem Copies single file from fromdir to todir
  90. echo Single file so just copying
  91. echo Copy %filename% from %fromdir% to %todir%
  92. xcopy %fromdir%\%filename% %todir%\ /S /Y
  93. GOTO:EOF
  94.  
  95. :copymkvs
  96. echo Copy all mkvs from %fromdir% and subdirs to %todir%
  97. xcopy %fromdir%\*.mkv %todir% /S /I /Y
  98. GOTO:EOF
  99.  
  100. :unpack_CD1_rar
  101. IF EXIST %fromdir%\subs xcopy %fromdir%\subs %todir% /S /I /Y
  102. IF EXIST %fromdir%\subtitles xcopy %fromdir%\subtitles %todir% /S /I /Y
  103. call %winrar% x %fromdir%\CD1\*.rar *.* %todir% -IBCK  -ilog"%todir%\RarErrors.log"
  104. goto :unpack_cD2_rar
  105.  
  106. :unpack_CD2_rar
  107. IF EXIST %fromdir%\subs xcopy %fromdir%\subs %todir% /S /I /Y
  108. IF EXIST %fromdir%\subtitles xcopy %fromdir%\subtitles %todir% /S /I /Y
  109. call %winrar% x %fromdir%\CD2\*.rar *.* %todir% -IBCK  -ilog"%todir%\RarErrors.log"
  110. goto :EOF
  111.  
  112. :extractrar
  113. echo Extracts all rars in %fromdir% to %todir%.
  114. rem Requires WinRar installed to c:\Program files
  115. if not exist %todir% mkdir %todir%
  116. IF EXIST %fromdir%\subs xcopy %fromdir%\subs %todir% /S /I /Y
  117. IF EXIST %fromdir%\subtitles xcopy %fromdir%\subtitles %todir% /S /I /Y
  118. call %winrar% x %fromdir%\*.rar *.* %todir% -IBCK  -ilog"%todir%\RarErrors.log"
  119. IF EXIST %fromdir%\*.nfo xcopy %fromdir%\*.nfo %todir% /S /I /Y
  120. GOTO:EOF
  121.  
  122. :eof
  123. echo processing complete
  124. exit
RAW Paste Data