Snippets Project Page
Author: entropy
Added: 4y
Updated: 3y
mIRC: 7.52+
Hits: 1,240
Downloads: 22
Review: westor
Size: 3.93KB
1 0
Login to vote.
Get File
v1.2
Downloads a file from the internet. Works with just about all formats.
Example:
/getfile -re "C:\mIRC\img.jpg" http://site.here/img.jpg
Downloads internet image img.jpg to the local mIRC directory.
Switches:
"r" switch - Run the download on completion
"e" switch - Echo to the active window socket details
Both switches are optional
Download
JSON
▲ Review
▲ Log
▼ Source
; Get File v1.2 - by entropy 2020 ;================================================================================== EXAMPLE ; Example: /getfile [-re] <"path\file.ext"> <site link> ; ================================================================================= ; Example: /getfile -re "C:\mIRC\img.jpg" http://site.here/img.jpg ; ================================================================================= ; "r" switch - Run the download on completion ; "e" switch - Echo to the active window socket details ; Both switches are optional ;================================================================================== ALIASES alias getfile { if (-re == $1 || -er == $1) { %_run = yes | %_echo = yes | tokenize 32 $2- } if (-r == $1) { %_run = yes | tokenize 32 $2- } if (-e == $1) { %_echo = yes | tokenize 32 $2- } if (!$1) { echo $color(info) -ta * [FILE] No local directory specified! | return } if (!$2) { echo $color(info) -ta * [FILE] No site specified! | return } if (" !isin $1-) { echo $color(info) -ta * [FILE] No Quotes present in local download directory! | return } var %a = $gettok($1-,-1,32) if (www.* !iswm %a && https://* !iswm %a && http://* !iswm %a) { echo $color(info) -ta * [FILE] No valid website specified! | return } %_site = $gettok($1-,-1,32) %_file = $qt($remove($1-,%_site,")) %_host = $gettok($remove(%_site,https://,https://,www.),1,47) var %a = $nofile(%_file) if (!$isdir(%a) && %a) { mkdir %a } if ($isfile(%_file)) { .remove %_file } write -c %_file sockclose file if (https://* iswm %_site) { sockopen -e file %_host 443 } else { sockopen file %_host 80 } if (%_echo == yes) { %_start = $ctime | echo $color(info) -tag * [FILE] Opening socket... } } alias -l unsetit { unset %_site %_file %_host %_run %_echo %_start %_content } alias -l enddownload { if (%_echo == yes) { echo $color(info) -tag * [FILE] $nopath($remove(%_file,")) file download complete... ( $+ $remove($bytes($file(%_file).size).suf,$chr(32)) $+ , $remove($replace($duration($calc($ctime - %_start)),wks,w,wk,w,days,d,day,d,hrs,h,hr,h,mins,m,min,m,secs,s,sec,s),$chr(32)) elapsed) } if (%_content == text/plain) { var %a = $read(%_file,0) if (%a isalnum || %a isnum) { write -dl0 %_file } var %a = $read(%_file,1) if (%a isalnum || %a isnum) { write -dl1 %_file } var %a = $read(%_file,$calc($lines(%_file) - 1)) if (%a == 0) { write $+(-dl,$readn) %_file } var %a = $read(%_file,$lines(%_file)) if (%a == $null) { write $+(-dl,$lines(%_file)) %_file } } if (%_run == yes) { run %_file } unsetit } ;================================================================================== SOCKET EVENTS on *:sockopen:file:{ if ($sockerr) { if (%_echo == yes) { echo $color(info) -tag * [FILE] Socket open errors... } | unsetit | return } if (%_echo == yes) { echo $color(info) -tag * [FILE] Reading socket... } sockwrite -n file GET %_site HTTP/1.1 sockwrite -n file Host: %_host sockwrite -n file User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0 sockwrite -n file $str($crlf,2) } on *:sockread:file:{ if ($sockerr) { if (%_echo == yes) { echo $color(info) -tag * [FILE] Socket read errors... } | unsetit | return } elseif (!$sock($sockname).mark) { var %read | sockread %read | if (Content-Type: * iswm %read) { %_content = $remove($gettok(%read,2,32),;,") } | if (%read == $null) { sockmark $sockname 1 } } else { sockread &image | if (%_file) { bwrite $qt(%_file) -1 -1 &image } | .timerechoget -o 1 1 enddownload } } ;================================================================================== EOF
Changelog:
v1.2 - 7/18/20
- Removed: "46" from sockopen
v1.1 - 5/23/20
- Added support for spaces in filenames.
v1.2 - 7/18/20
- Removed: "46" from sockopen
v1.1 - 5/23/20
- Added support for spaces in filenames.
Comments (2)
Feb 12th, 2020 - By: westor
Admin
Some comments about the 1.0 release:
/sockopen -e46 , the -46 is not need there.
$gettok($1,1--2,92 , you can use $gettok($1,1-2,92)
.remove $1 , you have to use $qt() like .remove $qt($1) , also if path have spaces it will not work.
in every write -dlN %variable you need to use $qt() there to like write -dl0 $qt(%_file)
run %_file , you have to use $qt() there too, like run $qt(%_file)
in bwrite %_file ... , you have to use $qt() there too, like bwrite $qt(%_file) ....
/sockopen -e46 , the -46 is not need there.
$gettok($1,1--2,92 , you can use $gettok($1,1-2,92)
.remove $1 , you have to use $qt() like .remove $qt($1) , also if path have spaces it will not work.
in every write -dlN %variable you need to use $qt() there to like write -dl0 $qt(%_file)
run %_file , you have to use $qt() there too, like run $qt(%_file)
in bwrite %_file ... , you have to use $qt() there too, like bwrite $qt(%_file) ....
Reply:
Feb 12th, 2020 - By: westor
Admin
Also it would be good if you could add more examples and a better alias description of what is the purpose so the new users will understand better
Reply: