Jump to content

Wget Progress Bar autoit script...


popojp00
 Share

Recommended Posts

I saw a post a while back about how you can get the progress bar, but I found it was not accurate and good enough.

So I created one from scratch.

The trick is to use --output-file from wget option and read % of the progress from the log.

I was going to post this a few days ago but I could not create autoit forum account or it was not available.

Here is my code:

wget.ini

[options]
proxyserver=
port=
downfolder=C:\pro\wget\wget
wgetexe=C:\pro\tools\wget\wget.exe
lastdown=
optionx=--user-agent="Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1" --no-check-certificate --output-file=C:\pro\wget\wget\wget.log
locl=720
loct=91

wget code

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=disalbexx.ico
#AutoIt3Wrapper_Outfile=..\..\wget\wgetx.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/striponly
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <String.au3>
#include <GUIStatusBar.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <FileConstants.au3>
#include <File.au3>
#region ### START Koda GUI section ### Form=
Opt("TrayAutoPause", 0)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
TraySetClick(16)
$abou = TrayCreateItem("About")
TrayItemSetOnEvent(-1, "_goabout")
$goex = TrayCreateItem("Exit", -1, -1, 0)
TrayItemSetOnEvent(-1, "_goexit")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "wakewget")
$curdir = @ScriptDir & "\"
$wgetini = @ScriptDir & "\wget.ini"
$proxysetting = ""
$pid = 0
$percent = 0
$downloading = 0
$chkstat = 0
$wrun = ""
$run50x = 0
$triesn = 0
$proxys = IniRead($wgetini, "options", "proxyserver", "")
$pport = IniRead($wgetini, "options", "port", "")
$downf = IniRead($wgetini, "options", "downfolder", "")
$wgetexe = IniRead($wgetini, "options", "wgetexe", "dummy323")
$lastd = IniRead($wgetini, "options", "lastdown", "")
$exoption = IniRead($wgetini, "options", "optionx", "")
$locl = IniRead($wgetini, "options", "locl", "")
$loct = IniRead($wgetini, "options", "loct", "")
$ndlst = $lastd
$dwnlink = ""
If Not ($exoption = "") Then $exoption = $exoption & " "
If $downf = "" Then $downf = @ScriptDir
If Not FileExists($downf) Then $downf = @ScriptDir
$runexplorer = "explorer.exe /e, " & $downf
If Not ($locl > 0) Then $locl = -1
If Not ($loct > 0) Then $loct = -1
$GUI = GUICreate("wgetx", 520, 258, $locl, $loct)
$edit_input = GUICtrlCreateCombo("", 16, 24, 440, 21)
GUICtrlSetData(-1, $lastd, "")
$progress = GUICtrlCreateLabel("0", 478, 28, 400, 22)
GUICtrlCreateLabel("%", 500, 28, 22, 22)
GUICtrlCreateLabel("access user name:", 16, 80, 90, 22)
$situsr = GUICtrlCreateInput("", 110, 78, 120, 21)
GUICtrlCreateLabel("access password:", 244, 80, 90, 22)
$sitpwd = GUICtrlCreateInput("", 336, 78, 120, 21)
$dtxt = GUICtrlCreateLabel("download folder:", 16, 54, 78, 22)
$dfolder = GUICtrlCreateInput($downf, 100, 52, 356, 21)
$seldir = GUICtrlCreateButton("..", 458, 52, 20, 20)
$proxytxt = GUICtrlCreateLabel("proxy server", 16, 106, 66, 22)
$httfptsel = GUICtrlCreateCombo("http", 84, 104, 40, 40)
GUICtrlSetData(-1, "http|ftp", "http")
$proxy = GUICtrlCreateInput($proxys, 128, 104, 88, 21)
$porttxt = GUICtrlCreateLabel("port", 224, 106, 22, 22)
$port = GUICtrlCreateInput($pport, 246, 104, 40, 21)
$retrytxt = GUICtrlCreateLabel("retry", 294, 106, 22, 22)
$tries = GUICtrlCreateInput("888", 318, 104, 24, 21)
$timeouttxt = GUICtrlCreateLabel("time out(sec)", 360, 106, 68, 22)
$timeout = GUICtrlCreateInput("44", 430, 104, 26, 21)
GUICtrlCreateLabel("proxy user name:", 16, 134, 90, 22)
$proxusr = GUICtrlCreateInput("", 110, 132, 120, 21)
GUICtrlCreateLabel("proxy password:", 244, 134, 90, 22)
$proxpwd = GUICtrlCreateInput("", 336, 132, 120, 21)
$newertxt = GUICtrlCreateLabel("newer file", 16, 162, 66, 22)
$newer = GUICtrlCreateInput("N", 84, 160, 18, 21)
$resumtxt = GUICtrlCreateLabel("resume", 128, 162, 33, 22)
$continue = GUICtrlCreateInput("Y", 168, 160, 18, 21)
$waitretxt = GUICtrlCreateLabel("wait retry", 194, 162, 44, 22)
$waitretry = GUICtrlCreateInput("44", 246, 160, 40, 21)
$recursivetxt = GUICtrlCreateLabel("recursive", 294, 162, 44, 22)
$recursive = GUICtrlCreateInput("N", 340, 160, 17, 21)
$npparenttxt = GUICtrlCreateLabel("no parent", 364, 162, 48, 22)
$npparrent = GUICtrlCreateInput("Y", 414, 160, 17, 21)
$errmsg = GUICtrlCreateLabel("", 16, 188, 220, 22)
$btn_download = GUICtrlCreateButton("Download", 106, 206, 60, 35, 0, 0x0001)
$btn_cancel = GUICtrlCreateButton("Cancel", 184, 206, 60, 35, 0)
$opdownf = GUICtrlCreateButton("View Files", 256, 206, 60, 35, 0)
$btn_exit = GUICtrlCreateButton("Exit", 328, 206, 60, 35, 0)
GUISetState(@SW_SHOW)
While 1
Sleep(10)
$chkstat = $chkstat + 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $seldir
   $seldir1 = FileSelectFolder("Select download folder", "", 1, $downf, $downf)
   If Not @error Then
    GUICtrlSetData($dfolder, $seldir1)
    If Not ($downf = $seldir1) Then IniWrite($wgetini, "options", "downfolder", $seldir1)
   EndIf
  Case $btn_exit
   $curloc = WinGetPos("[active]")
   If Not ($locl = $curloc[0]) Then IniWrite($wgetini, "options", "locl", $curloc[0])
   If Not ($loct = $curloc[1]) Then IniWrite($wgetini, "options", "loct", $curloc[1])
   _goexit()
  Case $btn_download
   $pid = 0
   $run50x = 0
   $errtxt = ""
   $percent = 0
   $proxysetting = ""
   $optx = "--output-file=" & $downf & "\wget.log "
   $cookies = "--load-cookies=" & $downf & "\wget.cookies" & " "
   If Not FileExists($downf & "\wget.cookies") Then $cookies = ""
   $savecook = "--save-cookies=" & $downf & "\wget.cookies" & " "
   $dwnlink = GUICtrlRead($edit_input)
   $httftpr = StringLower(GUICtrlRead($httfptsel))
   $proxyr = GUICtrlRead($proxy)
   $portr = GUICtrlRead($port)
   $proxusrr = GUICtrlRead($proxusr)
   $proxpwdr = GUICtrlRead($proxpwd)
   $triesr = GUICtrlRead($tries)
   $continuer = StringUpper(GUICtrlRead($continue))
   $newerr = StringUpper(GUICtrlRead($newer))
   $timeoutr = GUICtrlRead($timeout)
   $waitretryr = GUICtrlRead($waitretry)
   $recursiver = StringUpper(GUICtrlRead($recursive))
   $npparrentr = StringUpper(GUICtrlRead($npparrent))
   $susr = GUICtrlRead($situsr)
   $spwd = GUICtrlRead($sitpwd)
   If Not ($proxusrr = "") Then $proxusrr = "--proxy-user=" & $proxusrr & " "
   If Not ($proxpwdr = "") Then $proxpwdr = "--proxy-password=" & $proxpwdr & " "
   $pusrpwd = $proxusrr & $proxpwdr
   If Not ($dwnlink = $lastd) And Not ($dwnlink = "") Then
    $dllst = _dlchk($dwnlink)
    $lastd = $dwnlink
    IniWrite($wgetini, "options", "lastdown", $dllst)
    GUICtrlSetData($edit_input, $dwnlink, "")
   EndIf
   If Not ($susr = "") And Not ($spwd = "") And Not ($dwnlink = "") Then
    $dsitspl = StringSplit($dwnlink, "//", 1)
    If $dsitspl[0] = 2 Then
     $dwnlink = $dsitspl[1] & "//" & $susr & ":" & $spwd & "@" & $dsitspl[2]
    EndIf
   EndIf
   If Not ($httftpr = "http") And Not ($httftpr = "ftp") Then
    $httftpr = "http"
    GUICtrlSetData($httfptsel, $httftpr)
   EndIf
   If $httftpr = "http" Then $httftpr = "--execute=http_proxy="
   If $httftpr = "ftp" Then $httftpr = " --execute=ftp_proxy="
   If Not ($proxyr = "") And Not ($portr = "") Then $proxysetting = $httftpr & $proxyr & ":" & $portr & " " & $pusrpwd
   If Not ($triesr > 0) Then $triesr = ""
   If $triesr > 0 Then $triesr = "--tries=" & $triesr & " "
   If Not ($newerr = "Y") Then $newerr = ""
   If $newerr = "Y" Then $newerr = "--timestamping "
   If Not ($timeoutr > 0) Then $timeoutr = ""
   If $timeoutr > 0 Then $timeoutr = "--read-timeout=" & $timeoutr & " "
   If Not ($continuer = "Y") Then $continuer = ""
   If $continuer = "Y" Then $continuer = "--continue "
   If Not ($waitretryr > 0) Then $waitretryr = ""
   If $waitretryr > 0 Then $waitretryr = "--waitretry=" & $waitretryr & " "
   If Not ($recursiver = "Y") Then $recursiver = ""
   If $recursiver = "Y" Then $recursiver = "--recursive "
   If Not ($npparrentr = "Y") Then $npparrentr = ""
   If $recursiver = "" Then $npparrentr = ""
   If $npparrentr = "Y" And Not ($recursiver = "") Then $npparrentr = "--no-parent "
   $options = $proxysetting & $continuer & $recursiver & $npparrentr & $newerr & $triesr & $waitretryr & $timeoutr & $cookies & $savecook & $optx & $exoption
   If $susr = "" And Not ($spwd = "") Then $errtxt = "access user name is blank"
   If Not ($susr = "") And $spwd = "" Then $errtxt = "access password is blank"
   If Not FileExists($wgetexe) Then $errtxt = "wget.exe in wget.ini can't be found."
   If Not ($errtxt = "") Then GUICtrlSetData($errmsg, $errtxt)
   If Not ($dwnlink = "") And FileExists($wgetexe) Then
    GUICtrlSetData($errmsg, "")
    GUICtrlSetState($btn_download, $GUI_DISABLE)
    GUICtrlSetData($progress, 0)
    $wrun = $wgetexe & " " & $options & '"' & $dwnlink & '"'
    $pid = Run($wrun, $downf, @SW_HIDE, 0x4)
