Jump to content

filename from inetget


pcjunki
 Share

Recommended Posts

I'm making a gui downloader, and I'm using inetget to get the download.

how do I just download the file without knowing the file name of the download?

here is what I have below, but I do not want to have to type in "filename" every time, I just want to put in the link, and click download and it downloads the file to my desktop

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate(@ScriptName, 429, 181, 418, 372)

$Label1 = GUICtrlCreateLabel("URL", 8, 8, 20, 17)
$Input1 = GUICtrlCreateInput("", 8, 24, 409, 21)


$Label2 = GUICtrlCreateLabel("filename", 8, 64, 43, 17)
$Input2 = GUICtrlCreateInput("", 8, 88, 121, 21)

$Button1 = GUICtrlCreateButton("download to desktop", 8, 144, 115, 25)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            Call($Input1, $Input2)

            $url = GUICtrlRead($Input1)
            $filename = GUICtrlRead($Input2)

            InetGet($url, @DesktopDir & "/" & $filename)



    EndSwitch
WEnd
Link to comment
Share on other sites

Try this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate(@ScriptName, 429, 181, 418, 372)

$Label1 = GUICtrlCreateLabel("URL", 8, 8, 20, 17)
$Input1 = GUICtrlCreateInput("", 8, 24, 409, 21)
$hInput1 = GUICtrlGetHandle($Input1)

$Label2 = GUICtrlCreateLabel("filename", 8, 64, 43, 17)
$Input2 = GUICtrlCreateInput("", 8, 88, 121, 21)

$Button1 = GUICtrlCreateButton("download to desktop", 8, 144, 115, 25)

GUISetState(@SW_SHOW)


GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            Call($Input1, $Input2)

            $url = GUICtrlRead($Input1)
            $filename = GUICtrlRead($Input2)

            InetGet($url, @DesktopDir & "/" & $filename)



    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam

    Switch $lParam
        Case $hInput1
            GUICtrlSetData($Input2, StringRegExpReplace(GUICtrlRead($Input1), ".+\/(.*)", "$1"))
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

that didn't work, I tried to download this link

http://downloads.sourceforge.net/portableapps/DamnVidPortable_1.6.0.paf.exe?accel_key=69%3A1424986570%3Ahttp%253A//portableapps.com/apps/internet/damnvid_portable%3A3917e93e%247c08e29f291f12d06773b77efb62b0eb26a8f278&click_id=7b24d6b8-bdff-11e4-9ed6-0200ac1d1d92&source=accel

and it created a file on my desktop called,

damnvid_portable%3A3917e93e%247c08e29f291f12d06773b77efb62b0eb26a8f278&click_id=7b24d6b8-bdff-11e4-9ed6-0200ac1d1d92&source=accel

 

edit:

btw, thanks for the quick response, I kinda understand what your saying, but clueless...this is a little more advanced for me :)

Edited by pcjunki
Link to comment
Share on other sites

Well, the regex needs to be adjusted to grab only the filename from an URL in general - not only for this particual example!

Maybe mikell or Malkey can jump in and provide a regex pattern.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

what's interesting is there are actually 3 links all together.

from this first link

if I do this, it works

InetGet("http://downloads.sourceforge.net/portableapps/DamnVidPortable_1.6.0.paf.exe?accel_key=69%3A1424986570%3Ahttp%253A//portableapps.com/apps/internet/damnvid_portable%3A3917e93e%247c08e29f291f12d06773b77efb62b0eb26a8f278&click_id=7b24d6b8-bdff-11e4-9ed6-0200ac1d1d92&source=accel", @DesktopDir & "/file.exe")

the previous link if you click on it goes to here (the sourceforge.net page)

and if I do this, it works

