#include <Date.au3>
Opt('MustDeclareVars', 1)
Opt('TrayMenuMode', 1)
Global $aUrl[5] = [4, 'http://www.mediafire.com/?2o1ptow7z04ebni', _
		'http://www.mediafire.com/?vnzgmd5hxfjnbiv', _
		'http://www.mediafire.com/?2p861h0z7j8ptbl', _
		'http://www.mediafire.com/?i61m74lfuu7n2c6'], _
		$sDir = @ScriptDir & '\Download', _ ;папка, в котороую скачиваем
		$aInfo[$aUrl[0] + 1][4] = [[$aUrl[0]]], $sString = '|', $sTitle = 'Download mediafire.com', _
		$sSourse, $vLink, $iCount
If WinExists($sTitle & '{[/@$@\]}') Then Exit
AutoItWinSetTitle($sTitle & '{[/@$@\]}')
HotKeySet('+{Esc}', '_Exit');Shift + Esc - exit
TrayTip($sTitle, 'Get links now', 5, 1)
For $i = 1 To $aUrl[0]
	$sSourse = InetRead($aUrl[$i], 17)
	If @error Then ContinueLoop
	$sSourse = BinaryToString($sSourse)
	$vLink = StringRegExpReplace($sSourse, '(?s).*href="(.+?)"\h.*?Download\h<span>.*', '$1')
	If @extended <> 1 Then ContinueLoop
	$iCount += 1
	$aInfo[$iCount][0] = StringRegExpReplace($vLink, '^.*/', '')
	$aInfo[$iCount][1] = $vLink
	If StringLen($aInfo[$iCount][0]) > 10 Then $aInfo[$iCount][0] = StringRight($aInfo[$iCount][0], 10)
	$vLink = 0
	While FileExists($sDir & '\' & $aInfo[$iCount][0]) Or _
			StringInStr($sString, $aInfo[$iCount][0] & '|')
		$vLink += 1
		$aInfo[$iCount][0] = $vLink & '_' & StringRegExpReplace($aInfo[$iCount][0], '^.*_', '')
	WEnd
	$sString &= $aInfo[$iCount][0] & '|'
Next
If $iCount Then
	ReDim $aInfo[$iCount + 1][4]
	$aInfo[0][0] = $iCount
	$sString = ''
	$sSourse = 0
	$vLink = 0
	$aUrl = 0
Else
	MsgBox(16, $sTitle, 'Error get links')
	Exit
EndIf
TrayTip($sTitle, '', 1)
If Not FileExists($sDir) Then DirCreate($sDir)
If Not FileExists($sDir & '\Temp') Then DirCreate($sDir & '\Temp')
For $i = 1 To $aInfo[0][0]
	$aInfo[$i][2] = InetGet($aInfo[$i][1], $sDir & '\Temp' & '\' & $aInfo[$i][0] & '.tmp', 17, 1)
	$aInfo[$i][1] = 0
Next
ProgressOn($sTitle, StringFormat('Downloading %d files, [%d], [%s]', _
		$aInfo[0][0], $aInfo[0][0] - $iCount, _Timer($vLink * 1000)), '0%', 50, 50, 16)
While $iCount
	Sleep(1000)
	$vLink += 1
	$aInfo[0][3] = 0
	$aInfo[0][2] = 0
	For $i = 1 To $aInfo[0][0]
		If $aInfo[$i][2] Then
			If InetGetInfo($aInfo[$i][2], 2) Then
				$iCount -= 1
				If InetGetInfo($aInfo[$i][2], 4) Then
					$aInfo[$i][1] = 0
					FileDelete($sDir & '\Temp' & '\' & $aInfo[$i][0] & '.tmp')
					$aInfo[0][1] -= $aInfo[$i][1]
					TrayTip($sTitle, 'Error downloading: ' & $aInfo[$i][0], 5, 3)
				Else
					TrayTip($sTitle, 'Download ' & $aInfo[$i][0] & ' completed', 5, 1)
					FileMove($sDir & '\Temp' & '\' & $aInfo[$i][0] & '.tmp', $sDir & '\' & $aInfo[$i][0], 1)
				EndIf
				InetClose($aInfo[$i][2])
				$aInfo[$i][2] = 0
			Else
				If Not $aInfo[$i][1] Then
					$aInfo[$i][1] = InetGetInfo($aInfo[$i][2], 1)
					$aInfo[0][1] += $aInfo[$i][1]
				EndIf
				$aInfo[$i][3] = InetGetInfo($aInfo[$i][2], 0)
				$aInfo[0][3] += $aInfo[$i][3]
			EndIf
		EndIf
		$aInfo[0][2] += $aInfo[$i][3]
	Next
	If $aInfo[0][1] And $aInfo[0][3] Then
		ProgressSet(Int(100 * $aInfo[0][2] / $aInfo[0][1]), _
				StringFormat('%.2f%\t%s/sec, [%s], [%s]', 100 * $aInfo[0][2] / $aInfo[0][1], _
				_Format_Size($aInfo[0][3] / $vLink), _Format_Size($aInfo[0][2]), _
				_Format_Size($aInfo[0][1])), StringFormat('Downloading %d files, [%d], [%s]', _
				$aInfo[0][0], $aInfo[0][0] - $iCount, _Timer($vLink * 1000)))
	EndIf
WEnd
ProgressSet(100, 'Download completed', StringFormat('Downloading %d files, [%d], [%s]', _
		$aInfo[0][0], $aInfo[0][0] - $iCount, _Timer($vLink * 1000)))
$sString = StringFormat('Downloaded files: %d, [%s], [%s]\n\n', $aInfo[0][0], _
		_Format_Size($aInfo[0][1]), _Timer($vLink * 1000))
For $i = 1 To $aInfo[0][0]
	$sString &= StringFormat('%s\t%s\t%s\n', $aInfo[$i][0], _Format_Size($aInfo[$i][1]))
Next
DirRemove($sDir & '\Temp', 1)
MsgBox(64, $sTitle, StringTrimRight($sString, 1))
ProgressOff()
Func _Format_Size($i_Size, $i_Lang = 1);$i_Lang = 0 - рус, 1 - англ.
	Local $a_Str[5][2] = [['байт', 'byte'],['КБ', 'KB'],['МБ', 'MB'],['ГБ', 'GB'],['ТБ', 'TB']]
	$i_Lang = Int($i_Lang)
	If $i_Lang > 1 Or $i_Lang < 0 Then $i_Lang = 0
	$i_Size = Abs($i_Size)
	If $i_Size < 1024 Then Return StringFormat('%d ' & $a_Str[0][$i_Lang], $i_Size)
	For $i = 1 To 4
		$i_Size /= 1024
		If $i_Size < 1024 Then ExitLoop
	Next
	Return StringFormat('%.2f ' & $a_Str[$i][$i_Lang], $i_Size)
EndFunc   ;==>_Format_Size
Func _Timer($i_Diff)
	Local $i_Hour, $i_Min, $i_Sec
	_TicksToTime(Abs(Int($i_Diff)), $i_Hour, $i_Min, $i_Sec)
	Return StringFormat('%02d:%02d:%02d', $i_Hour, $i_Min, $i_Sec)
EndFunc   ;==>_Timer
Func _Exit()
	For $i = 1 To $aInfo[0][0]
		If $aInfo[$i][2] Then
			InetClose($aInfo[$i][2])
			FileDelete($sDir & '\Temp' & '\' & $aInfo[$i][0] & '.tmp')
		EndIf
	Next
	DirRemove($sDir & '\Temp', 1)
	Exit
EndFunc   ;==>_Exit