Sign in to follow this  
Followers 0
pasmo

_InetGetProgressArray

2 posts in this topic

#1 ·  Posted (edited)

Greets to AutoIt community!

This if my little contribution to research a magic AutoIt.

With _InetGetProgressArray you can download all files that's linked in passed to func array with a showing progress of getting.

Example gets all picz from site and put's all to 'temp23' folder

Of course any suggestions and improvements are will wellcomed of all! :) greetz!

; ===================================================================
; ===================================================================
; _InetGetProgressArray(ByRef $URLArray, [$toFolder])
;
; Get all files passed to func with array of links. Calculate all size of files and shows getting progress.
; Parameters:
;    $URLArray  - IN - Array of links ie 'http://site.com/folder/file.ext'
;    $toFolder  - OPTIONAL IN - Name of local folder to put files to. If not set then put files near running script.
; Returns:
;    None but if errors.
; ===================================================================

Func _InetGetProgressArray(ByRef $URLArray, $toFolder = '')

; ===================================================================
  Local $iPercentage, $iBytesRead, $iInetBytesRead, $sProgressText
  Local $sCounter = 0, $TotalFileSize = 0, $gCounter = 0
  Local $ArrayOfFileSizes[UBound($URLArray)]
; ===================================================================
; $iPercentage      - variable for calculating percents of running action, get fsizes and get file
; $iBytesRead       - for accumulate progress of getted data in cycle
; $iInetBytesRead   - currently readed data with InetGet func
; $sProgressText    - string var. for showing stats in progress window (under progress bar)
; $sCounter     - integer for increment of array index in getting file sizes
; $TotalFileSize    - integer that keeps total amount of bytes to get
; $gCounter     - integer for indexing of array of given url's
; $ArrayOfFileSizes - array for keep of getted file sizes
; ===================================================================

if not IsArray($URLArray) then Return SetError(1, 1, 0)

ProgressOn ('','')
    While $sCounter < UBound($URLArray)
     $ArrayOfFileSizes[$sCounter] = InetGetSize($URLArray[$sCounter], 1)
     $TotalFileSize += $ArrayOfFileSizes[$sCounter]
     $iPercentage = $sCounter * 100 / UBound($URLArray)
     $sProgressText = $URLArray[$gCounter] & @CRLF & 'filesize: ' & $ArrayOfFileSizes[$sCounter] & ' , total: ' & $TotalFileSize & ' bytes'
ProgressSet(Round($iPercentage, 0), $sProgressText, 'Getting file size of ' & $sCounter & ' of ' & UBound($URLArray))
     $sCounter += 1
     Sleep (100)
    WEnd
