Jump to content

Recommended Posts

Posted

how can i calculate the time untill a download is finished

i got a download tool for a gui of mine i already got the percentage finish and the actual download speed

all i need is the time until dl is finished

#include <GUIConstants.au3>
#NoTrayIcon
AutoItSetOption("GUIOnEventMode", 1)

$GUITitle = "Download Firefox"
$GUIWidth = 302
$GUIHeight = 168
Dim $iDloadFinalSize = ""
Dim $iDloadCurrentSize = ""

$GUI = GUICreate($GUITitle, $GUIWidth, $GUIHeight, (@DesktopWidth - $GUIWidth) / 2, (@DesktopHeight - $GUIHeight) / 2)
$sFileURL1 = GUICtrlCreateInput("", 24, 24, 249, 21)
$Button1 = GUICtrlCreateButton("Download", 24, 72, 115, 17, 0)
$Button2 = GUICtrlCreateButton("Cancel / Close", 148, 72, 115, 17, 0)
$progressDownloadStatus = GUICtrlCreateProgress(24, 104, 246 - 10, 10)
$lb_Mn_Progress = GUICtrlCreateLabel('Download not Started yet', 40, 120, $GUIWidth, $GUIHeight)
GUISetState()
GUICtrlSetState($Button2,$GUI_DISABLE)

#Region Events list
GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitIt")
GUICtrlSetOnEvent($Button2,"_DownloadFF")
GUICtrlSetOnEvent($Button1,"_DownloadFF")
#EndRegion Events list

While 1
    Sleep(10)
    If $iDloadFinalSize <> "" Then _CheckActiveDownload()
WEnd

Func _ExitIt()
    Exit
EndFunc

Func _CheckActiveDownload()
        While @InetGetActive
            $oldspeed = @InetGetBytesRead
            Sleep(250)
            $newspeed = @InetGetBytesRead
            $speed = Int(($newspeed - $oldspeed) * 4 / 1024)
    If @InetGetBytesRead <> "-1" Then
        GUICtrlSetState($Button2,$GUI_ENABLE)
        $iDloadCurrentSize = @InetGetBytesRead
        $iPercentage = Round(($iDloadCurrentSize/$iDloadFinalSize)*100,1)
        GUICtrlSetData($progressDownloadStatus,$iPercentage)
        GUICtrlSetData($lb_Mn_Progress, 'Download Progress: ' & $iPercentage & " percent (%) with " & $speed & " KB/s")
    Else
        $iDloadFinalSize = ""
        GUICtrlSetData($progressDownloadStatus,"0")
        MsgBox(16,"Error","The download was cancelled, or did not complete successfully.")
        FileDelete($sFileDest)
        Exit
    EndIf
    Wend
    If $iDloadCurrentSize = $iDloadFinalSize Then
        $iDloadFinalSize = ""
        MsgBox(64,"Complete","Download complete!")
    EndIf
EndFunc

Func _DownloadFF()
    $file=GUICtrlRead($sFileURL1)
    If @InetGetActive Then
        InetGet("abort")
        GUICtrlSetData($progressDownloadStatus,"0")
    Else
        Global $file
        Global $file2 = StringTrimLeft($file,StringInStr($file,"/",0,-1))
        Global $sFileDest = @ScriptDir&"/"&$file2
        $iDloadFinalSize = InetGetSize($file)
        $iDloadCurrentSize = "0"
        InetGet($file, $sFileDest, 1, 1)
    EndIf
EndFunc
Posted

You have the speed, the final size and the current downloaded data. So remaining time is (finalsize-downloadedsize)/bytesPerSec

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

You have the speed, the final size and the current downloaded data. So remaining time is (finalsize-downloadedsize)/bytesPerSec

hm i did iETADown = Round(($iDloadFinalSize/1024/1024) - ($iDloadCurrentSize/1024/1024)/$speed,1)

but somehow it gives me a real wierd response aof 4000 something.

so i divided with 3600 to get the hours but the value shown in autoit tells me i have 1h and 30 mins

the same download with ie and firefox shows me 1h and 15 min

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...