;~   filewrite(@ScriptDir & "\test.txt", $c & " " & $downf)
;~   _goexit()
    Sleep(6444)
    ProcessSetPriority($pid, 0) ;; lowest
    $streamcounter = 0
    $downloading = 1
   EndIf
  Case $opdownf
   GUICtrlSetState($opdownf, $GUI_DISABLE)
   Run($runexplorer, $curdir)
   Sleep(888)
   GUICtrlSetState($opdownf, $GUI_ENABLE)
  Case $btn_cancel
   GUICtrlSetState($btn_cancel, $GUI_DISABLE)
   If $pid > 0 Then ProcessClose($pid)
   Sleep(888)
   If ProcessExists($pid) Then ProcessClose($pid)
   $downloading = 0
   GUICtrlSetState($btn_download, $GUI_ENABLE)
   GUICtrlSetState($btn_cancel, $GUI_ENABLE)
  Case $GUI_EVENT_CLOSE
   _goexit()
EndSwitch
If $chkstat > 400 Then
  $chkstat = 0
  If $downloading = 1 Then
   $percent = _chkstat()
   If $percent < 101 Then
    GUICtrlSetData($progress, $percent)
    If $percent = 100 Then
     GUICtrlSetState($btn_download, $GUI_ENABLE)
     $downloading = 0
    EndIf
   EndIf
   If Not ProcessExists($pid) Then
    If $percent > 499 Then
     If Not ($percent = 888) Then GUICtrlSetData($errmsg, "warning error " & $percent & " wget starts re-run!")
     If $percent = 888 Then GUICtrlSetData($errmsg, "warning: unknown error! wget starts re-run!")
     $pid = Run($wrun, $downf, @SW_HIDE, 0x4)
     If $run50x = 0 Then $triesn = GUICtrlRead($tries)
     $run50x = $run50x + 1
     If $run50x > $triesn Then
      $downloading = 0
      GUICtrlSetData($errmsg, "error downloading!")
      GUICtrlSetState($btn_download, $GUI_ENABLE)
     EndIf
    EndIf
    If Not ($percent = 100) And Not ($percent > 499) Then
     GUICtrlSetData($errmsg, "error downloading")
     GUICtrlSetState($btn_download, $GUI_ENABLE)
     $downloading = 0
    EndIf
   EndIf
  EndIf
