► Afficher le texte
#include-once
#include <String.au3>
; #FUNCTION# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; Name...........: _TorrentAdd_URL
; Description ...: Adds a torrent to your µtorrent job list
; Syntax.........: _TorrentAdd_URL($sUser, $sPass, $sTorrentURL, $sIP, $sPort)
; Parameters ....: $sUser - Username as set in the Web UI settings of µtorrent.
; $sPass - Password as set in the Web UI settings of µtorrent.
; $sTorrentURL - http address of the torrent you want to add.
; $sIP - [Optional] Local or remote IP of the target machine running µtorrent (Deafault = @IPAddress1).
; $sPort - [Optional] Port to access as set in the Web UI settings of µtorrent (Default = "8080").
; Return values .: Success - True
; Failure - False
; Author ........: JohnOne
; Modified.......:
; Remarks .......: All parameters should be string type
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Func _TorrentAdd_URL($sUser, $sPass, $sTorrentURL, $sIP = @IPAddress1, $sPort = "8080")
$aParams = _Get_Token($sUser, $sPass, $sIP, $sPort)
$sURL = $aParams[0] & "?token=" & $aParams[1] & "&action=add-url&s=" & $sTorrentURL
$temp = BinaryToString(InetRead($sURL), 1)
If StringInStr($temp, '"build"') Then
Return True
Else
Return False
EndIf
EndFunc ;==>_TorrentAdd_URL
; #FUNCTION# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; Name...........: _TorrentAction
; Description ...: Performs an action on a torrent in your µtorrent job list
; Syntax.........: _TorrentAction($sUser, $sPass, $sTorrentName, $sAction, $sIP, $sPort)
; Parameters ....: $sUser - Username as set in the Web UI settings of µtorrent.
; $sPass - Password as set in the Web UI settings of µtorrent.
; $sTorrentName - Name of the torrent you wish to work with.
; $sAction - The action to perform on the torrent...below
;
; start
; stop
; pause
; unpause
; forcestart
; recheck
; remove
; removedata
; setprio
;
; $sIP - [Optional] Local or remote IP of the target machine running µtorrent (Deafault = @IPAddress1).
; $sPort - [Optional] Port to access as set in the Web UI settings of µtorrent (Default = "8080").
; Return values .: Success - True
; Failure - False
; Author ........: JohnOne
; Modified.......:
; Remarks .......: All parameters should be string type
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Func _TorrentAction($sUser, $sPass, $sTorrentName, $sAction, $sIP = @IPAddress1, $sPort = "8080")
$sHash = _Get_Hash($sUser, $sPass, $sTorrentName, $sIP, $sPort)
$aParams = _Get_Token($sUser, $sPass, $sIP, $sPort)
$sURL = $aParams[0] & "?token=" & $aParams[1] & "&action=" & $sAction & "&hash=" & $sHash
$temp = BinaryToString(InetRead($sURL), 1)
If StringInStr($temp, '"build"') Then
Return True
Else
Return False
EndIf
EndFunc ;==>_TorrentAction
; #FUNCTION# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; Name...........: _List_Torrents
; Description ...: Returns a list of all the current torrent jobs and the states they are in
; Syntax.........: _List_Torrents($sUser, $sPass, $sIP, $sPort)
; Parameters ....: $sUser - Username as set in the Web UI settings of µtorrent.
; $sPass - Password as set in the Web UI settings of µtorrent.
; $sIP - [Optional] Local or remote IP of the target machine running µtorrent (Deafault = @IPAddress1).
; $sPort - [Optional] Port to access as set in the Web UI settings of µtorrent (Default = "8080").
; Return values .: Success - 2 Dimentional array, where the colums represent the torrent jobs and rows are the properties.
; [0][0] = The hash of the torrent
; [1][0] = The The state of the torrent
; [2][0] = The name of the torrent
; [3][0] = The size of the torrent (bytes)
; [4][0] = The progress percentage (1000 = 100.0) complete
; [5][0] = The amount downloaded (bytes)
; [6][0] = The amount uploaded (bytes)
; [7][0] = The torrent ratio
; [8][0] = The upload speed (bps)
; [9][0] = The download speed (bps)
; [10][0] = The ETA (seconds)
; [11][0] = The torrent label
; [12][0] = The amount of connected peers
; [13][0] = The amount of peers in the swarm
; [14][0] = The amount of connected seeds
; [15][0] = The amount of seeds in the swarm
; [16][0] = The availability
; [17][0] = The queue order of the torrent
; [18][0] = The amount remaining to download(to finish the torrent) (bytes)
;
; Failure - 0
; Author ........: JohnOne
; Modified.......:
; Remarks .......: All parameters should be string type
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Func _List_Torrents($sUser, $sPass, $sIP = @IPAddress1, $sPort = "8080")
$aList = _Get_List(_Get_Token($sUser, $sPass, $sIP, $sPort))
If IsArray($aList) Then
Return $aList
Else
Return 0
EndIf
EndFunc ;==>_List_Torrents
; #FUNCTION# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;
; Name...........: _TorrentSet_GL_UD
; Description ...: Sets the global Upload and Download rate
; Syntax.........: _TorretSet_GL_UD($sUser, $sPass, $sUp, $sDown, $sIP, $sPort)
; Parameters ....: $sUser - Username as set in the Web UI settings of µtorrent.
; $sPass - Password as set in the Web UI settings of µtorrent.
; $sUp - [Optional] Global upload rate in KB (Default is 0, unlimited)
; $sDown - [Optional] Global Download rate in KB (Default is 0, unlimited)
; $sIP - [Optional] Local or remote IP of the target machine running µtorrent (Deafault = @IPAddress1).
; $sPort - [Optional] Port to access as set in the Web UI settings of µtorrent (Default = "8080").
; Return values .: Success - True
; Failure - False
; Author ........: JohnOne
; Modified.......:
; Remarks .......:
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Func _TorrentSet_GL_UD($sUser, $sPass, $sUp = 0, $sDown = 0, $sIP = @IPAddress1, $sPort = "8080")
$aParams = _Get_Token($sUser, $sPass, $sIP, $sPort)
$sURL = $aParams[0] & "?token=" & $aParams[1] & "&action=setsetting&s=max_ul_rate&v=" & $sUp & "&s=max_dl_rate&v=" & $sDown
$temp = BinaryToString(InetRead($sURL), 1)
If StringInStr($temp, '"build"') Then
Return True
Else
Return False
EndIf
EndFunc
; #FUNCTION# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;
; Name...........: _Get_Settings
; Description ...: Retrieves a list of settings, variable types, and current values supported in your version of µtorrent.
; Syntax.........: _Get_Settings($sUser, $sPass, $sIP, $sPort)
; Parameters ....: $sUser - Username as set in the Web UI settings of µtorrent.
; $sPass - Password as set in the Web UI settings of µtorrent.
; $sIP - [Optional] Local or remote IP of the target machine running µtorrent (Deafault = @IPAddress1).
; $sPort - [Optional] Port to access as set in the Web UI settings of µtorrent (Default = "8080").
; Return values .: Success - A 2 dimensional array, where colum 0 = the setting name, colum 1 = the type of variable you can use....
; ... (0=integer 1=boolean 2=string), colum 2 = The current setting of the variable.
; Failure - False
; Author ........: JohnOne
; Modified.......:
; Remarks .......:The list returned from this function is to get info on a setting you can alter using _Set_Settings() function
; There are too many to list here and they may vary between µtorrent versions
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Func _Get_Settings($sUser, $sPass, $sIP = @IPAddress1, $sPort = "8080")
Local $tmpfile = @ScriptDir & "\temp.txt"
$aParams = _Get_Token($sUser, $sPass, $sIP, $sPort)
$GSettings_URL = $aParams[0] & "?action=getsettings&token=" & $aParams[1]
$temp = InetRead($GSettings_URL)
$temp = BinaryToString($temp, 1)
$temp = StringRegExpReplace($temp, "(\s)", "")
$temp = _StringBetween($temp,"[[", "]]")
FileWrite($tmpfile,$temp[0])
$sfile = FileRead($tmpfile)
$atemp = StringSplit($sfile, "],[" , 3)
Local $aFinalList[UBound($atemp)][3]
For $i = 0 To UBound($atemp)-1
$atemp2 = StringSplit($atemp[$i], ",", 2)
For $j = 0 To 2
$aFinalList[$i][$j] = $atemp2[$j]
Next
Next
$atemp = 0
FileDelete($tmpfile)
If IsArray($aFinalList) And $aFinalList[0][2] <> "" Then
Return $aFinalList
Else
Return False
EndIf
EndFunc
; #INTERNAL FUNCTIONS# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; Name...........: _Get_Token
; Description ...: Retrieves a security token needed to acces the web API
;
; Name...........: _Get_List
; Description ...: Retrieves a list of torrents, using the token
;
; Name...........: _Get_Hash
; Description ...: Retrieves a hash of a given torrent, needed to perform actions on them
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Func _Get_Token($sUser, $sPass, $sIP = @IPAddress1, $sPort = "8080")
Local $aRet[2]
$sBase_URL = "http://" & $sUser & ":" & $sPass & "@" & $sIP & ":" & $sPort & "/gui/"
$sToken_URL = $sBase_URL & "token.html"
$aRet[0] = $sBase_URL
$aRet[1] = StringMid(BinaryToString(InetRead($sToken_URL, 1)), 45, 60)
Return $aRet
EndFunc ;==>_Get_Token
Func _Get_List($aParams)
$sList_URL = $aParams[0] & "?list=1" & "&token=" & $aParams[1]
$temp = _StringBetween(StringRegExpReplace(BinaryToString(InetRead($sList_URL, 1)), "(\s)", ""), "[[", "]]")
$aList = StringSplit($temp[0], "],[", 3)
Local $aFinalList[19][UBound($aList)]
For $i = 0 To UBound($aFinalList, 2) - 1
$atemp = StringSplit($aList[$i], ",", 2)
For $j = 0 To 18
$aFinalList[$j][$i] = $atemp[$j]
Next
Next
Return $aFinalList
EndFunc ;==>_Get_List
Func _Get_Hash($sUser, $sPass, $sTorrentName, $sIP = @IPAddress1, $sPort = "8080")
Local $sHash
$aParams = _Get_Token($sUser, $sPass, $sIP, $sPort)
$aList = _Get_List($aParams)
For $i = 0 To UBound($aList, 2) - 1
If StringInStr($aList[2][$i], $sTorrentName) Then
$sHash = StringReplace($aList[0][$i], '"', '')
ExitLoop
EndIf
Next
Return $sHash
EndFunc ;==>_Get_Hash