/download

Platform:  mIRC
Published  Feb 01, 2012
Updated  Feb 02, 2012
About:
I wrote this to make downloading files easier on myself and thought I'd share it.

To Load:
Copy into a fresh mIRC remotes file

To Use:
/download [callback alias] [url] [path\file]

[callback alias] - The alias to be called when the file is finished downloading.
if it has multiple parameters surround it in double quotes: "echo -a"
The callback alias gets called with:
[0|1] [MSG] [URL] [FILEPATH]
Where:
[0|1] - 1 if success, 0 if download failed
[MSG] - "S_OK" if successful, or the error message of why the download failed
[URL] - The url that was to be downloaded
[FILEPATH] - the file the data was to be wrote to

[url] - The page/file you wish to download

[path\file] - The file you wish to save to, if no path is specified, $mircdir will be used.
If the filepath contains spaces, place it in double quotes: "c:\some dir\file.txt"


Example:
/download "echo -a" https://www.google.com/search?q=test example.txt alias Download {
if ($regex(Args,$1-,^-c (?|(?:"(?=.+")([^"]+)")|(\S+)) (\S+) (?|(?:"(?=.+")([^"]+)")|(\S+)) (\S+)$)) {
var %callback = $regml(Args,1)
var %url = $regml(Args,2)
var %file = $qt($regml(Args,3))
var %com = $regml(Args,4)
var %r = $iif($comerr,1,$com(%com).result)

.remove $qt($scriptdir $+ %com)
if ($com(%com)) { .comclose %com }

if (%r == -1) { %callback 1 S_OK %url $qt(%file) }
elseif (%r == 1) { %callback 0 UnKnown_ComErr %url $qt(%file) }
elseif (%r == 2) { %callback 0 IE6+_Needed %url $qt(%file) }
elseif (%r == 3) { %callback 0 Connect_Error %url $qt(%file) }
elseif (%r == 4) { %callback 0 Newer_ActiveX_Needed %url $qt(%file) }
elseif (%r == 5) { %callback 0 Writefile_Error %url $qt(%file) }
else { %callback 0 Unknown_Error %url $qt(%file) }
}
elseif ($1 != -c) {
if ($isid) || (!$regex(Args,$1-,^(?|(?:"(?=.+")([^"]+)")|(\S+)) (\S+) (?|(?:"(?=.+")([^"]+)")|(\S+))$)) || ($regml(Args,0) != 3) { return }

var %callback = $regml(Args,1)
var %url = $qt($regml(Args,2))
var %file = $qt($iif(: isin $regml(Args,3),$v2,$mircdir $+ $v2))
var %com = download $+ $ticks $+ .vbs
var %s = $qt($scriptdir $+ %com)
var %w = write %s

%w on error resume next
%w Set C = CreateObject("msxml2.xmlhttp.3.0")
%w if (err.number <> 0) then
%w err.clear
%w set C = CreateObject("msxml2.xmlhttp")
%w if (err.number <> 0) then
%w err.clear
%w set C = CreateObject("XMLHttpRequest")
%w if (err.number <> 0) then wscript.quit(2)
%w end if
%w end if
%w C.open "GET", %url $+ , false
%w C.send
%w if (err.number <> 0) then wscript.quit(3)
%w set O = createobject("adodb.stream")
%w if (err.number <> 0) then wscript.quit(4)
%w O.type=1
%w O.mode=3
%w O.open
%w O.write C.responsebody
%w O.savetofile %file $+ ,2
%w if (err.number <> 0) then wscript.quit(5)
%w O.close
%w wscript.quit(-1)

.comopen %com WScript.Shell
if ($comerr || !$comcall(%com,download -c $qt(%callback) $noqt(%url) %file,run,1,bstr*,%s,uint,1,bool,true)) { goto error }
return
}
:error
if ($error) { reseterror }
if ($isfile(%s)) { .remove %s }
if ($com(%com)) { .comclose %com }
}

Comments

Sign in to comment.
SReject   -  Feb 02, 2012
You're welcome. Just trying to make things easier on myself and others :D
 Respond  
hxck   -  Feb 02, 2012
Works like a charm, thanks. :)
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.