ProgressOff()



    if not FileExists(@ScriptDir & '\' & $toFolder) then DirCreate (@ScriptDir & '\' & $toFolder)

ProgressOn("", "")

    While $gCounter < UBound($URLArray)

    Local $hDownload = InetGet($URLArray[$gCounter], @ScriptDir & '\' & $toFolder & '\' & fnURL ($URLArray[$gCounter]), 0, 1)
    If @error Then Return SetError(1, 1, 0)

    
    While Not InetGetInfo($hDownload, 2)
        $iInetBytesRead = InetGetInfo($hDownload, 0)
        $iPercentage = ($iBytesRead+$iInetBytesRead) * 100 / $TotalFileSize
        $sProgressText = "Downloading " & _ByteSuffix($iBytesRead+$iInetBytesRead) & " Of " & _ByteSuffix($TotalFileSize) & @CRLF & 'Image ' & $gCounter & ' of ' & UBound($URLArray)
        ProgressSet(Round($iPercentage, 0), $sProgressText, "Downloading " & $toFolder & '\' & fnURL($URLArray[$gCounter]))
        Sleep(100)
    WEnd

    $iBytesRead += $ArrayOfFileSizes[$gCounter]
    $gCounter += 1
    WEnd ; main while from array

    InetClose($hDownload)
ProgressOff()

EndFunc   ;==>_InetGetProgress

Func _ByteSuffix($iBytes) ; By Spiff59 >> http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_
    $iBytes /= 1024
    Return Round($iBytes) & ' Kb'
EndFunc   ;==>_ByteSuffix

Func _ExByteSuffix($iBytes) ; By Spiff59 >> http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_
    Local $A, $aArray[6] = [" B", " KB", " MB", " GB", " TB", " PB"]
    While $iBytes > 1023
        $A += 1
        $iBytes /= 1024
    WEnd
    Return Round($iBytes) & $aArray[$A]
EndFunc   ;==>_ByteSuffix

Func fnURL ($httpurl) ; get filename from given URL
Local $res = StringRegExp ($httpurl,"(?i)([a-z0-9\-_~%!$&'();=]+)(?:.jpg|.jpeg|.gif|.bmp)",2);
 Return $res[0]
EndFunc

Example

#include <Inet.au3>
#include <Array.au3>

$htmlbase = _INetGetSource("http://epidemz.net/pro_eto/page/10/index.php")

$ParsedPictures = StringRegExp ($htmlbase,'<!--dle_image_begin:(http:\/\/.*?)(?!.jpg|.jpeg|.gif|.bmp)\|-->',3)
;<!--dle_image_begin:(http:\/\/.*?)(?!.jpg|.jpeg|.gif|.bmp)\|-->


_ArrayDisplay ($ParsedPictures)
_InetGetProgressArray($ParsedPictures,'temp23')


; ===================================================================
; ===================================================================
; _InetGetProgressArray(ByRef $URLArray, [$toFolder])
;
; Get all files passed to func with array of links. Calculate all size of files and shows getting progress.
; Parameters:
;    $URLArray  - IN - Array of links ie 'http://site.com/folder/file.ext'
;    $toFolder  - OPTIONAL IN - Name of local folder to put files to. If not set then put files near running script.
; Returns:
;    None but if errors.
; ===================================================================

Func _InetGetProgressArray(ByRef $URLArray, $toFolder = '')

; ===================================================================
  Local $iPercentage, $iBytesRead, $iInetBytesRead, $sProgressText
  Local $sCounter = 0, $TotalFileSize = 0, $gCounter = 0
  Local $ArrayOfFileSizes[UBound($URLArray)]
; ===================================================================
; $iPercentage      - variable for calculating percents of running action, get fsizes and get file
; $iBytesRead       - for accumulate progress of getted data in cycle
; $iInetBytesRead   - currently readed data with InetGet func
; $sProgressText    - string var. for showing stats in progress window (under progress bar)
; $sCounter     - integer for increment of array index in getting file sizes
; $TotalFileSize    - integer that keeps total amount of bytes to get
; $gCounter     - integer for indexing of array of given url's
; $ArrayOfFileSizes - array for keep of getted file sizes
; ===================================================================

if not IsArray($URLArray) then Return SetError(1, 1, 0)

ProgressOn ('','')
    While $sCounter < UBound($URLArray)
     $ArrayOfFileSizes[$sCounter] = InetGetSize($URLArray[$sCounter], 1)
     $TotalFileSize += $ArrayOfFileSizes[$sCounter]
     $iPercentage = $sCounter * 100 / UBound($URLArray)
     $sProgressText = $URLArray[$gCounter] & @CRLF & 'filesize: ' & $ArrayOfFileSizes[$sCounter] & ' , total: ' & $TotalFileSize & ' bytes'
ProgressSet(Round($iPercentage, 0), $sProgressText, 'Getting file size of ' & $sCounter & ' of ' & UBound($URLArray))
     $sCounter += 1
     Sleep (100)
    WEnd
ProgressOff()



    if not FileExists(@ScriptDir & '\' & $toFolder) then DirCreate (@ScriptDir & '\' & $toFolder)

ProgressOn("", "")

    While $gCounter < UBound($URLArray)

    Local $hDownload = InetGet($URLArray[$gCounter], @ScriptDir & '\' & $toFolder & '\' & fnURL ($URLArray[$gCounter]), 0, 1)
    If @error Then Return SetError(1, 1, 0)

    
    While Not InetGetInfo($hDownload, 2)
        $iInetBytesRead = InetGetInfo($hDownload, 0)
        $iPercentage = ($iBytesRead+$iInetBytesRead) * 100 / $TotalFileSize
        $sProgressText = "Downloading " & _ByteSuffix($iBytesRead+$iInetBytesRead) & " Of " & _ByteSuffix($TotalFileSize) & @CRLF & 'Image ' & $gCounter & ' of ' & UBound($URLArray)
        ProgressSet(Round($iPercentage, 0), $sProgressText, "Downloading " & $toFolder & '\' & fnURL($URLArray[$gCounter]))
        Sleep(100)
    WEnd

    $iBytesRead += $ArrayOfFileSizes[$gCounter]
    $gCounter += 1
    WEnd ; main while from array

    InetClose($hDownload)
ProgressOff()

EndFunc   ;==>_InetGetProgress

Func _ByteSuffix($iBytes) ; By Spiff59 >> http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_
    $iBytes /= 1024
    Return Round($iBytes) & ' Kb'
EndFunc   ;==>_ByteSuffix

Func _ExByteSuffix($iBytes) ; By Spiff59 >> http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_
    Local $A, $aArray[6] = [" B", " KB", " MB", " GB", " TB", " PB"]
    While $iBytes > 1023
        $A += 1
        $iBytes /= 1024
    WEnd
    Return Round($iBytes) & $aArray[$A]
EndFunc   ;==>_ByteSuffix

Func fnURL ($httpurl) ; get picture filename from given URL
Local $res = StringRegExp ($httpurl,"(?i)([a-z0-9\-_~%!$&'();=]+)(?:.jpg|.jpeg|.gif|.bmp)",2);
 Return $res[0]
EndFunc
Edited by pasmo

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcolme to the Forums !

pasmo, imagines that a young woman falls in your photos that you ask us to download, she would be outraged ! Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
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
Sign in to follow this  
Followers 0