Jump to content

uTorrent Auto Download


JohnOne
 Share

Recommended Posts

Only made this after seeing a question in GHAS, and thought it could be usefull to someone.

Its use could be, If you are waiting on a torrent that normally appears at a certain time (you know those free/shareware apps or publications you like to read) and you are going out or to bed.

What this does is looks at the isohunt page (There are tons of torrent sites so you would have to parse the page yourself to use it on another) for the title of the torrent you want, and automatically adds it to your list and downloads if it shows up. You add the intervals it checks in minutes.

Best to use the full and most precise name (as it appears on the site list) as you can.

Anyway its just an example, but any comments, or mockery are welcome.

#include <Inet.au3>
#include <String.au3>

Global $sDLURL = "http://isohunt.com" ;------------------------- URL of isohunt
Global $sLURL = "/latest.php?mode=bt" ;------------------------- Page of latest torrents
Global $sExePath = 'C:\Program Files\uTorrent\uTorrent.exe' ;--- µTorrent exe path
Global $switch1 = ' /DIRECTORY' ;------------------------------- Switch - param 1 = save dir, param 2 = torrent path
Global $param1 = 'C:\Your\download\Folder\' ;------------------- Save dir
Global $switch2 = ' /HIDE' ;------------------------------------ Switch "/HIDE" or "/MINIMIZE" (use when app not running)
Global $found = False

HotKeySet("^{ESC}","_Exit")

$Gui = GUICreate("ADµTorrent", 250, 80, 400, 400)
$Input1 = GUICtrlCreateInput("Enter Torrent Name", 10, 10, 230, 17)
$Input2 = GUICtrlCreateInput("Check Torrent Every", 10, 47, 105, 17)
$lable = GUICtrlCreateLabel("Minutes", 120, 50, 40, 17)
$OK = GUICtrlCreateButton("OK", 180, 47, 60, 17)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case $OK
            $sTorrentName = GUICtrlRead($Input1)
            $iMins = GUICtrlRead($Input2)
            GUIDelete($Gui)
            _Start($sTorrentName, $iMins)
    EndSwitch
    Sleep(10)
WEnd

Func _Start($name, $mins)
    Do
        _Search_Title($name)
        Sleep(($mins * 1000) * 60)
    Until $found = True
    Exit
EndFunc   ;==>_Start

Func _Add_Torrent($param2 = "") ;---------------------------------------------- Torrent path (generated during search -@scriptdir + name)
    If $param2 <> "" Then
        $found = True
        Beep(800, 200)

        Local $PID = Run($sExePath & " " & $switch1 & " " & $param1 & " " & $param2 & $switch2, "", @SW_HIDE)
        Local $hwnd
    EndIf
    While 1
        If WinActive("µTorrent 2.0.2") Then
            If WinSetState("µTorrent 2.0.2", "", @SW_MINIMIZE) = 1 Then;-- This is just to minimize the window if app is running
                ExitLoop
            EndIf
        EndIf
        Sleep(10)
    WEnd
    _CheckState()
EndFunc   ;==>_Add_Torrent

Func _CheckState()
    If $found Then
        Exit
    EndIf
EndFunc   ;==>_CheckState

Func _Search_Title($Title)
    Local $sSource = _INetGetSource($sDLURL & $sLURL)
    Local $aLinkArray = _StringBetween($sSource, "[DL]", "</a>")
    Local $Torrent
    For $i = 0 To UBound($aLinkArray) - 1
        $a = StringSplit($aLinkArray[$i], '"', 3)
        $s_L_Title = $a[(UBound($a) - 1)]
        If StringInStr($s_L_Title, $Title) Then
            $s_Link = $sDLURL & $a[1]
            ConsoleWrite($s_Link & @CRLF)
            $Torrent = _Get_Torrent($s_Link, $s_L_Title)
        EndIf
    Next
    _Add_Torrent($Torrent)
EndFunc   ;==>_Search_Title

Func _Get_Torrent($sLink, $s_Name)
    Local $sName = StringTrimLeft($s_Name, 1)
    $sName = StringReplace($sName, " ", "")
    Local $sFilePath = @ScriptDir & "\" & $sName & ".torrent"
    If InetGet($sLink, $sFilePath, 1) = 0 Then
        Beep(800, 400)
        Return False
    EndIf
    Return $sFilePath
EndFunc   ;==>_Get_Torrent

Func _Exit()
    Exit
EndFunc

EDIT:

Swapped stringregexpreplace in favour of stringreplace.

Thanks czardas.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Nice idea, but how does it know that the torrent file is exactly the title you want and not another torrent with the same title? For example if it's an executable you're after, and you end up with a mediia file.

Do you need to use StringRegExpReplace?

Edited by czardas
Link to comment
Share on other sites

Nice idea, but how does it know that the torrent file is exactly the title you want and not another torrent with the same title? For example if it's an executable you're after, and you end up with a mediia file.

Do you need to use StringRegExpReplace?

You cannot be 100% caertain, thats why I mentioned being as precise as possible, for instance I would add the full name including release group and date and edition/episode that I knew would be appearing.

It needs stringregexpreplace because where its used becomes part of $param2 that is passed to uTorrent, and it dosent like spaces in there.

Thanks for your comments.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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...