EndIf
WEnd
Func _goexit()
TrayItemSetState($goex, $TRAY_UNCHECKED)
If $pid > 0 Then ProcessClose($pid)
Sleep(666)
If ProcessExists($pid) Then ProcessClose($pid)
Exit
EndFunc   ;==>_goexit
Func wakewget()
GUISetState(@SW_RESTORE)
EndFunc   ;==>wakewget
Func _goabout()
TrayItemSetState($abou, $TRAY_UNCHECKED)
TraySetToolTip("wgetx about screen is active!")
TraySetState(4)
$aboutxan = GUICreate("About wgetx: Version 0.0.0.1", 560, 280)
GUICtrlCreateLabel("wgetx ", 18, 18, 540, 22)
GUICtrlSetFont(-1, 10)
GUICtrlSetColor(-1, 0x800080)
GUICtrlCreateLabel("easy download files", 68, 18, 540, 22)
GUICtrlSetFont(-1, 10)
GUICtrlCreateLabel("Contact:" & @CRLF & @CRLF & "email and google chat: disguise9@gmail.com" & @CRLF & "skype: dandy.siren", 18, 88)
$okxanbutton = GUICtrlCreateButton("OK", 460, 240, 88, 32, 0x0001)
GUISwitch($aboutxan)
GUISetState(@SW_SHOW)
$noofloop = 0
While 1
  $noofloop = $noofloop + 1
  Sleep(44)
  $msg = GUIGetMsg(1)
  If $noofloop > 4000 Then $msg[0] = $okxanbutton
  Select
   Case $msg[0] = $okxanbutton
    GUIDelete()
    ExitLoop
   Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $aboutxan
    GUIDelete()
    ExitLoop
  EndSelect
