name22

Download With Progress Function

May 25th, 2012
270
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Date.au3>
  2.  
  3. Func _DownloadWithProgress($sURL, $sFileName = "")
  4.     ; -Author: name22 (www.autoit.de)
  5.  
  6.     Local $hDownload, $iSizeBytes = InetGetSize($sURL)
  7.     Local $iH, $iM, $iS, $iTicks, $iCompletedBytes, $nPercent, $nElapsedTime, $nBPS, $nT = TimerInit()
  8.  
  9.     If $sFileName = "" Then
  10.         $hDownload = InetGet($sURL, StringTrimLeft($sURL, StringInStr($sURL, "/", 0, -1)), 1, 1)
  11.     Else
  12.         $hDownload = InetGet($sURL, $sFileName, 0, 1)
  13.     EndIf
  14.  
  15.     ProgressOn("Download", "0% Completed - 0 kB/s", "Remaining - 00:00:00", Default, Default, 18)
  16.  
  17.     Do
  18.         $iCompletedBytes = InetGetInfo($hDownload, 0)
  19.         $nPercent = $iCompletedBytes * 100 / $iSizeBytes
  20.         $nElapsedTime = TimerDiff($nT) / 1000
  21.  
  22.         $nBPS = $iCompletedBytes / $nElapsedTime
  23.         $iTicks = $iSizeBytes / $nBPS - $nElapsedTime
  24.         $iH = Int($iTicks / 3600)
  25.         $iTicks = Mod($iTicks, 3600)
  26.         $iM = Int($iTicks / 60)
  27.         $iS = Mod($iTicks, 60)
  28.  
  29.         ProgressSet($nPercent, "Remaining - " & StringFormat("%02d:%02d:%02d", $iH, $iM, $iS), StringFormat("%.1f", Round($nPercent, 1)) & "% Completed - " & Int($nBPS / 1024) & " kB/s")
  30.  
  31.         Sleep(50)
  32.     Until InetGetInfo($hDownload, 2)
  33.  
  34.     ProgressSet(100, "", "Download completed.")
  35.     ProgressOff()
  36. EndFunc   ;==>_DownloadWithProgress
RAW Paste Data