uTorrent批处理脚本

时间:2014-01-10 13:48:12

标签: batch-file utorrent

我自己写了一个基于我找到的另一个脚本的脚本,但我无法弄清楚它为什么不起作用。

它应该如何工作是一旦洪流完成下载,它运行脚本并抓取torrent上的标签。为了测试,我正在下载一首带有音乐标签的歌曲。 当它到达:copyfile时,它不会将它移动到正确的目录中。而不是进入F:\ Completed Torrent \ Music,它只是进入F:\ Completed Torrent。

有人可以指出我错过了什么,因为我已经三次看了它,这让我发疯了。脚本如下。

@echo off
title Liam's 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="F:\Completed Torrents"
set winrar="C:\Program Files (x86)\WinRAR\WinRAR.exe"
set torrentlog="F:\Torrent Scripts\logs\torrentlog.txt"
set handledlog="F:\Torrent Scripts\logs\handled_torrents.txt"
set errorlog="F:\Torrent Scripts\logs\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%=="Music" goto known
if %label_prefix%=="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

:TV
echo **Known Download Type - %label%
set todir=%savepartition%\%label_prefix%\%label_suffix%
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:EOF

: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: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%
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:EOF

修改 此外,由于某种原因,在第39行没有打印到日志。对于那些希望看到包含行号的代码的人:http://hastebin.com/juqokefoxa.dos

2 个答案:

答案 0 :(得分:1)

ya的几位:

1)可能,您的脚本没有移动文件。首选项/目录可以选择在完成后移动下载。验证这些设置是否正在移动文件。

2)uTorrent在完成时锁定文件,以便继续播种。要更改此行为,请转到“首选项/高级”并将bt.read_only_on_complete设置为false

3)你仍然会被挫败因为"当一个种子完成时运行这个程序"并没有真正按照它说的做。当下载达到100%时,它运行程序,但是uTorrent仍在移动文件或播种。查看我的错误报告here

帖子的快速摘要,以防邮件被删除:你必须在"设置命令时,当torrent更改状态时运行此程序:",添加%S参数并检查%S == 11

4)我尝试做一些非常相似的事情只是一个提示:当您从参数设置变量时,添加波浪号(%〜1而不是%1)。这将删除引号,让我们以后更容易使用变量构建命令行。

答案 1 :(得分:0)

您说没有写入日志。尝试将其作为测试,看看它是否写入日志。

如果不存在,则存在其他一些基本问题。

@echo off
title Liam's 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=F:\Completed Torrents"
set "winrar=C:\Program Files (x86)\WinRAR\WinRAR.exe"
set "torrentlog=F:\Torrent Scripts\logs\torrentlog.txt"
set "handledlog=F:\Torrent Scripts\logs\handled_torrents.txt"
set "errorlog=F:\Torrent Scripts\logs\ErrorLog.txt"
set "label_prefix="

set "handledlog=%userprofile%\desktop\handled_torrents.txt"

>> "%handledlog%" echo Input: "%fromdir%" "%name%" "%label%" "%kind%" "%filename%"
>> "%handledlog%" echo %date% at %time%: Handling "%label%" torrent "%name%"