WEnd
TraySetToolTip("wget is running")
TraySetState(8)
EndFunc   ;==>_goabout
Func _chkstat()
$npc = 888
$werrcode = 0
$wgetlog = $downf & "\wget.log"
If FileExists($wgetlog) Then
  $lin = _FileCountLines($wgetlog)
  $linp = $lin - 1
  $linc = $lin - 2
  If Not ($lin > 0) Then $lin = 1
  If Not ($linp > 0) Then $linp = 1
  If Not ($linc > 0) Then $linc = 1
  $rlinc = FileReadLine($wgetlog, $linc)
  $rlinp = FileReadLine($wgetlog, $linp)
  $rlinl = FileReadLine($wgetlog, $lin)
  $werr = StringInStr($rlinl, "ERROR")
  If $werr > 0 Then
   $werrcode = StringMid($rlinl, $werr + 6, 3)
   If $werrcode > 0 Then $npc = $werrcode
  EndIf
  $plocc = StringInStr($rlinc, "%") - 3
  $plocp = StringInStr($rlinp, "%") - 3
  $plocl = StringInStr($rlinl, "%") - 3
  $pcc = StringReplace(StringMid($rlinc, $plocc, 3), " ", "")
  $pcp = StringReplace(StringMid($rlinp, $plocp, 3), " ", "")
  $pcl = StringReplace(StringMid($rlinl, $plocl, 3), " ", "")
  If $pcp > 0 And $pcp < 101 Then $npc = $pcp
  If $pcl > 0 And $pcl < 101 Then $npc = $pcl
  If $pcc = 100 Then $npc = $pcc
EndIf
Return $npc
EndFunc   ;==>_chkstat
 
Func _dlchk($dfile)
$chkdlist = StringInStr($ndlst, "|")
If $chkdlist = 0 Then $ndlst = $dfile & "|" & $ndlst
If $chkdlist > 0 Then
  $dlistsp = StringSplit($ndlst, "|")
  If $dlistsp[0] = 1 Then $ndlst = $dfile & "|" & $ndlst
  If $dlistsp[0] > 1 Then
   $dupchk = 0
   For $dl = 1 To $dlistsp[0]
    If $dlistsp[$dl] = $dfile Then $dupchk = 1
    If $dupchk = 1 Then ExitLoop
   Next
   If $dupchk = 0 Then
    If $dlistsp[0] < 7 Then $ndlst = $dfile & "|" & $ndlst
    If $dlistsp[0] > 6 Then $ndlst = $dfile & "|" & $dlistsp[1] & "|" & $dlistsp[2] & "|" & $dlistsp[3] & "|" & $dlistsp[4] & "|" & $dlistsp[5] & "|" & $dlistsp[6]
   EndIf
  EndIf
EndIf
Return $ndlst
EndFunc   ;==>_dlchk
Edited by Y5bLOyuJc9in
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...