Jump to content

_MultiSiteDownload FileHippo, PortableApp, etc


storme
 Share

Recommended Posts

G'day All

At the moment this is a a place holder for the code that will follow.

Purpose:

A Central function _MultiSiteDownload that will download programs/updates/etc from multiple file sites.

Behind this funciton will be a UDF for each site (eg "_PortableApp_Download", "_FileHippoDownload") that can be split off if your project only needs to download from one of these sites.)

Use:

Add to your projects that use 3rd party tools so they can be downloaded when needed.

Existing code links

FileHippo

Portableapps

/page__st__20#entry1008033

SourceForge

/page__st__20#entry918460

Download.com

/page__st__20#entry918356

The only one I can vouch for at the moment is teh filehippo and portableapps downloader. The rest I'll have to test to make sure they are still working. When I have I'll move then to this tread.

If you have any code to add to the collection please post and I'll add it.

Onward and upward

John Morrison

Link to comment
Share on other sites

Do you mean something like this. It uses an external program http://users.ugent.be/~bpuype/wget/ because sometimes i had no luck with inetget.

#include
ProgressOn("Regular Download", "Downloading : Chrome")
_Regulardownload("http://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi", "GoogleChromeStandaloneEnterprise.msi")
ProgressOff()

Func _DownloadProgress($Percentage)
ProgressSet($Percentage, $Percentage & "%")
Return True
EndFunc

Func _Regulardownload($command, $dest)
$Pid = Run('"' & @ComSpec & '" /c ' & @ScriptDir & "\wget.exe " & "-O " & @ScriptDir & "\install\" & $dest & " " & $command, '', @SW_HIDE, 2 + 4)
MsgBox(1,"teszt", @ScriptDir & "\wget.exe ")
While 1
$text = StderrRead($Pid, False, False)
If @error Then ExitLoop
Sleep(10)
Local $tmp = _StringBetween($text, ".....", '%')
If @error <> 1 Then
$percent = StringReplace($tmp[0], ".", "");
$percent = StringStripWS($percent, "7");
_DownloadProgress($percent)
EndIf
WEnd
EndFunc
Link to comment
Share on other sites

Do you mean something like this. It uses an external program http://users.ugent.be/~bpuype/wget/ because sometimes i had no luck with inetget.

Not quiet but in teh ball park. :)

With the sites in the first post it isn't as simple as using a URL to download a file.

However, your scirpt maybe added to the UDF for those that want to use wget with a progress bar.

Thanks for the input!

John Morrison

Link to comment
Share on other sites

Heres some code ;)

#include-once
#include <Array.au3>
#include <File.au3>
#include <Misc.au3>
#include <WinAPIEx.au3> ; http://www.autoitscript.com/forum/topic/98712-winapiex-udf/
#include <WinHttp.au3> ; https://code.google.com/p/autoit-winhttp/downloads/list

Global $iDownload_Mode = 0
Global $sDownload_UserAgent = ''

Global Enum $iFileHippo, $iPortableApps, $iSourceForge, $iCnet
Global Enum $iDomainName, $iQuerySyntax

Global Const $aDownloadSite[4][2] = [ _
        ['http://filehippo.com', '/download_'], _
        ['http://sourceforge.net', '/projects/'], _
        ["http://downloads.sourceforge.net/portableapps", "/"], _
        ['http://download.com', '/'] _
        ]

If @ScriptName = 'MultiSiteDownload.au3' Then

;~     _Set_MS_Mode('WinHttp', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1) Gecko/20100101 Firefox/10.0.1')
;~     Dim $_FileDetails = _MultiSite_Download('FileHippo', 'avg_antivirus_32', @ScriptDir, 'avg_antivirus_32.exe', True, False, '_UpdateProgress')
;~     _ArrayDisplay($_FileDetails)

    _Set_MS_Mode('InetGet', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1) Gecko/20100101 Firefox/10.0.1')
    ProgressOn("FileHippo Download", "Downloading : avg_antivirus_32")
    Dim $_FileDetails = _MultiSite_Download('FileHippo', 'avg_antivirus_32', @ScriptDir, 'avg_antivirus_32.exe', True, False, '_UpdateProgress')
    ProgressOff()
    _ArrayDisplay($_FileDetails)

