2014-01-10 37 views
0

我爲自己寫了一個基於另一個腳本的腳本,我發現它很難找出爲什麼它不起作用。uTorrent批處理腳本

它應該如何工作是一旦洪流完成下載,它運行腳本並抓取洪流上的標籤。爲了測試,我正在下載一首帶有音樂標籤的歌曲。 當它到達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

+0

您的代碼與正確的行有更多的引用問題。正如你可能知道的那樣,SO是專業和熱心程序員的地方,而不是仿冒者。 – Endoro

+0

您似乎有很多'echo'語句顯示處理中的事件。現在,您可以與我們分享這些信息,我們可以更好地幫助您... – Magoo

+0

@Endoro如果您閱讀第一行「基於另一個」。我從來沒有承認是一個專業,但我喜歡編程。 Magoo不幸的是,它不能像那樣工作...一旦洪流完成,它就運行批處理腳本。無論你放入多少暫停語句,它都會繞過它們。你甚至看不到窗戶。 – Spedwards

回答

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%" 
+0

不幸的是,這有相同的結果。 :( – Spedwards

+0

查看我編輯的答案 – foxidrive

+0

仍然沒有任何日誌 – Spedwards

1

一種亞夫婦位:

1)可能的是,你的腳本是不動的文件。首選項/目錄可以在完成時移動下載的選項。確認這些設置沒有在移動文件。

2)uTorrent完成鎖定文件,以便種子可以繼續。要改變這種行爲,轉到首選項/高級,並設置bt.read_only_on_complete爲假

3)你仍然會被挫敗,因爲「當一個洪流結束時運行這個程序」並沒有真正做它說的。它在下載達到100%時運行程序,但uTorrent仍在移動文件或播種。看到我的錯誤報告here

這篇文章的快速總結,以防萬一帖子被刪除:您必須在「在torrent更改狀態時運行此程序:」中添加命令,並添加%S參數並檢查%S == 11

4)我試圖做一些非常相似的事情:當你從參數中設置變量時,添加一個代字號(%〜1而不是%1)。這將消除引號,讓我們更容易地構建後續變量的命令行。