Shoutbox

How to download - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: How to download (/showthread.php?tid=87388)

How to download by ArkaneArkade on 11-20-2008 at 11:05 PM

Hey all,

Working on a little extra, to automatically download an image from a site.  Probelm is, one of the images inst a png.
- OK, not very good at explaining - the image specifically is http://www.bungie.net/Stats/halo2emblem.ashx?s=70...=26&bi=36&fl=1&m=1

Because its an ashx page (presumably) the downloadfile doesn't seem to work,  Is there a possible method to do it, or is it just impossible?


RE: How to download by SmokingCookie on 11-24-2008 at 07:31 AM

Apparently, downloading from dynamic pages is not possible.

You'll have to save the file manually, host it somewhere else and download it from there.


RE: How to download by ArkaneArkade on 11-24-2008 at 08:42 AM

OK, cheers Smokie.  I'll have to figure something else out for that later on.  May find some other way to steal the image.


RE: How to download by matty on 11-24-2008 at 01:55 PM

The mimetype is image/jpg.

You can use the Win32 API URLDownloadToFile.

Your code would look something like this:

code:
function URLDownloadToFile (sUrl, sFile) {
    Interop.Call('wininet.dll', 'DeleteUrlCacheEntryW', sUrl);
    Interop.Call('urlmon.dll', 'URLDownloadToFileW', 0, sUrl, sFile, 0, Interop.GetInterfacePtr('OnProgress'));
}

function OnProgress (ulProgress, ulProgressMax, ulStatusCode, szStatusText) {
    if (ulProgress == ulProgressMax) Debug.Trace('Download Complete');
}

Now I cannot guarantee that the callback function for this works because Plus! had to handwrite all of the function callbacks and he may have missed this one. If this is the case then you can do this:

code:
function URLDownloadToFile (sUrl, sFile) {
    Interop.Call('wininet.dll', 'DeleteUrlCacheEntryW', sUrl);
    Interop.Call('urlmon.dll', 'URLDownloadToFileW', 0, sUrl, sFile, 0, 0);
}

RE: How to download by ArkaneArkade on 11-25-2008 at 05:25 AM

Cheers matty.  I have that working... at least for the download.  I get object doesnt support method errors, so I guess that the callback was missed.  Shouldn't matter though... I'll just need to figure out some other way to detect it, so that I don't set my image to an incomplete file.
cheers dude


RE: How to download by Spunky on 11-25-2008 at 11:58 AM

quote:
Originally posted by Leroux
I'll just need to figure out some other way to detect it, so that I don't set my image to an incomplete file.

Is it possible to compare file sizes?

or md5 hashes if you really wanna go nuts :p
RE: How to download by matty on 11-25-2008 at 12:35 PM

URLDownloadToFile I do believe is a synchronous call meaning when it returns 0 for success the file is done.


RE: How to download by Matti on 11-25-2008 at 05:46 PM

quote:
Originally posted by matty
URLDownloadToFile I do believe is a synchronous call meaning when it returns 0 for success the file is done.
Unfortunately, it's not.
quote:
Returns one of the following values.
S_OK - The download started successfully.
That means: it returns as soon as its started, from there you're supposed to monitor the progress through the callback function - which we can't do unfortunately.

Ugh, how I hate the lack of asynchronous callback support. :(
RE: How to download by matty on 11-25-2008 at 06:05 PM

quote:
Originally posted by Matti
quote:
Originally posted by matty
URLDownloadToFile I do believe is a synchronous call meaning when it returns 0 for success the file is done.
Unfortunately, it's not.

That means: it returns as soon as its started, from there you're supposed to monitor the progress through the callback function - which we can't do unfortunately.

Ugh, how I hate the lack of asynchronous callback support. :(
Oops I didn't actually read the MSDN article ahaha!

And why didn't MsgPlus.DownloadFile work? It should process the url like any other.