EndIf

Func _Set_MS_Mode($sMode = 'InetGet', $sUserAgent = '') ; [InetGet or WinHttp or wGet] ; wGet reguires http://users.ugent.be/~bpuype/wget/
    Local Enum $InetGet, $WinHttp, $wGet
    Select
        Case StringInStr($sMode, 'InetGet', 2)
            $iDownload_Mode = $InetGet ; 0
        Case StringInStr($sMode, 'WinHttp', 2)
            $iDownload_Mode = $WinHttp ; 1
        Case StringInStr($sMode, 'wGet', 2)
            $iDownload_Mode = $wGet ; 2
    EndSelect
    $sDownload_UserAgent = $sUserAgent
    If $sUserAgent <> '' Then HttpSetUserAgent($sDownload_UserAgent)
EndFunc   ;==>_Set_MS_Mode

Func _MultiSite_Download($sWebSite, $sProgramTitle = "", $sDownloadPath = @WorkingDir, $sDownloadFileName = "", $vParam1 = "", $vParam2 = "", $vParam3 = "")
    For $iSite = $iFileHippo To $iCnet
        If StringInStr($aDownloadSite[$iSite][$iDomainName], $sWebSite, 2) Then ExitLoop
        If $iSite = $iCnet Then Return SetError(1, 0, 0)
    Next

    Switch $iSite
        Case $iFileHippo
            Local $vReturn = _FileHippoDownload($sProgramTitle, $sDownloadPath, $sDownloadFileName, $vParam1, $vParam2, $vParam3)
        Case $iPortableApps
            ;Local $vReturn = _PortableApp_Download($sProgramTitle, $sDownloadPath, $sDownloadFileName, $vParam1)
        Case $iSourceForge
            ;Local $vReturn = _SourceforgeDownload($sProgramTitle, $sDownloadPath, $sDownloadFileName, $vParam1)
        Case $iCnet
            ;Local $vReturn = _CnetDownload($sProgramTitle, $sDownloadPath, $sDownloadFileName, $vParam1)
    EndSwitch

    Local $iError = @error
    If $iError Then Return SetError($iError, 0, "")

    Return $vReturn
EndFunc   ;==>_MultiSite_Download

Func _FileHippoDownload($sProgramTitle, $sDownloadFolder, $sDownloadFileName = "", $bDownload = True, $bSkipBeta = True, $FunctionToCall = "")
    Local $DownloadUrl, $asDownloadUrl
    Local $sCurrentVersion, $asCurrentVersion
    Local $sBaseSite = $aDownloadSite[$iFileHippo][$iDomainName]
    Local $sBaseFolder = $aDownloadSite[$iFileHippo][$iQuerySyntax] & $sProgramTitle & '/'
    Local $sVersionFolder = "" ; for Beta rejection


    _FileCreateDownloadDir($sDownloadFolder)
    If @error Then Return SetError(6, 0, "")


    ;Get source for program page
    Local $sPageSource = _GetSourceCode($sBaseSite & $sBaseFolder)
    If @error Then Return SetError(1, 0, "") ;Failed to get programs page

    ;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="http://cache.filehippo.com/img/down5.png" 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

        _FileDownload($sBaseSite & $DownloadUrl, $sDownloadFolder, $sDownloadFileName, $FunctionToCall)
    EndIf
    Return $_FileDetails
EndFunc   ;==>_FileHippoDownload

Func _FileCreateDownloadDir($sDownloadFolder)
    If StringRight($sDownloadFolder, 1) = "" Then StringLeft($sDownloadFolder, StringLen($sDownloadFolder) - 1) ; String trailing slash ""
    If DirCreate($sDownloadFolder) = 0 Then Return SetError(1, 0, 0) ; Destination unreachable
EndFunc

