【问题标题】:uTorrent Batch ScriptuTorrent 批处理脚本
【发布时间】:2014-01-10 13:48:11
【问题描述】:

我根据我发现的另一个脚本为自己编写了一个脚本,但我无法弄清楚它为什么不起作用。

它的工作原理是,一旦 torrent 完成下载,它就会运行脚本并获取 torrent 上的标签。为了测试,我正在下载一首带有 Music 标签的歌曲。 当它到达 :copyfile 时,它​​不会将它移动到正确的目录中。它没有移动到 F:\Completed Torrents\Music,而是移动到 F:\Completed Torrents。

谁能指出我错过了什么,因为我已经看过三次了,这让我发疯了。脚本如下。

@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

【问题讨论】:

  • 您的代码中存在引用问题的行数多于正确行数。您可能知道,SO 是 'professional and enthusiast programmers' 的地方,而不是模仿者。
  • 您似乎有很多 echo 语句显示处理中的事件。现在,如果您与我们分享这些内容,我们将能够更好地提供帮助......
  • @Endoro 如果您阅读第一行,“基于另一行”。我从未承认自己是专业人士,但我喜欢编程。 Magoo 不幸的是,它不是那样工作的......当洪流完成后,它会运行批处理脚本。无论您在其中放入多少暂停语句,它都会绕过它们。你甚至看不到窗户。
  • 尝试缩小您的问题范围,或专注于表现不符合预期的特定行。如果您的问题有一百行代码并且您只是说“它不起作用”,那么您就不能期望得到一个好的答案。例如,有很多方法可以到达 :copyfile,但在您的情况下,我们无法知道它是如何到达那里的,因此无法知道 %todir% 的值。尝试为您的特定情况删除所有不必要的代码,然后编辑您的问题,这样您最多只需要提供十几行代码。很可能到那时你自己已经发现了问题。

标签: batch-file utorrent


【解决方案1】:

几位给你:

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

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

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

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

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

【讨论】:

    【解决方案2】:

    你说日志没有被写入。试试这个作为测试,看看它是否写入日志。

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

    @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%"
    

    【讨论】:

    • 不幸的是,这具有相同的结果。 :(
    • 那么你的批处理文件没有运行或者你的日志文件有权限问题。再次尝试上面编辑的代码,看看是否在您的桌面上创建了日志文件。
    • 我知道批处理文件运行是因为它执行脚本的移动部分(只是不移动到正确的文件夹)。
    • 不,它没有运行。除非您测试了上述内容并且它创建了日志文件。如果它没有创建日志文件,那么 Utorrent 很可能会自行将文件移动到已完成的文件夹中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    相关资源
    最近更新 更多