This has come in useful in a few projects now so I thought I'd release it and maybe it'll be useful for others.
The usage is straight froward and all in the header so I haven't included a test file. If you need help let me know.
I've had help writing this but can't remember who. If you've helped me on this let me know (IM) and I'll add your name.
If you have any advice or improvements please let me know.
Example
ProgressOn("FileHippo Download", "Downloading : malwarebytes_anti_malware") $test = _FileHippoDownload("malwarebytes_anti_malware", @ScriptDir & "\downloads\", "", True, True, "_UpdateProgress") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $test = ' & $test & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ProgressOff() _ArrayDisplay($test) Exit #include <Misc.au3> Func _UpdateProgress($Percentage) ProgressSet($Percentage, $Percentage & "%") If _IsPressed("77") Then Return False ; Abort on F8 Return True ; bei 1 Fortsetzten EndFunc ;==>_UpdateProgress
#cs ConsoleWrite("Start: malwarebytes_anti_malware") $MWB_down = _FileHippoDownload("malwarebytes_anti_malware", @ScriptDir & "\file_includes", "install_malware.exe", True) If @error Then MsgBox(0, "Error", @error) EndIf ConsoleWrite("End: malwarebytes_anti_malware") ConsoleWrite("Start: avg_antivirus_32") $AVG32_down = _FileHippoDownload("avg_antivirus_32", @ScriptDir & "\file_includes", "install_avg_32.exe", True) If @error Then MsgBox(0, "Error", @error) EndIf ConsoleWrite("End: avg_antivirus_32") ConsoleWrite("Start: avg_antivirus_64") $AVG64_down = _FileHippoDownload("avg_antivirus_64", @ScriptDir & "\file_includes", "install_avg_64.exe", True) If @error Then MsgBox(0, "Error", @error) EndIf ConsoleWrite("End: avg_antivirus_64") ;#AutoIt3Wrapper_Run_Debug_Mode=y ProgressOn("FileHippo Download", "Downloading : Firefox") $test = _FileHippoDownload("firefox", @ScriptDir & "\downloads\", "", True, False, "_UpdateProgress") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $test = ' & $test & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ProgressOff() _ArrayDisplay($test) Exit #include <Misc.au3> Func _UpdateProgress($Percentage) ProgressSet($Percentage, $Percentage & "%") If _IsPressed("77") Then Return False ; Abort on F8 Return True ; bei 1 Fortsetzten EndFunc ;==>_UpdateProgress #ce #include-once #include <array.au3> ; #FUNCTION# ==================================================================================================================== ; Name...........: _FileHippoDownload ; Description ...: Downloads the designated file from FileHippo and/or returns the latest verison number ; Syntax.........: _FileHippoDownload($sProgramTitle, $sDownloadFolder[, $sDownloadFileName = ""][, $bDownload = True][,$bSkipBeta = True][, $FunctionToCall = ""]) ; Parameters ....: $sProgramTitle - the title of the program as it appears in the URL ; - "malwarebytes_anti_malware" from <a href='http://filehippo.com/download_malwarebytes_anti_malware/' class='bbc_url' title='External link' rel='nofollow external'>http://filehippo.com/download_malwarebytes_anti_malware/</a> ; $sDownloadFolder - the full path for the file to be downloaded to ; $sDownloadFileName - the filename of the file to be downloaded ; - if filename = "" use filename from filehippo ; $bDownload - [optional] True = program will be downloaded False = return Version number ONLY ; $bSkipBeta - [optional] True = BETA copies will not be downloaded False = latest version will be downloaded ; $FunctionToCall - [optional] A function which can update a Progressbar and react on UserInput like Click on Abort or Close App. ; - If "$FunctionToCall" returns False abort download ; - Func _UpdateProgress($Percentage) ; - ProgressSet($Percentage,$Percentage &"%") ; - If _IsPressed("77") Then Return False ; Abort on F8 ; - Return True ; ALL OK Continue download ; - Endfunc ; Return values .: Success - returns a 2D array containing technical details about the file (eg Filename, author, etc) ; - element [0][0] contains row count ; Failure - "" ; @error = 1 - Unable to download programs/description page ; @error = 2 - Unable to read programs/description page ; @error = 3 - Unable to read download page ; @error = 4 - Unable to read URL to download program ; @error = 5 - Unable to download program ; @error = 6 - Destination not reachable ; @error = 7 - Aborted by $FunctionToCall ; @error = 8 - $FunctionToCall doesn't exist ; @error = 9 - $bSkipBeta=TRUE however there are no NON-Beta files to download ; Author ........: John Morrison aka Storm-E ; Modified.......: V2.0 Added details from TECH tab ; : V2.1 Added create destination folder and error code if it can't be created @error = 6 ; : Changed InetGet to work in the backgroud and added sleep to give script time to do things (eg for adlib) ; : Changed returned array to return row count in element 0,0 ; : Added "Latest Version" number to array (element[1][1] (left it out in V2.0 OOPS ; : V2.11 Added Progress function $FunctionToCall ; : V2.12 Added check if $FunctionToCall function exists ; : V2.121 Minor fix for properties that may not exist (Author & HomePage) Thanks 'Chimaera' ; : V2.13 Added option to ignore BETA copies "$bSkipBeta" ; : V2.14 Change on FileHippo site messed up site scape Thanks engjcowi ; Remarks .......: Thanks to skin27 for your suggestion to add details and auto filename from filehippo ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _FileHippoDownload($sProgramTitle, $sDownloadFolder, $sDownloadFileName = "", $bDownload = True, $bSkipBeta = True, $FunctionToCall = "") Local $DownloadUrl, $asDownloadUrl Local $sCurrentVersion, $asCurrentVersion Local $sBaseSite = 'http://filehippo.com' Local $sBaseFolder = '/download_' & $sProgramTitle & '/' Local $sVersionFolder = "" ; for Beta rejection ;String trailing slash "\" If StringRight($sDownloadFolder, 1) = "\" Then StringLeft($sDownloadFolder, StringLen($sDownloadFolder) - 1) If DirCreate($sDownloadFolder) = 0 Then Return SetError(6, 0, "") ; destination unreachable ;Get source for program page Local $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder) If @error Then ;Failed to get programs page Return SetError(1, 0, "") EndIf ;Latest Version<br/><b>Malwarebytes Anti-Malware 1.51.1</b><br/><br/>Old Versions $asCurrentVersion = StringRegExp($sPageSource, '(?s)(?i)Latest Version<br(.*?)</b><br/><br/>Old Versions', 3) If @error Then Return SetError(2, 0, "") EndIf $sCurrentVersion = StringMid($asCurrentVersion[0], StringInStr($asCurrentVersion[0], " ", 0, -1) + 1) ;Check for BETA copy rejection If $bSkipBeta And StringInStr($asCurrentVersion[0], "beta") <> 0 Then ;Get table of old versions $asCurrentVersion = StringRegExp($sPageSource, '(?s)(?i)>Old Versions<(.*?)download_firefox/history/', 3) If @error Then Return SetError(2, 0, "") EndIf ; Break table into array $asCurrentVersion = StringRegExp($asCurrentVersion[0], '(?s)(?i)<a href="/download_firefox/(.*?)/">(.*?)</a>', 3) If @error Then Return SetError(2, 0, "") EndIf ;search array for NON beta version For $iItem = 1 To UBound($asCurrentVersion) - 1 Step 2 If StringInStr($asCurrentVersion[$iItem], "beta") = 0 Then $sVersionFolder = $asCurrentVersion[$iItem - 1] & "/" $sCurrentVersion = StringMid($asCurrentVersion[$iItem], StringInStr($asCurrentVersion[$iItem], " ", 0, -1) + 1) ExitLoop EndIf Next If $sVersionFolder = "" Then ;NO NON BETA version available Return SetError(9, 0, "") Else ;Found non beta ;Get source for non beta program page Local $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder & $sVersionFolder) If @error Then ;Failed to get programs page Return SetError(1, 0, "") EndIf EndIf EndIf ;Get download URL $asDownloadUrl = StringRegExp($sPageSource, '(?s)(?i)<a href="' & $sBaseFolder & 'download/(.*?)/">', 3) If @error Then Return SetError(2, 0, "") EndIf $_DownloadUrl1 = $asDownloadUrl[0] ;Get source for details page Local $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder & 'tech/') If @error Then ;Failed to get programs page Return SetError(1, 0, "") EndIf ;Get Details/description Table ;$asDescTable = StringRegExp($sPageSource, '(?s)(?i)<div class="desc">.*?<table>(.*?)</table>', 3) $asDescTable = StringRegExp($sPageSource, '(?s)(?i)<div id="txt">.*?<table>(.*?)</table>', 3) If @error Then Return SetError(2, 0, "") EndIf $sDescTable = $asDescTable[0] ;Split up table $asDescTable = StringRegExp($sDescTable, '(?s)(?i)<tr><td><b>(.*?):</b></td><td>(.*?)</td></tr>', 3) If @error Then Return SetError(2, 0, "") EndIf ;Convert to 2D array Dim $_FileDetails[UBound($asDescTable) / 2 + 2][2] $_FileDetails[0][0] = UBound($asDescTable) / 2 ; number of rows in array $_FileDetails[2][0] = $asDescTable[0] $_FileDetails[2][1] = $asDescTable[1] For $item = 2 To UBound($asDescTable) - 1 Step 2 $_FileDetails[$item / 2 + 2][0] = $asDescTable[$item] $_FileDetails[$item / 2 + 2][1] = $asDescTable[$item + 1] Next ;Cleanup Author Local $iIndex = _ArraySearch($_FileDetails, "Author") If Not @error Then $_FileDetails[$iIndex][1] = StringLeft($_FileDetails[$iIndex][1], StringInStr($_FileDetails[$iIndex][1], "<") - 1) EndIf ;Cleanup HomePage $iIndex = _ArraySearch($_FileDetails, "HomePage") If Not @error Then $_FileDetails[$iIndex][1] = StringMid($_FileDetails[$iIndex][1], StringInStr($_FileDetails[$iIndex][1], "href=") + 6) $_FileDetails[$iIndex][1] = StringMid($_FileDetails[$iIndex][1], 1, StringInStr($_FileDetails[$iIndex][1], '"') - 1) EndIf $_FileDetails[1][0] = "Latest Version" $_FileDetails[1][1] = $sCurrentVersion If $bDownload Then ;<a href="/download_malwarebytes_anti_malware/download/f9c81a8e689661f472f47aa7a0b12ada/"><img src="<a href='http://cache.filehippo.com/img/down5.png' class='bbc_url' title='External link' rel='nofollow external'>http://cache.filehippo.com/img/down5.png"</a> alt="Download"/></a> ;Get source for download page $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder & 'download/' & $_DownloadUrl1) ; downlaod page If @error Then ;Failed to get programs page Return SetError(3, 0, "") EndIf ;<a id="_ctl0_contentMain_lnkURL" class="black" href="/download/file/de709ff1117ec419609d7fceecd86e625fe523b1385fa00515aa824249206a40/">If not then please click this link</a> $asDownloadUrl = StringRegExp($sPageSource, '(?s)(?i)href="/download/file/(.*?)/">', 3) If @error Then Return SetError(4, 0, "") EndIf $DownloadUrl = "/download/file/" & $asDownloadUrl[0] & "/" If $sDownloadFileName = "" Then ;Use FileHippo filename $sDownloadFileName = $_FileDetails[_ArraySearch($_FileDetails, "Filename")][1] EndIf ; DOWNLOAD FILE Local $iFileSize = InetGetSize($sBaseSite & $DownloadUrl, 1) Local $DownloadedSoFar = 0 ; howmany bytes of the file have been downloaded Local $bRtn = True ; Progress function return OK Local $hDownload = InetGet($sBaseSite & $DownloadUrl, $sDownloadFolder & "\" & $sDownloadFileName, 1, 1) Do If $FunctionToCall <> "" Then $bRtn = Call($FunctionToCall, Floor((InetGetInfo($hDownload, 0) / $iFileSize) * 100)) If @error Then InetClose($hDownload) ; Close the handle to release resourcs. Return SetError(8, 0, "") EndIf EndIf Sleep(250) Until InetGetInfo($hDownload, 2) Or $bRtn = False ; Check if the download is complete. Local $nBytes = InetGetInfo($hDownload, 0) InetClose($hDownload) ; Close the handle to release resourcs. If @error Then Return SetError(5, 0, "") EndIf If $bRtn = False Then ;Download aborted by $FunctionToCall Return SetError(7, 0, "") EndIf EndIf Return $_FileDetails EndFunc ;==>_FileHippoDownload Func _GetSourceCode($_Url) Local $_InetRead = InetRead($_Url) If Not @error Then Local $_BinaryToString = BinaryToString($_InetRead) If Not @error Then Return $_BinaryToString EndIf EndFunc ;==>_GetSourceCode
Edits
12/08/2011 V2.0 added details from FileHippo site returned as a 2D array, also if filename is blank will use file name from FileHippo
14/08/2011 V2.1 Added create destination folder and error code if it can't be created @error = 6
- Changed InetGet to work in the backgroud and added sleep to give script time to do things (eg for adlib)
- Changed returned array to return row count in element 0,0
- Other minor changes
14/08/2011 V2.11 Added progress bar function call
16/08/2011 V2.12 Added check if $FunctionToCall function exists
17/08/2011 V2.121 Minor fix for properties that may not exist (Author HomePage) Thanks 'Chimaera'
18/02/2012 V2.13 Added option to ignore BETA copies "$bSkipBeta"
18/04/2012 V2.14 Change on FileHippo site messed up site scrape Thanks engjcowi
Edited by storme, 18 April 2012 - 01:00 PM.





