- Offizieller Beitrag
Hallo
So, wie versprochen: Hier ist eine RapidPrem UDF mit folgenden Funktionen:
- _RapidPrem_DownloadFile
- _RapidPrem_UploadFile
- _RapidPrem_GenerateAuth
- _RapidPrem_CheckAcc
- _RapidPrem_IsRapidLink
Die UDF kommt komplett ohne die IE.au3 geschweige denn dem Internet Explorer object oder sonst irgendeinem Browser Objekt zurecht.
Es ist 100%ig AutoIt und es funktioniert rein über die TCP/IP befehle.
Hier die UDF:
RapidPrem.au3
#include-once
[/autoit] [autoit][/autoit] [autoit];RapidPrem - by GtaSpider
[/autoit] [autoit][/autoit] [autoit]TCPStartup()
Global $hProg_Downl
Global $hLab_DownlPrz
Global $hGUI_Prog
Global $bDownloadActive = False
;##########################
; RapidPrem - Corefunktionen
;##########################
;===============================================================================
;
; Function Name: _RapidPrem_DownloadFile
; Description:: Download a file with given Login
; Parameter(s): $sURL: Download Link
; $sFileSavePath: Path to save downloaded file
; $sUsername: Username
; $sPassword: Password
; [$sServer: [optional] Default Rapidshare Server]
; Requirement(s): TCP
; Return Value(s): True on Succes
; : False (0) on Failed
; : @error codes:
; : 1 - Is not a Valid Rapidshare link
; : 2 - Couldn't gerenarte Authentification code
; : 3 - couldn't ping Rapidshare server
; : 4 - Couldn't connect to rapidshare server on port 80
; : 5 - Error by sending string
; : 6 - Helpful for abort function: If $bDownloadActive = false while downloading
; : 7 - Not 200 OK received, Return: $sRecv
;
; Author(s): GtaSpider
;
;===============================================================================
;
Func _RapidPrem_DownloadFile($sURL, $sFileSavePath, $sUsername, $sPassword, $sServer = "1")
Local $sSendString, $sGet, $sAuth, $hSocket, $sRecv, $iExt, $aRegEx, $sRet
$sGet = _RapidPrem_IsRapidLink($sURL)
If @error Then Return SetError(1, 0, 0); No Valid Rapidshare Link
$sAuth = _RapidPrem_GenerateAuth($sUsername, $sPassword)
If @error Then Return SetError(2, 0, 0); Error by gerenating an Authentication string
Ping("rs" & $sServer & ".rapidshare.com")
If @error Then Return SetError(3, @error, 0); Error by pinging rapidshare server
$hSocket = TCPConnect(TCPNameToIP("rs" & $sServer & ".rapidshare.com"), 80)
If @error Then Return SetError(4, @error, 0)
$sSendString = "GET " & $sGet & " HTTP/1.1" & @CRLF & _
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" & @CRLF & _
"Accept-Language: de, en-gb;q=0.9, en;q=0.8" & @CRLF & _
"Authorization: Basic " & $sAuth & @CRLF & _
"Host: rs" & $sServer & ".rapidshare.com" & @CRLF & _
"Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" & @CRLF & _
"Connection: keep-alive" & @CRLF & @CRLF
_HTTPSend($sSendString, $hSocket)
If @error Then SetError(5, 0, 0)
$bDownloadActive = True
$sRecv = _HTTPRecv($hSocket, 50, 0, $sFileSavePath, 1)
If @error = 4 Then Return SetError(6, 0, 0)
$bDownloadActive = False
If @extended = 1 Then
If StringInStr($sRecv, "HTTP/1.1 302 Moved Temporarily") Then
$aRegEx = StringRegExp($sRecv, "Location: (?:http://)?rs(.*?).rapidshare", 3)
$sRet = _RapidPrem_DownloadFile($sURL, $sFileSavePath, $sUsername, $sPassword, $aRegEx[0])
Return SetError(@error, @extended, $sRet)
Else
Return SetError(7, 0, $sRecv)
EndIf
EndIf
Return True
EndFunc ;==>_RapidPrem_DownloadFile
;===============================================================================
;
; Function Name: _RapidPrem_UploadFile
; Description:: Upload a file with given Login
; Parameter(s): $sFilePath: Path to Uploadfile
; $sUsername: Username
; $sPassword: Password
; [$sServer: [optional] Default Rapidshare Server]
; Requirement(s): TCP
; Return Value(s): Received Header, @extended is Error return from HTTPRecv function
; : False (0) on Failed
; : @error codes:
; : 1 - Is not a Valid Rapidshare link
; : 2 - couldn't ping Rapidshare server
; : 3 - Couldn't connect to rapidshare server on port 80
; : 4 - Error by sending string
;
; Author(s): GtaSpider
;
;===============================================================================
;
Func _RapidPrem_UploadFile($sFilePath, $sUsername, $sPassword, $sServer = "1")
Local $sSendString, $sTemp, $sGet, $sAuth, $hSocket
If Not FileExists($sFilePath) Then Return SetError(1, 0, 0); No Valid File
Ping("rs" & $sServer & ".rapidshare.com")
If @error Then Return SetError(2, @error, 0); Error by pinging rapidshare server
$hSocket = TCPConnect(TCPNameToIP("rs" & $sServer & ".rapidshare.com"), 80)
If @error Then Return SetError(3, @error, 0)
$sTemp = @CRLF & _
"----------" & _GetTime() & @CRLF & _
'Content-Disposition: form-data; name="toolmode2"' & @CRLF & _
"" & @CRLF & _
"1" & @CRLF & _
"----------" & _GetTime() & @CRLF & _
'Content-Disposition: form-data; name="filecontent"; filename="' & $sFilePath & '"' & @CRLF & _
"Content-Type: multipart/form-data" & @CRLF & _
"Content-Transfer-Encoding: binary" & @CRLF & @CRLF & _
FileRead($sFilePath) & @CRLF & _
"----------" & _GetTime() & @CRLF & _
'Content-Disposition: form-data; name="login"' & @CRLF & _
"" & @CRLF & _
$sUsername & @CRLF & _
"----------" & _GetTime() & @CRLF & _
'Content-Disposition: form-data; name="password"' & @CRLF & _
"" & @CRLF & _
$sPassword & @CRLF & _
"----------" & _GetTime() & @CRLF
$sSendString = "POST /cgi-bin/upload.cgi HTTP/1.0" & @CRLF & _
"Connection: Keep-Alive" & @CRLF & _
"Content-Type: multipart/form-data; boundary=--------" & _GetTime() & @CRLF & _
"Content-Length: " & StringLen($sTemp) & @CRLF & _
"Host: rs." & $sServer & ".rapidshare.com" & @CRLF & _
"Keep-Alive: 300" & @CRLF & _
"User-Agent: RapidUploader[v1,2]" & @CRLF & $sTemp; So tuen als ob wir den Rapiduploader v1,2 ausführen
_HTTPSend($sSendString, $hSocket, Round(StringLen($sTemp) / 100))
If @error Then Return SetError(4, @error, 0)
$sRecv = _HTTPRecv($hSocket)
Return SetError(0, @error, $sRecv)
EndFunc ;==>_RapidPrem_UploadFile
;##########################
; RapidPrem - Nebenfunktionen
;##########################
;Generates an Authentification code with Base64 Encoding
;by GtaSpider
Func _RapidPrem_GenerateAuth($sUsername, $sPassword)
Local $sRet = _Base64Encode($sUsername & ":" & $sPassword)
If Not StringLen($sRet) Then SetError(1, 0, 0)
Return $sRet
EndFunc ;==>_RapidPrem_GenerateAuth
;Check Premium account
;by GtaSpider
Func _RapidPrem_CheckAcc($sUsername, $sPassword)
$S = _RapidPrem_DownloadFile("http://rapidshare.com/files/136642724/0.txt", @TempDir & "\0.txt", $sUsername, $sPassword)
If @error Then Return SetError(FileDelete(@TempDir&"\0.txt"), @error, $S)
If FileRead(@TempDir&"\0.txt") <> "CHECK_ACCOUNT" Then Return SetError(2,1,FileRead(@TempDir&"\0.txt")&"_"&FileDelete(@TempDir&"\0.txt"))
Return FileDelete(@TempDir&"\0.txt")
EndFunc ;==>_RapidPrem_CheckAcc
;Check Rapidshare Link
;by GtaSpider
Func _RapidPrem_IsRapidLink($sURL)
$aRegEx = StringRegExp($sURL, "(http://)?(rs.*)?rapidshare.com/files/\d*/[-a-zA-Z0-9\_\.]*\z")
If Not $aRegEx Then Return SetError(1, 0, 0)
$aRegEx = StringRegExp($sURL, "(http://)?(rs.*)?rapidshare.com(/files/.*?)\z", 3)
Return $aRegEx[2]
EndFunc ;==>_RapidPrem_IsRapidLink
;##########################
; Sonsitge Funktionen
;##########################
;HTTP Send
;by GtaSpider
Func _HTTPSend($sSendString, $hSocket, $iBuffersize = 2904)
Local $sBuffer = $sSendString, $iProz
If $iBuffersize < 1024 Then $iBuffersize = 1024
While StringLen($sBuffer)
$iSend = 0
If $iBuffersize >= StringLen($sBuffer) Then $iBuffersize = StringLen($sBuffer) + 2
While $iSend < $iBuffersize
$iSend += TCPSend($hSocket, StringLeft($sBuffer, $iBuffersize))
If @error Then ExitLoop Beep() + 1
WEnd
$sBuffer = StringTrimLeft($sBuffer, $iBuffersize)
$iProz = Round(100 - (100 * StringLen($sBuffer) / StringLen($sSendString)))
GUICtrlSetData($hProg_Downl, $iProz)
GUICtrlSetData($hLab_DownlPrz, $iProz & "%")
WEnd
EndFunc ;==>_HTTPSend
;HTML Recv
;by GtaSpider
Func _HTTPRecv($hSocket, $iSleep = 50, $iTimeOut = 20000, $sDwn = False, $iForceBinary = 0, $iBuffersize = 1024)
Local $sRecv, $sRet, $iErr = 0, $hTi, $hFiOp, $sFirstRecv, $iLen = 0, $iFirst = True
If $iTimeOut > 0 Then $hTi = TimerInit()
If $sDwn Then $hFiOp = FileOpen($sDwn, 17)
While 1
If $iTimeOut > 0 And TimerDiff($hTi) > $iTimeOut Then ExitLoop
$sRecv = TCPRecv($hSocket, $iBuffersize, $iForceBinary)
$iErr = @error
If $iErr Then ExitLoop
If $sDwn And (Not $bDownloadActive) Then ExitLoop
While StringLen($sRecv)
If $iForceBinary Then $sRecv = BinaryToString($sRecv)
If $iFirst Then
If Not StringInStr($sRecv, "HTTP/1.1 200 OK") Then
TCPCloseSocket($hSocket)
If $sDwn Then FileClose($hFiOp)
Return SetError(1, 1, "ERR:" & $sRecv)
EndIf
$sFirstRecv = $sRecv
If $sDwn Then $sRecv = StringTrimLeft($sRecv, StringInStr($sRecv, @CRLF & @CRLF)+4)
$iFirst = False
EndIf
If $sDwn Then
$iLen += StringLen($sRecv)
FileWrite($hFiOp, $sRecv)
Call("__SetProgress",$sFirstRecv,$iLen)
EndIf
If Not $sDwn Then $sRet &= $sRecv
$sRecv = TCPRecv($hSocket, $iBuffersize, $iForceBinary)
$iErr = @error
If $iErr Then ExitLoop 2
If $iTimeOut > 0 And TimerDiff($hTi) > $iTimeOut Then ExitLoop 2
If $sDwn And (Not $bDownloadActive) Then ExitLoop 2
WEnd
Sleep($iSleep)
WEnd
TCPCloseSocket($hSocket)
If $sDwn Then FileClose($hFiOp)
If $iForceBinary Then $sRet = "0x" & StringReplace($sRet, "0x", "")
If $iTimeOut > 0 And TimerDiff($hTi) > $iTimeOut Then Return SetError(2, 0, "Timeout")
If $iErr Then Return SetError(3, $iErr, $sRet)
If Not $bDownloadActive Then Return SetError(4, 0, 0)
Return $sRet
EndFunc ;==>_HTTPRecv
;GetTime
;by GtaSpider
Func _GetTime()
Return @MON & @MDAY & StringRight(@YEAR, 2) & @HOUR & @MIN & @SEC & "044";Eigentlich MSec aber warte auf naecchste Stable
EndFunc ;==>_GetTime
;Base64 Encoding
;By Ward
Func _Base64Encode($Data)
Local $Opcode = "0x5589E5FF7510535657EB1A8B5D088B7DFC8B4D0CE81F000000834508038345FC04836D0C03837D0C007FE08B75FCC606005F5E5BC9C21000E8410000004142434445464748494A4B4C4D4E4F505152535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435363738392B2F005A0FB633C1EE0201D68A06880731C083F901760C0FB6430125F0000000C1E8040FB63383E603C1E60409C601D68A0688470183F90176210FB6430225C0000000C1E8060FB6730183E60FC1E60209C601D68A06884702EB04C647023D83F90276100FB6730283E63F01D68A06884703EB04C647033DC3"
Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
DllStructSetData($CodeBuffer, 1, $Opcode)
Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
DllStructSetData($Input, 1, $Data)
Local $Ouput = DllStructCreate("char[" & Int(BinaryLen($Data) * 4 / 3) + 4 & "]")
[/autoit] [autoit][/autoit] [autoit]DllCall("user32.dll", "none", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
"ptr", DllStructGetPtr($Input), _
"int", BinaryLen($Data), _
"ptr", DllStructGetPtr($Ouput), _
"int", 0)
$Ret = DllStructGetData($Ouput, 1)
$Input = 0
$Ouput = 0
$CodeBuffer = 0
Return $Ret
EndFunc ;==>_Base64Encode
Ein "Beispiel" (PR3M - Rapidshare PremiumAccount sammler) + UDF ist im Annhang
Würde mich sehr über Kommentare freuen
Mfg Spider