Jump to content

InetGet with unknown file name


Recommended Posts

i want to download the latest version of firefox msi installer using an url like

https://download.mozilla.org/?product=firefox-msi-latest-ssl&os=win64&lang=de

in this case the filename is unknown before download and i also do not want to use a static name like 'firefox-latest' or similar. a web browser is able to read the correct filename before downloading it so maybe autoit is able to do that too so i can set a variable before the actual download starts?

Link to comment
Share on other sites

21 hours ago, LeMa said:

i want to download the latest version of firefox msi installer using an url like

https://download.mozilla.org/?product=firefox-msi-latest-ssl&os=win64&lang=de

in this case the filename is unknown before download and i also do not want to use a static name like 'firefox-latest' or similar

Hmm, you don't want this "latest" expression however it is present everywhere  :huh2:
If you want to know the version number of this latest one you are downloading, just Inetread the page and get it

$s = BinaryToString(InetRead("https://www.mozilla.org/de/firefox/"))
$version = StringRegExpReplace($s, '(?s).*?data-latest-firefox="([^"]+).*', "$1") ; latest
$file = "Firefox Setup " & $version & ".msi"
$url = "https://download-installer.cdn.mozilla.net/pub/firefox/releases/" & $version & "/win64/de/" & $file
InetGet($url, @scriptdir & "\" & $file)

 

Edited by mikell
added some saturday's spoon feeding :)
Link to comment
Share on other sites

thank you. nice solution!

theoretically the filename must come together with the download. if you put an url like

https://download.mozilla.org/?product=firefox-msi-latest-ssl&os=win64&lang=de

into your browser the next thing that happens is that you are asked if/where you want to save a file named

Firefox Setup 68.0.msi

on your computer. thats why i thought this filename (sent by the site as a result of the query string) could be read out somehow.

[for downloading the url

https://ftp.mozilla.org/pub/firefox/releases/68.0/win64/de/

might be a good choice too]

Edited by LeMa
Link to comment
Share on other sites

3 hours ago, LeMa said:

theoretically the filename must come together with the download

Yes it does. The location of the download (which contains the filename) is returned in the response headers of the page, along with the content-type, the file size, etc. To make the script have the same behaviour than the browser there are 2 actions to perform

HTTP/1.1 302 Found
Cache-Control: max-age=60
Content-Length: 127
Content-Type: text/html; charset=utf-8
Date: Mon, 15 Jul 2019 09:51:30 GMT
Location: https://download-installer.cdn.mozilla.net/pub/firefox/releases/68.0/win64/de/Firefox%20Setup%2068.0.msi
Connection: keep-alive

HTTP/1.1 200 OK
Content-Type: application/x-msi
Content-Length: 48466944
Connection: keep-alive
Date: Tue, 09 Jul 2019 16:26:56 GMT
x-amz-replication-status: COMPLETED
Last-Modified: Mon, 08 Jul 2019 13:27:53 GMT
ETag: "fd4c2a033b9deca85348d9c8decf5c02"
Cache-Control: public, max-age=14400
x-amz-version-id: VGqdZQjugXZO5taw1ikbrQz4.wM4VKIQ
Accept-Ranges: bytes
Server: AmazonS3
Via: 1.1 f5f83db1a84a10ea220332d32f95e38b.cloudfront.net (CloudFront), 1.1 c5e8408e2914e204df7d18fc961818b5.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: LHR3-C2
Age: 572
X-Cache: Hit from cloudfront
X-Amz-Cf-Pop: LHR3-C2
X-Amz-Cf-Id: H0BuCrb-rYpPzKDZ2OPkx50D_B4zkEuHSd7e-Ow1CE2oeWeyCnOt2Q==

:)

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...