Func _FileDownload($sUrl, $sDownloadFolder, $sDownloadFileName, $sFunction)
    Switch $iDownload_Mode
        Case 0
            Local $iFileSize = InetGetSize($sUrl, 1)
            Local $bRtn = True ; Progress function return OK
            Local $hDownload = InetGet($sUrl, $sDownloadFolder & "" & $sDownloadFileName, 1, 1)
            Do
                If $sFunction <> "" Then
                    $bRtn = Call($sFunction, 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 $sFunction
                Return SetError(7, 0, "")
            EndIf
        Case 1
            FileChangeDir($sDownloadFolder)
            _WinHttpGet($sUrl, $sDownloadFileName, True)
    EndSwitch
EndFunc

#region ### Example Functions ###
Func _Example_FileHippoDownload()
    Local $sDownloadFolder = @ScriptDir & "file_includes", $Return_Value, $aProgramTitle[4] = ['avg_antivirus_32', _
        'malwarebytes_anti_malware', 'avg_antivirus_64', 'firefox']
    For $iTitle = 0 To UBound($aProgramTitle, 1) - 1
        ConsoleWrite(@CRLF & "> Start: " & $aProgramTitle[$iTitle] & @CRLF)
        ProgressOn("FileHippo Download", "Downloading : " & $aProgramTitle[$iTitle])
        $Return_Value = _MultiSite_Download("FileHippo", $aProgramTitle[$iTitle], $sDownloadFolder, 'install_' & $aProgramTitle[$iTitle] & '.exe', True, False, "_UpdateProgress")
        ProgressOff()
        _ArrayDisplay($Return_Value)
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Return_Value = ' & $Return_Value & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
        ConsoleWrite(@CRLF & "End: " & $aProgramTitle[$iTitle] & @CRLF)
    Next
EndFunc   ;==>_Example_FileHippoDownload
#endregion ### Example Functions ###
#region ### Internal Functions ###
Func _UpdateProgress($Percentage) ; Requires #include <Misc.au3>
    ProgressSet($Percentage, $Percentage & "%")
    If _IsPressed("77") Then Return False ; Abort on F8
    Return True ; bei 1 Fortsetzten
EndFunc   ;==>_UpdateProgress
Func _GetSourceCode($_Url)
    Switch $iDownload_Mode
        Case 0
            Local $_InetRead = InetRead($_Url)
        Case 1
            Return _WinHttpRead($_Url)
    EndSwitch
    If Not @error Then
        Local $_BinaryToString = BinaryToString($_InetRead)
        If Not @error Then Return $_BinaryToString
    EndIf
EndFunc   ;==>_GetSourceCode
Func _ByteSuffix($iBytes, $iRound = 2)
    ; UnKnown Author
    Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"]
    While $iBytes > 1023
        $A += 1
        $iBytes /= 1024
    WEnd
    Return Round($iBytes, $iRound) & $aArray[$A]
EndFunc   ;==>_ByteSuffix
Func _WinHttpRead($sDownload_URI, $sReferer = Default)
    Return _WinHttpGet($sDownload_URI, Default, False, $sReferer)
EndFunc
Func _WinHttpGet($sDownload_URI, $sFile_Name = Default, $iFileMode = False, $sReferer = Default)
    Local $aSplit_URL = _WinHttpCrackUrl($sDownload_URI)
    Local $hOptTime = TimerInit()
    Local $hWinHttpOpen = _WinHttpOpen()
    Local $hWinHttpConnect = _WinHttpConnect($hWinHttpOpen, $aSplit_URL[2])
    Local $hWinHttpRequest = _WinHttpOpenRequest($hWinHttpConnect, "GET", $aSplit_URL[6], Default, $sReferer)
    _WinHttpSendRequest($hWinHttpRequest)
    _WinHttpReceiveResponse($hWinHttpRequest)
    Local $iSizeBytes = _WinHttpQueryHeaders($hWinHttpRequest, $WINHTTP_QUERY_CONTENT_LENGTH)
    If _WinHttpQueryDataAvailable($hWinHttpRequest) Then
        Local $iBytePerStep = 8192
        Local $iBufferSize = 1024 * 1024
        If $iFileMode Then
            If $sFile_Name = Default Then $sFile_Name = @WorkingDir & "" & StringTrimLeft($aSplit_URL[6], StringInStr($aSplit_URL[6], "/", 0, -1))
            Local $hFile = _WinAPI_CreateFileEx($sFile_Name, $CREATE_NEW, $GENERIC_WRITE, $FILE_SHARE_READ, $FILE_ATTRIBUTE_NORMAL)
        EndIf
        Local $tBuffer = DllStructCreate("byte[" & $iBufferSize & "]")
        Local $pBuffer = DllStructGetPtr($tBuffer)
        Local $tOverlapped = _GetStruct_Overlapped(0)
        Local $pOverlapped = DllStructGetPtr($tOverlapped)
        Local $iByteWritten = 0
        Local $iOffsetFile = 0
        If $iFileMode Then
            Local $vData = Binary("")
        Else
            Local $vData = ""
        EndIf
        Local $iError, $iBufferContent, $iByteWritten
        ConsoleWrite(@CRLF & "> Downloading " & $sFile_Name & @CRLF)
        Do
            If $iFileMode Then
                $vData &= _WinHttpReadData($hWinHttpRequest, 2, $iBytePerStep) ; Get Chunk
            Else
                $vData &= _WinHttpReadData($hWinHttpRequest)
            EndIf
            $iError = @error
            If $iFileMode Then
                $iBufferContent = BinaryLen($vData)
                If $iBufferContent >= $iBufferSize - $iBytePerStep Or $iError = -1 Then
                    _WinAPI_GetOverlappedResult($hFile, $pOverlapped, $iByteWritten, True)
                    DllStructSetData($tBuffer, 1, $vData)
                    $vData = Binary("")
                    $iOffsetFile += $iByteWritten
                    $tOverlapped = _GetStruct_Overlapped($iOffsetFile)
                    $pOverlapped = DllStructGetPtr($tOverlapped)
                    _WinAPI_WriteFile($hFile, $pBuffer, $iBufferContent, $iByteWritten, $pOverlapped)
                EndIf
            EndIf
        Until $iError = -1
        If $iFileMode Then _WinAPI_CloseHandle($hFile)
        _WinHttpCloseHandle($hWinHttpRequest)
        _WinHttpCloseHandle($hWinHttpConnect)
        _WinHttpCloseHandle($hWinHttpOpen)
        If Not @Compiled Then ConsoleWrite(@CRLF & "> Downloaded " & $aSplit_URL[2] & $aSplit_URL[6] & " in " & Round(TimerDiff($hOptTime) / 1000, 2) & _
                " second(s)" & " at " & _ByteSuffix($iSizeBytes / Int(TimerDiff($hOptTime)) * 1000, -1) & "/s" & @CRLF)
        If Not $iFileMode Then
            Return $vData
        Else
            If FileExists($sFile_Name) Then
                Return $sFile_Name
            Else
                Return False
            EndIf
        EndIf
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_WinHttpGet
Func _GetStruct_Overlapped($iOffset, $hEvent = 0)
    Local $tOffset = DllStructCreate('int64')
    Local $tOffsetSplit = DllStructCreate('dword;dword', DllStructGetPtr($tOffset))
    DllStructSetData($tOffset, 1, $iOffset)

    $tStruct = DllStructCreate($tagOVERLAPPED)
    DllStructSetData($tStruct, "Internal", 0)
    DllStructSetData($tStruct, "InternalHigh", 0)
    DllStructSetData($tStruct, "Offset", DllStructGetData($tOffsetSplit, 1))
    DllStructSetData($tStruct, "OffsetHigh", DllStructGetData($tOffsetSplit, 2))
    DllStructSetData($tStruct, "hEvent", $hEvent)
    Return $tStruct
EndFunc   ;==>_GetStruct_Overlapped
#endregion ### Internal Functions ###

The WinHttp function was downloading AVG from FileHippo @ 110 kb/s thats slow for a 30 meg connection.

Edited by Decipher
Spoiler

censored.jpg

 

Link to comment
Share on other sites

Thanks M8

Very nice Ideas in there!

I'll have to trawl throught the code to see what everything is doing.

It may take a while as I have to work what's been done and why. :)

It's no use me trying to support this without understanding it.

Thanks!

John Morrison

Link to comment
Share on other sites

  • 2 months later...

Good day, i spent some time yesterday making a merged function of the _filehippodownload and the _sourceforgedownload functions by user "storme" and some code written by "Decipher" into one function i now use for my download script, it just returns the download strings to the newest exe on either filehippo or sourceforge file so i can use them with _inetget(therefor the name _Inetgetlink()). i thought i would share it here.

if you guys could give me some pointers to how to improve it it would be sweet, im really a noob when it comes to regexp so any help optimizing things here would be appriciated

one thing i added was firefox as the http engine so that _inetread() in sourceforge returns the windows files instead of the sourcefiles

a big thanks to both storme and decipher for their code

;#RequireAdmin

$DownloadUrl = _INetGetLink("firefox.mirror", "sourceforge")
ConsoleWrite($DownloadUrl)
;InetGet($DownloadUrl, @ScriptDir & "setupfile.exe", 1, 0)
;If @error Then ConsoleWrite("error: " & @error)

Func _INetGetLink($sProgramTitle, $site) ; ref _FileHippoDownload & _SourceForgeDownload by Storme
HttpSetUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1) Gecko/20100101 Firefox/10.0.1')
Local $DownloadUrl, $asDownloadUrl
Local $sCurrentVersion, $asCurrentVersion, $sDownloadSource
Local $sSourcePage, $sFullPath, $sString, $sTrailing