InetGet("http://sourceforge.net/projects/portableapps/files/DamnVid_Portable/DamnVid%20Portable%201.6/DamnVidPortable_1.6.0.paf.exe/download?use_mirror=hivelocity&click_id=7b24d6b8-bdff-11e4-9ed6-0200ac1d1d92&source=accel&accel_key=69%3A1424986570%3Ahttp%253A%2F%2Fportableapps.com%2Fapps%2Finternet%2Fdamnvid_portable%3A3917e93e%247c08e29f291f12d06773b77efb62b0eb26a8f278", @DesktopDir & "/file.exe")

and of course, the direct download link

and if I do this, it works

InetGet("http://downloads.sourceforge.net/project/portableapps/DamnVid_Portable/DamnVid%20Portable%201.6/DamnVidPortable_1.6.0.paf.exe?r=&ts=1424988355&use_mirror=hivelocity", @DesktopDir & "/file.exe")
Link to comment
Share on other sites

This will probably work for your particular example

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam

    Switch $lParam
        Case $hInput1
            GUICtrlSetData($Input2, StringRegExpReplace(GUICtrlRead($Input1), "http.+\/(.+\.exe).*", "$1"))
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

but as mentioned it is only for *.exe filenames. I don't know yet how to make a regex for generic filenames.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

this doesnt work on the middle link, but does on the original and the direct

;~ $sString = "http://downloads.sourceforge.net/project/portableapps/DamnVid_Portable/DamnVid%20Portable%201.6/DamnVidPortable_1.6.0.paf.exe?r=&ts=1424988355&use_mirror=hivelocity"
$sString = "http://downloads.sourceforge.net/portableapps/DamnVidPortable_1.6.0.paf.exe?accel_key=69%3A1424986570%3Ahttp%253A//portableapps.com/apps/internet/damnvid_portable%3A3917e93e%247c08e29f291f12d06773b77efb62b0eb26a8f278&click_id=7b24d6b8-bdff-11e4-9ed6-0200ac1d1d92&source=accel"

$aString = stringregExp(StringReverse($sString) , "\?(.*?)\/" ,3)

msgbox(0, '' , stringreverse($aString[0]))

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Here is one RE pattern that works,

Local $aString[3] = _
        ["http://downloads.sourceforge.net/portableapps/DamnVidPortable_1.6.0.paf.exe?accel_key=69%3A1424986570%3Ahttp%253A//portableapps.com/apps/internet/damnvid_portable%3A3917e93e%247c08e29f291f12d06773b77efb62b0eb26a8f278&click_id=7b24d6b8-bdff-11e4-9ed6-0200ac1d1d92&source=accel", _
        "http://sourceforge.net/projects/portableapps/files/DamnVid_Portable/DamnVid%20Portable%201.6/DamnVidPortable_1.6.0.paf.exe/download?use_mirror=hivelocity&click_id=7b24d6b8-bdff-11e4-9ed6-0200ac1d1d92&source=accel&accel_key=69%3A1424986570%3Ahttp%253A%2F%2Fportableapps.com%2Fapps%2Finternet%2Fdamnvid_portable%3A3917e93e%247c08e29f291f12d06773b77efb62b0eb26a8f278", _
        "http://downloads.sourceforge.net/project/portableapps/DamnVid_Portable/DamnVid%20Portable%201.6/DamnVidPortable_1.6.0.paf.exe?r=&ts=1424988355&use_mirror=hivelocity"]

For $i = 0 To UBound($aString) - 1
    ; "(?i)^.*?([^/]+\.exe).*$" - Capture only the sequence of characters," (...)",  that are not a backslash,"[^/]+", and end with ".exe",
    ;   and, disregard all other characters before, "^.*?", and after, ".*$".     "(?i)" allows capture of "exe" in upper or lower case.
    ConsoleWrite('$aString[' & $i & '] converted to "' & StringRegExpReplace($aString[$i], "(?i)^.*?([^/]+\.exe).*$", "$1") & '"' & @LF)
Next

#cs  Returns:-
$aString[0] converted to "DamnVidPortable_1.6.0.paf.exe"
$aString[1] converted to "DamnVidPortable_1.6.0.paf.exe"
$aString[2] converted to "DamnVidPortable_1.6.0.paf.exe"
#ce
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...