Nunos Posted February 24, 2012 Posted February 24, 2012 (edited) I am trying to use the script that Storme made to download a file from Filehippo. I would just like to learn how to get one of the fields from the array so I can try to run it from a script. Basicaly it returns tons of information about the file it downloaded and offers you to copy a selected field. I would like to not display the array but instead get the filename that is in field 3 of the returned array. I looked through the beginners guide but I couldn't wrap my head around how to accomplish it. If someone could help I would appreciate it. The script is pasted below. Oh and if possible to keep that killer little progress bar thing that would be killer my attempts at making it do what I want I have removed that on accident expandcollapse popup#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]) ; Parameters ....: $sProgramTitle - the title of the program as it appears in the URL ; - "malwarebytes_anti_malware" from [url="http://filehippo.com/download_malwarebytes_anti_malware/"]http://filehippo.com/download_malwarebytes_anti_malware/[/url] ; $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 ; $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 ; 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' ; 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, $FunctionToCall = "") Local $DownloadUrl, $asDownloadUrl Local $sCurrentVersion, $asCurrentVersion Local $sBaseSite = 'http://filehippo.com' Local $sBaseFolder = '/download_' & $sProgramTitle & '/' ;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 ;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) If @error Then Return SetError(2, 0, "") EndIf $sDescTable = $asDescTable[0] ;Split up table $asDescTable = StringRegExp($sDescTable, '(?s)(?i)<b>(.*?):</b>(.*?)', 3) If @error Then Return SetError(2, 0, "") EndIf ;Latest Version <b>Malwarebytes Anti-Malware 1.51.1</b> Old Versions $asCurrentVersion = StringRegExp($sPageSource, '(?s)(?i)Latest Version Old Versions', 3) If @error Then Return SetError(2, 0, "") EndIf $sCurrentVersion = StringMid($asCurrentVersion[0], StringInStr($asCurrentVersion[0], " ", 0, -1) + 1) ;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 ;Latest Version <b>Malwarebytes Anti-Malware 1.51.1</b> Old Versions $asCurrentVersion = StringRegExp($sPageSource, '(?s)(?i)Latest Version Old Versions', 3) If @error Then Return SetError(2, 0, "") EndIf $_FileDetails[1][0] = "Latest Version" $_FileDetails[1][1] = StringMid($asCurrentVersion[0], StringInStr($asCurrentVersion[0], " ", 0, -1) + 1) If $bDownload Then ;</br(.*?)<></br(.*?)<></div></a><div class="desc"><a href="/download_malwarebytes_anti_malware/download/f9c81a8e689661f472f47aa7a0b12ada/"><img alt="Download" src="[url=" img="" url]?="" down5.png[="" cache.filehippo.com=""></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 ; how many 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 MsgBox(0, "Name", $_FileDetails[3]) 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 ProgressOn("FileHippo Download", "Downloading : malwarebytes_anti_malware") $test = _FileHippoDownload("malwarebytes_anti_malware", @ScriptDir & "downloads", "", 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 Edited February 24, 2012 by Melba23 Added code tags
water Posted February 24, 2012 Posted February 24, 2012 (edited) Directly access the element in the array. $aResult = _FileHippoDownload(...) ConsoleWrite($aResult[3] & @CRLF) Edited February 24, 2012 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Nunos Posted February 24, 2012 Author Posted February 24, 2012 ok so where would I insert that? Do I need to declare $aResult as a local or global variable first somewhere? Thank you for teaching me
Moderators Melba23 Posted February 24, 2012 Moderators Posted February 24, 2012 Nunos,When you post code please use Code tags - put [autoit] before and [/autoit] after your posted code. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Nunos Posted February 24, 2012 Author Posted February 24, 2012 Sorry I don't know much about html code either but I will learn it. Nunos
water Posted February 24, 2012 Posted February 24, 2012 This is the line whre you call function _FileHippoDownload: $test = _FileHippoDownload("malwarebytes_anti_malware", @ScriptDir & "\downloads\", "", True, "_UpdateProgress") So $test is the array. Use $test[3] to access the 3rd element. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
AdmiralAlkex Posted February 25, 2012 Posted February 25, 2012 We have an Array Tutorial in the wiki, maybe you want to take a look? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
Nunos Posted February 25, 2012 Author Posted February 25, 2012 Sweet thank you all for the help and links to more information. I got it to work ShellExecuteWait($test[3][1],"/silent",@ScriptDir &"downloads", "",@SW_HIDE) ;Install MBAM
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now