#include <IE.au3>
#include <Encoding.au3>
$sUrl = 'http://ru.savefrom.net/'
$sTextUrl = 'http://youtube.com/watch?v=jPj7klRF1j0'
$sUrlFLV = ''
$sUrlMP4 = ''
;$oIE = _IECreate($sUrl);окно IE будет видно
$oIE = _IECreate($sUrl, 0, 0);окно IE будет скрыто
$oInput = _IEGetObjById($oIE, 'sf_url')
$oSubmit = _IEGetObjById($oIE, 'sf_submit')
_IEFormElementSetValue($oInput, $sTextUrl)
_IEAction($oSubmit, 'click')
_IELoadWait($oIE)
$iStart = TimerInit()
While 1
$oUrls = _IETagNameGetCollection($oIE, 'a')
For $oUrl In $oUrls
ConsoleWrite($oUrl.innertext & ' - ' & $oUrl.href & @CR)
If $oUrl.innertext == 'FLV' Then
$sUrlFLV = $oUrl.href
ExitLoop
EndIf
Next
For $oUrl In $oUrls
ConsoleWrite($oUrl.innertext & ' - ' & $oUrl.href & @CR)
If $oUrl.innertext == 'MP4' Then
$sUrlMP4 = $oUrl.href
ExitLoop
EndIf
Next
If $sUrlFLV And $sUrlMP4 Then ExitLoop
If TimerDiff($iStart) > 20000 Then
MsgBox(16, 'Error', 'Время вышло')
_IEQuit($oIE)
Exit
EndIf
Sleep(500)
WEnd
_IEQuit($oIE)
MsgBox(64, 'Info', 'FLV: ' & $sUrlFLV & @LF & 'MP4: ' & $sUrlMP4)
If Not StringInStr($sUrlFLV, '%') Then
$oHTTP = ObjCreate('WinHttp.WinHttpRequest.5.1')
$oHTTP.Open('GET', $sUrlFLV)
$oHTTP.SetRequestHeader('User-Agent', 'AutoIt')
$oHTTP.SetRequestHeader('Host', 'savefrom.net')
$oHTTP.SetRequestHeader('Cache-Control', 'no-cache')
$oHTTP.Send('')
$oHTTP.WaitForResponse
$sHeader = $oHTTP.GetAllResponseHeaders
$sFLV = $oHTTP.ResponseBody
$sFileNameFLV = _Encoding_CyrillicTo1251(StringRegExpReplace($sHeader, '(?s).*?filename="(.*?flv)"?.*', '\1'))
$hFile = FileOpen(@ScriptDir & '\' & $sFileNameFLV, 18)
FileWrite($hFile, $sFLV)
FileClose($hFile)
$oHTTP.Open('GET', $sUrlMP4)
$oHTTP.SetRequestHeader('User-Agent', 'AutoIt')
$oHTTP.SetRequestHeader('Host', 'savefrom.net')
$oHTTP.SetRequestHeader('Cache-Control', 'no-cache')
$oHTTP.Send('')
$oHTTP.WaitForResponse
$sHeader = $oHTTP.GetAllResponseHeaders
$sMP4 = $oHTTP.ResponseBody
$sFileNameMP4 = _Encoding_CyrillicTo1251(StringRegExpReplace($sHeader, '(?s).*?filename="(.*?mp4)"?.*', '\1'))
$hFile = FileOpen(@ScriptDir & '\' & $sFileNameMP4, 18)
FileWrite($hFile, $sMP4)
FileClose($hFile)
MsgBox(64, 'Info', $sFileNameFLV & @LF & $sFileNameMP4)
Exit
Else
$sFileNameFLV = 'File.flv'
$sFileNameMP4 = 'File.mp4'
EndIf
$hDownloadMP4 = InetGet($sUrlMP4, @ScriptDir & '\' & $sFileNameMP4, 1, 1)
$hDownloadFLV = InetGet($sUrlFLV, @ScriptDir & '\' & $sFileNameFLV, 1, 1)
Do
ConsoleWrite($sFileNameMP4 & ' скачано: ' & InetGetInfo($hDownloadMP4, 0) & ' b' & @CR)
ConsoleWrite($sFileNameFLV & ' скачано: ' & InetGetInfo($hDownloadFLV, 0) & ' b' & @CR)
Sleep(250)
Until InetGetInfo($hDownloadMP4, 2) And InetGetInfo($hDownloadFLV, 2)
$nBytesMP4 = InetGetInfo($hDownloadMP4, 0)
$nBytesFLV = InetGetInfo($hDownloadFLV, 0)
InetClose($hDownloadMP4)
InetClose($hDownloadFLV)
MsgBox(64, 'Info', $sFileNameMP4 & ': ' & $nBytesMP4 & ' b' & @LF & $sFileNameFLV & ': ' & $nBytesFLV & ' b')