Local $sSourceforge_BaseSite = 'http://sourceforge.net'
Local $sSourceforge_BaseFolder = '/projects/' & $sProgramTitle & '/'
Local $sSourceforge_FullPath = $sSourceforge_BaseSite & $sSourceforge_BaseFolder & 'files/'
Local $sSourceforge_Trailing = '/download/'
Local $sSourceforge_String = '(?s)(?i)title="Download /(.*?)from'
Local $sSourceforge_Dlstring = '(?i)<a href="(.*?)" class='
Local $sSourceforge_Finalstring = ""

Local $sFilehippo_BaseSite = 'http://filehippo.com'
Local $sFilehippo_BaseFolder = '/download_' & $sProgramTitle & '/'
Local $sFilehippo_FullPath = $sFilehippo_BaseSite & $sFilehippo_BaseFolder & 'download/'
Local $sFilehippo_Trailing = "/"
Local $sFilehippo_String = '(?s)(?i)<a href="' & $sFilehippo_BaseFolder & 'download/(.*?)/">'
Local $sFilehippo_Dlstring = '(?s)(?i)url=(.*?)/"/>'
Local $sFilehippo_Finalstring = $sFilehippo_BaseSite
Select
Case StringInStr($site, "sourceforge")
$sSourcePage = $sSourceforge_BaseSite & $sSourceforge_BaseFolder
$sFullPath = $sSourceforge_FullPath
$sTrailing = $sSourceforge_Trailing
$sString = $sSourceforge_String
$sDlstring = $sSourceforge_Dlstring
$sFinalstring = $sSourceforge_Finalstring
Case StringInStr($site, "filehippo")
$sSourcePage = $sFilehippo_BaseSite & $sFilehippo_BaseFolder
$sDownloadSource = $sFilehippo_BaseSite & $sFilehippo_BaseFolder & 'download/'
$sFullPath = $sFilehippo_FullPath
$sTrailing = $sFilehippo_Trailing
$sString = $sFilehippo_String
$sDlstring = $sFilehippo_Dlstring
$sFinalstring = $sFilehippo_Finalstring
Case Else
Return SetError(1, 0, 0)
EndSelect
;Get source for program page
Local $PageSource = _GetSourceCode($sSourcePage)
If Not @error Then
;ConsoleWrite($PageSource)
$asCurrentVersion = StringRegExp($PageSource, $sString, 3)
If Not @error Then
$sCurrentVersion = $asCurrentVersion[0]
$DownloadUrl = $sFullPath & StringStripWS($sCurrentVersion, 2) & $sTrailing
$source = _GetSourceCode($DownloadUrl)
$test = StringRegExp($source, $sDlstring, 3)
If Not @error Then
For $i = 0 To UBound($test) - 1
If StringInStr($test[$i], "download") Then $DownloadUrl = $test[$i]
$DownloadUrl = $sFinalstring & $DownloadUrl & "/"
Next
EndIf
EndIf
EndIf
HttpSetUserAgent('autoit')
Return ($DownloadUrl)
EndFunc ;==>_SourceforgeDownload


Func _GetSourceCode($_Url)
Local $_InetRead = InetRead($_Url)
If Not @error Then
Local $_BinaryToString = BinaryToString($_InetRead)
If Not @error Then Return $_BinaryToString
EndIf
EndFunc ;==>_GetSourceCode
Edited by landetls
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...