downloads an image and then displays it
/idl [link]
if the file already exists it will open it and wont re-download it
right click in a channel to either download a new pic or open the IDownLoad dir
on *:load:if (!$isdir(IDownLoad)) mkdir IDownLoad
menu Channel,@IDownLoad {
IDownLoad
.Download New Pic:idl $$?="Enter the EXACT link to the image"
.Open IDownLoad Image Directory:run $idir
}
on ^$*:hotlink:/(?:http:\/\/)?(?:www\.)?(.*\.\S{2,3})(\/(.*\.(?:jpe?g|bmp|gif|png)))/Si:*:return
on $*:hotlink:/(?:http:\/\/)?(?:www\.)?(.*\.\S{2,3})(\/(.*\.(?:jpe?g|bmp|gif|png)))/Si:#:idl $1
alias idir return $qt($+($mircdirIDownLoad\,$1))
alias idl {
if ($regex($1,/(?:http:\/\/)?(?:www\.)?(.*\.\S{2,3})(\/(.*\.(?:jpe?g|bmp|gif|png)))/Si)) {
var %loc = $gettok($1,-1,47)
if ($isfile($idir(%loc))) { idl.open $idir(%loc) | halt }
var %a = idownload. $+ $r(1,$ticks)
sockopen %a $regml(1) 80
sockmark %a start
hadd -m %a Site $regml(1)
hadd %a path $regml(2)
hadd %a location $idir(%loc))
}
else echo 10 -a * Invalid Image Link
}
on *:sockopen:idownload.*: {
sockwrite -n $sockname GET $hget($sockname,path) HTTP/1.1
sockwrite -n $sockname HOST: $hget($sockname,site)
sockwrite -n $sockname $crlf
}
on *:sockread:idownload.*: {
var %a
if ($sock($sockname).mark == start) {
while ($sock($sockname).rq) {
sockread %a
if (!%a) { sockmark $sockname read | hadd $sockname Time $ctime | break }
if ($regex(%a,/^Content-Type:\W(.*)) && $regml(1) == text/html) { echo $color(info) -a * Error: Bad/broken file | sockclose $sockname }
elseif ($regex(%a,/^Content-length: (\d*)/i)) hadd $sockname Size $regml(1)
}
}
if ($hget($sockname,Size)) {
var %a = $sockname,%echo = echo $iif($me ison $active,$active,$lactive)
window -aCdk0p @IDL -1 -1 300 60
while ($sock($sockname).rq) {
sockread &idl
bwrite $hget($sockname,location) -1 -1 &idl
clear @IDL
drawtext @IDL 14 5 5 Downloading File: $+($file($hget(%a,location)).size,/,$hget(%a,size),$chr(40),$round($calc($file($hget(%a,location)).size / $hget(%a,size) *100),2),%,$chr(41))
}
if ($file($hget($sockname,location)).size == $hget($sockname,Size)) {
%echo Download Complete!
%echo Download took: $calc($ctime - $hget(%a,time)) Seconds
idl.open $hget(%a,location)
hfree %a
}
}
}
alias idl.open {
if ($window(@IDL)) { clear $v1 | drawtext $v1 14 5 5 Download complete! | window -c $v1 }
var %a = $qt($1-),%b = $calc($pic(%a).width +20),%c = $calc($pic(%a).height +40)
if ($window(@IDownLoad)) window -c @IDownLoad
window -aCdk0p @IDownLoad -1 -1 %b %c
drawpic -o @IDownLoad 0 0 5 %a
}