alias download {
if ($isid) || (!$2) {
if ($show) { echo -s $+(,$colour(info),*) /download $+ : correct format is /download <url> <directory> }
return
}
elseif (!$isdir($+(",$remove($2-,"),"))) {
if ($input($+(",$remove($2-,"),") directory does not exist $+ $chr(44) do you want to create it?,ohd,error) == $true) { mkdir $+(",$remove($2-,"),") }
}
hadd -m $remove($gettok($$1,1,47),http://,www.) path $$2-
tokenize 47 $remove($$1,http://,www.)
if ($isfile($+(",$hget($1,path),$ [ $+ [ $0 ] ],"))) && ($input($ [ $+ [ $0 ] ] exists $+ $chr(44) overwrite?,owd,exists) != $true) { return }
elseif ($isfile($+(",$remove($ [ $+ [ $0 ] ],"),"))) { .remove $+(",$remove($ [ $+ [ $0 ] ],"),") }
hadd -m $1 url $1
hadd -m $1 file $iif($left($ [ $+ [ $0 ] ],1) != /,/) $+ $ [ $+ [ $0 ] ]
sockopen download. [ $+ [ $1 ] ] $1 80
}
on *:sockopen:download.*:{
if ($sockerr) { return }
tokenize 46 $sockname
sockwrite -n $sockname GET $hget($replace($2-,$chr(32),$chr(46)),file) HTTP/1.1
sockwrite -n $sockname Accept: */*
sockwrite -n $sockname Host: www. [ $+ [ $replace($2-,$chr(32),$chr(46)) ] ]
sockwrite -n $sockname $crlf
}
on *:sockread:download.*:{
if ($sockerr) { return }
tokenize 46 $sockname
sockread -f &file
bwrite $+(",$iif($right($hget($replace($2-,$chr(32),$chr(46)),path),1) == \,$hget($replace($2-,$chr(32),$chr(46)),path),$hget($replace($2-,$chr(32),$chr(46)),path) $+ \),dlfile. [ $+ [ $right($hget($replace($2-,$chr(32),$chr(46)),file),-1) $+ .dat ] ],") -1 -1 &file
}
on *:sockclose:download.*:{
tokenize 46 $sockname
echo -a $right($hget($replace($2-,$chr(32),$chr(46)),file),-1) finished downloading.
.rename $+(",$iif($right($hget($replace($2-,$chr(32),$chr(46)),path),1) == \,$hget($replace($2-,$chr(32),$chr(46)),path),$hget($replace($2-,$chr(32),$chr(46)),path) $+ \),dlfile. [ $+ [ $right($hget($replace($2-,$chr(32),$chr(46)),file),-1) $+ .dat ] ],") $+(",$iif($right($hget($replace($2-,$chr(32),$chr(46)),path),1) == \,$hget($replace($2-,$chr(32),$chr(46)),path),$hget($replace($2-,$chr(32),$chr(46)),path) $+ \),$right($hget($replace($2-,$chr(32),$chr(46)),file),-1),")
if (!$isfile($+(",$hget($replace($2-,$chr(32),$chr(46)),path),$right($hget($replace($2-,$chr(32),$chr(46)),file),-1),"))) { echo -s $+(,$colour(info),*) /download: there was an error in the download. }
elseif (!$file($+(",$hget($replace($2-,$chr(32),$chr(46)),path),$right($hget($replace($2-,$chr(32),$chr(46)),file),-1),")).size) {
echo -s $+(,$colour(info),*) /download: there was an error in the download.
.remove $+(",$hget($replace($2-,$chr(32),$chr(46)),path),$right($hget($replace($2-,$chr(32),$chr(46)),file),-1),")
}
.hfree $replace($2-,$chr(32),$chr(46))
}