Jump to content

uTorrent automation jobs


Recommended Posts

Just discovered AutoIt, pretty interesting. But before I start testing out, I would like to know if what I want to do is possible.

I would need to run the script every X minutes to control uTorrent. uTorrent window could be active, inactive or minimized in tray, if that matters.

What I want to do is checking if torrent A has X amount of seeders, then set Maximum Upload Speed to '1' AND label torrent "Seeding: Slowed".

Else: set Maximum Upload Speed to '0' wich is unlimited, and label torrent "Seeding: Full speed".

There are two ways to know how many seeders for each torrent: column, and torrent properties window.

The only way to label a torrent is by right clicking it and choosing a label.

The script would have to check thousands of torrents at once.

Link to comment
Share on other sites

I looked in the Help, and to be honnest I don't really know where to start. There's a lot of stuff in there, and what I want to achieve is more than a simple 'Hello World' script.

Anyone would be kind enough to put me on the right track? I don't really know what functions to look at. Once I know, I'll be able to do the rest myself. Well, I'll try at least :)

A good start would be to know how to get to the torrent properties window. Then I'll be able to get all the infos I need myself, change values, etc..

I thought each torrent would have a different ID # or something like that and then I could get the number of torrents, and check the # of seeders and upload speed set of each one, but using AutoIt Window Info I couldn't find an individual ID for each torrent.. so yeah. I don't know. :-/

Link to comment
Share on other sites

I think this should work:

#Include <GuiListView.au3>
#include <WinAPI.au3>

Opt("WinTitleMatchMode", 4)

Dim $MaxSeeds = 30 ; Change this value to desired max ammount of seeders before it should limit upload
Dim $ReCheckTime = 5 ; Number of minutes it should wait before rechecking already limited torrents/downloads
Dim $aItems[1024][2] ; You can increase 1024 to any number of max torrents/downloads you want to support/check




; should not be any need to change any of the code below

$iPid = ProcessExists("uTorrent.exe")
If Not $iPid Then Exit 1

; This gets the main window of uTorrent
$hWindow = _ProcessGetWinEx("uTorrent.exe", "", "Torrent")
If Not $hWindow[0] Then Exit 1

; Gets the handle of the list of the torrents/downloads
$hControl = ControlGetHandle($hWindow[1], "", "[CLASSNN:SysListView322]")

; Gets the "Seeds" column
$iColumn = _GetSeedsColumn()
If $iColumn = -1 Then Exit 1

; Continously checks the torrents in the list each 1.5 second
While 1
    _CheckSeeds()
    Sleep(1500)
WEnd

Func _CheckSeeds()
    Local $iItemCount = _GUICtrlListView_GetItemCount($hControl)
    For $i = 0 To $iItemCount-1
        $iSeeds = _GUICtrlListView_GetItemText($hControl, $i, $iColumn)
        $iSeeds = Number(StringLeft($iSeeds, StringInStr($iSeeds, "(")-2))
        If $iSeeds >= $MaxSeeds And (Not $aItems[$i][0] Or ($aItems[$i][0] And TimerDiff($aItems[$i][1]) >= ($ReCheckTime*60*1000))) Then
            $aItems[$i][1] = TimerInit()
            $aItems[$i][0] = True
            _LimitUpload($i)
        ElseIf $iSeeds < $MaxSeeds Then
            $aItems[$i][1] = 0
            $aItems[$i][0] = False
        EndIf
        Sleep(1)
    Next
EndFunc

Func _LimitUpload($iItemIndex)
    If Not Winactive($hWindow[1]) Then WinActivate($hWindow[1])
    Do
        WinActivate($hWindow[1])
        Sleep(250)
    Until WinActive($hWindow[1])
    
    ConsoleWrite("Clicking on item with index: " & $iItemIndex & @LF)
    
    _GUICtrlListView_ClickItem($hControl, $iItemIndex, "right", False, 1, 1)
    
    ControlSend("[ACTIVE]", "", "", "{down 10}{right}{down 4}{right}{down}{enter}")
    
EndFunc

Func _ProcessGetWinEx($ivPid, $svClass = "", $svTitle = "", $svText = "")
   
    $ivPid = ProcessExists($ivPid)
    If Not $ivPid Then Return(SetError(1, 0, 0))
    
    Local $avwArray = WinList()
    Local $avRet[1] = [0]
   
    For $i = 1 To $avwArray[0][0]
        If WinGetProcess($avwArray[$i][1]) = $ivPid Then
            If $svClass = "" Or _WinAPI_GetClassName($avwArray[$i][1]) = $svClass Then
                If ($svTitle = "" Or StringInStr($avwArray[$i][0], $svTitle)) And ($svText = "" Or StringInStr(WinGetText($avwArray[$i][1]), $svText)) Then
                    $avRet[0] += 1
                    ReDim $avRet[$avRet[0]+1]
                    $avRet[$avRet[0]] = $avwArray[$i][1]
                EndIf
            EndIf
        EndIf
    Next
   
    Return $avRet
   
EndFunc

Func _GetSeedsColumn()
    Local $iColumns = _GUICtrlListView_GetColumnCount($hControl)
    For $i = 0 To $iColumns-1
        Local $aColumn = _GUICtrlListView_GetColumn($hControl, $i)
        If $aColumn[5] = "Seeds" Then 
            Return $i
        EndIf
    Next
    Return -1
EndFunc

Note that it requires that you don't click around, etc. when it tries to limit a torrent, because then it will mess up..

Link to comment
Share on other sites

Wow, greeeat.

There seem to be a problem somewhere.

I've tested out by putting a MsgBox to see where the script exits and it seems to be in the _GetSeedsColumn() function

Did you test it yourself? Was it working?

in $aColumn[5], does the 5 stands for 5th column? If so, I better use a variable to set manually as it can change. That's all I came up with so far :)

Thanks alot

Link to comment
Share on other sites

Hmm, it should work, all that function does is look through all the columns until it finds one with the text "Seeds", that's to counter possible re-arrangement of the columns..

Yes, I tried it, and it workt just fine for me. :)

The 5 in $aColumn[5] is the "Column header text", returned from the _GUICtrlListView_GetColumn function.

Edited by FreeFry
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...