Jump to content

Get URL Final Download File Name


Recommended Posts

Kindley i need a Code to retrieve file name with extension from this URL :

https://www.internetdownloadmanager.com/getlatestversion.html

as i paste it to browser adress bar it will give me the Real Link to the file as :

https://mirror2.internetdownloadmanager.com/idman639build2.exe?v=lt&filename=idman639build2.exe

So i need the Last  part which is File Name + extension from the First blind Link not the second

Meaning i need a code to read idman639build2.exe from the Link : https://www.internetdownloadmanager.com/getlatestversion.html directly

Thanks in advance

Edited by Sam2022
Link to post
Share on other sites
  • Developers
4 hours ago, Sam2022 said:

Meaning i need a code to read :

Great ...  so what exactly is your AutoIt3 question or is your wish we code the whole thing for you? :) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
1 hour ago, Jos said:

Great ...  so what exactly is your AutoIt3 question or is your wish we code the whole thing for you? :) 

#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Read the file without downloading to a folder. The option of 'get the file from the local cache' has been selected.
    Local $dData = InetRead("https://www.internetdownloadmanager.com/getlatestversion.html")
    ; The number of bytes read is returned using the @extended macro.
    Local $iBytesRead = @extended
    ; Convert the ANSI compatible binary string back into a string.
    Local $sData = BinaryToString($dData)
    
    $IDMGETlink    = StringRegExp($dData    , '(?:http|https)s?[^"\r\n]+(?:exe)',  1  )
    $IDMdownloadURL     = $IDMGETlink    [ 0  ]
    MsgBox($MB_SYSTEMMODAL, "", "The File Name or Link is: " & $IDMdownloadURL)

    ; Display the results.
    MsgBox($MB_SYSTEMMODAL, "", "The number of bytes read: " & $iBytesRead & @CRLF & @CRLF & $sData)
EndFunc   ;==>Example

 

So first Message gives nothing

but second okay

 

i need the first message to read the file name or the final link

Link to post
Share on other sites

Using the command line tool curl it shows you the link you need:

C:\Users\User>curl https://www.internetdownloadmanager.com/getlatestversion.html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://mirror2.internetdownloadmanager.com/idman639build2.exe?v=lt&ampfilename=idman639build2.exe">here</a>.</p>
</body></html>

Perhaps you can use StringRegExp() to extract the link from the output of this command?

(I know there is a cURL UDF, but it does not appear to work with the 64 bit libcurl-x64.dll file)

More info:

 

Edited by Leendert-Jan
Link to post
Share on other sites
23 minutes ago, Leendert-Jan said:

Using the command line tool curl it shows you the link you need

Right  :)

#include <AutoItConstants.au3>

$cmd = "curl -sk " & "https://www.internetdownloadmanager.com/getlatestversion.html"
Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
$file = StringRegExpReplace(StdoutRead($iPID), '(?s).*?filename=([^"]+).*', "$1")
Msgbox(0,"", $file)

Note that curl could be used to eventually dowload the file too

Edited by mikell
Link to post
Share on other sites
16 minutes ago, mikell said:

Right  :)

#include <AutoItConstants.au3>

$cmd = "curl -sk " & "https://www.internetdownloadmanager.com/getlatestversion.html"
Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
$file = StringRegExpReplace(StdoutRead($iPID), '(?s).*?filename=([^"]+).*', "$1")
Msgbox(0,"", $file)

Note that curl could be used to eventually dowload the file too

The meesage gives blank value 

Meaning it returns nothing

Link to post
Share on other sites

For the fun  :)
By checking the download in the Scite console, you could even build a progressbar, a percent progress etc 

#include <AutoItConstants.au3>

$url = "https://www.internetdownloadmanager.com/getlatestversion.html"

; get filename
$cmd = "curl -sk " & $url
Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
$file = StringRegExpReplace(StdoutRead($iPID), '(?s).*?filename=([^"]+).*', "$1")
Msgbox(0,"", $file)

; then download
$cmd = 'curl -Lk ' & $url
SplashTextOn ("", "Downloading ...", 300, 55, -1, 350, 49, "", 12)
Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
Local $out = StdoutRead($iPID)
SplashOff()
$h = Fileopen(@desktopdir & "\" & $file, 18)
Filewrite($h, $out)
Fileclose($h)

 

Link to post
Share on other sites
6 hours ago, mikell said:

For the fun  :)
By checking the download in the Scite console, you could even build a progressbar, a percent progress etc 

#include <AutoItConstants.au3>

$url = "https://www.internetdownloadmanager.com/getlatestversion.html"

; get filename
$cmd = "curl -sk " & $url
Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
$file = StringRegExpReplace(StdoutRead($iPID), '(?s).*?filename=([^"]+).*', "$1")
Msgbox(0,"", $file)

; then download
$cmd = 'curl -Lk ' & $url
SplashTextOn ("", "Downloading ...", 300, 55, -1, 350, 49, "", 12)
Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
Local $out = StdoutRead($iPID)
SplashOff()
$h = Fileopen(@desktopdir & "\" & $file, 18)
Filewrite($h, $out)
Fileclose($h)

 

Thanks Man

vey good and clear

 

Link to post
Share on other sites

You can use @trancexx excellent UDF WinHttp.au3 to receive and send http requests.

Main Steps: Disable Redirects  -- Send request -- Query Location Header 

vmEXVkL.png

#include "WinHttp.au3"

Local $URL = "https://www.internetdownloadmanager.com/getlatestversion.html"

Local $aURL = _WinHttpCrackUrl($URL)
Local $hOpen = _WinHttpOpen()
Local $hConnect = _WinHttpConnect($hOpen, $aURL[2])
Local $hRequest = _WinHttpOpenRequest($hConnect, 'HEAD', $aURL[6], Default, Default, Default)
_WinHttpSetOption($hRequest, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_REDIRECTS)
_WinHttpSendRequest($hRequest)
_WinHttpReceiveResponse($hRequest)
Local $sLocation = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_LOCATION)
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
MsgBox(0, "Location", $sLocation)

 

Link to post
Share on other sites
On 10/16/2021 at 3:35 PM, NewCommer said:

You can use @trancexx excellent UDF WinHttp.au3 to receive and send http requests.

Main Steps: Disable Redirects  -- Send request -- Query Location Header 

vmEXVkL.png

#include "WinHttp.au3"

Local $URL = "https://www.internetdownloadmanager.com/getlatestversion.html"

Local $aURL = _WinHttpCrackUrl($URL)
Local $hOpen = _WinHttpOpen()
Local $hConnect = _WinHttpConnect($hOpen, $aURL[2])
Local $hRequest = _WinHttpOpenRequest($hConnect, 'HEAD', $aURL[6], Default, Default, Default)
_WinHttpSetOption($hRequest, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_REDIRECTS)
_WinHttpSendRequest($hRequest)
_WinHttpReceiveResponse($hRequest)
Local $sLocation = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_LOCATION)
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
MsgBox(0, "Location", $sLocation)

 

Perfect Answer my dear

Excellent and working 100%

Thanks a lot

Accept my respect and best regards

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...