SHARE
TWEET

Untitled

a guest May 31st, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. urlparse stuf by Saturn @ QuakeNet
  3. */
  4. alias urlparse {
  5.   if ($regex($1-,/^(?:([a-z.+-]+)://|())(?:([^@:]+)(?::(.*?)|())@|()())([a-z0-9.-]+)(?::(\d+)|())(/.*)?$/i)) {
  6.     var %proto = $iif($regml(1) != $null,$ifmatch,http)
  7.     if ($prop == proto) return $iif($regml(1) != $null,$ifmatch,http)
  8.     elseif ($prop == user) return $regml(2)
  9.     elseif ($prop == pass) return $regml(3)
  10.     elseif ($prop == host) return $regml(4)
  11.     elseif ($prop == port) return $iif($regml(5) != $null,$ifmatch,$urlport($iif($regml(1) != $null,$ifmatch,http)))
  12.     elseif ($prop == path) return $iif($regml(6) != $null,$ifmatch,/)
  13.     else return $true
  14.   }
  15.   else return $iif(!$prop,$false)
  16. }
  17.  
  18. alias urlport {
  19.   return $iif($findtok(http ftp telnet nntp https gopher,$1,32),$gettok(80 21 23 119 443 70,$ifmatch,32),0)
  20. }
  21.  
  22. alias urlencode {
  23.   var %t = $1-, %r = "", %c
  24.   while ($len(%t)) {
  25.     %c = $asc($left(%t,1))
  26.     %r = %r $+ $iif((%c <= 32) || (%c >= 127),% $+ $base($ifmatch,10,16,2),$chr(%c))
  27.     %t = $right(%t,-1)
  28.   }
  29.   return %r
  30. }
  31.  
  32. alias urldecode {
  33.   var %t = $replace($1-,+,$chr(32),% $+ 20,$chr(32)), %r = ""
  34.   while ($regex(%t,/%([0-9A-F]{2})/i)) {
  35.     noop $regsub(%t,/(.*?)%([0-9A-F]{2})/i,,%t)
  36.     %r = %r $+ $regml(1) $+ $chr($base($regml(2),16,10)))
  37.   }
  38.   return %r $+ %t
  39. }
  40.  
  41. alias urlpath {
  42.   var %t = $iif($right($1-,1) == /,/), %r = "", %i = 0
  43.   while (%i < $numtok($1-,47)) {
  44.     inc %i
  45.     if ($gettok($1-,%i,47) == .) %r = %r $+ $iif($right(%r,1) != /,/)
  46.     elseif ($gettok($1-,%i,47) != ..) %r = $instok(%r,$ifmatch,0,47)
  47.     else {
  48.       if (!$numtok(%r,47)) return $null
  49.       %r = $deltok(%r,-1,47) $+ /
  50.     }
  51.   }
  52.   return $iif(%r != /,/) $+ %r $+ $iif((%r != $null) && ($right(%r,1) != /),%t)
  53. }
  54. /*
  55. progress bar by Suchorski @ mircscripts.org
  56. */
  57. alias prog { progress $1- }
  58. alias progress {
  59.   if ($1 == -o && !$window(@Progress) && !$window(@Progress.B) && $2-) {
  60.     window -pdohknBC +dL @Progress -1 -1 $iif($calc($width($2-,tahoma,13) +30) < 256,$v2,$v1) 64
  61.     drawrect -rf @Progress 16514043 1 0 0 $window(@Progress).w $window(@Progress).h
  62.     drawrect -r @Progress 14869218 2 0 0 $window(@Progress).w $window(@Progress).h
  63.     drawtext -r @Progress 0 tahoma 13 $calc(($window(@Progress).w - $width($2-,tahoma,13))/2) 12 $2-
  64.     drawrect -r @Progress 6842472 1 10 40 $calc($window(@Progress).w -20) 13
  65.     window -a @Progress
  66.     var %prog = 164,202,255 149,183,231 142,178,228 133,170,223 124,164,220 117,158,214 20,125,251 25,136,243 36,150,238 50,170,238 91,228,255,%p = 1
  67.     window -phkBC +d @Progress.B 1 1 $calc($window(@Progress).w -22) 11
  68.     while (%p <= 11) {
  69.       var %c = $gettok(%prog,%p,32)
  70.       drawdot -r @Progress.B $rgb($gettok(%c,1,44),$gettok(%c,2,44),$gettok(%c,3,44)) 1 0 %p
  71.       inc %p
  72.     }
  73.     %p = 1
  74.     while (%p <= $window(@Progress.B).w) {
  75.       drawcopy @Progress.B 0 0 1 11 @Progress.B %p 0
  76.       inc %p
  77.     }
  78.   }
  79.   if ($1 == -c) {
  80.     window -c @Progress
  81.     window -c @Progress.B
  82.   }
  83.   if ($1 == -p && $window(@Progress) && $window(@Progress.B) && $2 isnum 0-100) {
  84.     drawrect -rnf @Progress 16514043 1 11 41 $window(@Progress.B).w 11
  85.     drawcopy -n @Progress.B 0 0 $round($calc(($window(@Progress.B).w * $2)/100),0) 11 @Progress 11 41
  86.     drawtext -rn @Progress 0 tahoma 9 $calc(($window(@Progress).w -20- $width($+($2,%),tahoma,9))/2 +10) 41 $3
  87.     drawdot @Progress
  88.   }
  89. }
  90.  
  91. /*
  92. MY CODE LULZ
  93. */
  94. alias dl {
  95.   if (!$isdir(downloads)) { mkdir downloads }
  96.   var %folder = downloads\ $+ $asctime(dd.mm.yyyy) $+ \
  97.   if (!$isdir(%folder)) { mkdir %folder }
  98.   var %sockname = download. $+ $ticks
  99.   var %fname = %folder $+ %sockname $+ $nopath($urlparse($1).path)
  100.   hadd -m %sockname fname %fname
  101.   hadd -m %sockname get $urlparse($1).path
  102.   hadd -m %sockname host $+($urlparse($1).host,$iif($urlparse($1).port != 80,$v1))
  103.   hadd -m %sockname bytes 0
  104.   hadd -m %sockname perc 0
  105.   hadd -m %sockname starttime $ctime
  106.   prog -o $nopath($urlparse($1).path)
  107.  
  108.   sockopen %sockname $urlparse($1).host $urlparse($1).port
  109.  
  110. }
  111.  
  112. on *:sockopen:download.*:{
  113.   if ($sockerr) { echo -ag $sock($sockname).wsmsg | prog -c | return }
  114.   sockwrite -n $sockname GET $hget($sockname,get) HTTP/1.0
  115.   sockwrite -n $sockname Host: $hget($sockname,host)
  116.   sockwrite -n $sockname
  117. }
  118. alias bar return [[ $+ $str(|,$1) $+ $str(-,$calc(100 - $1)) $+ ]]
  119. on *:SOCKREAD:download.*:{
  120.   if (!$sock($sockname).mark) {
  121.     var %x
  122.     sockread %x
  123.  
  124.     if (Content-Length: * iswm %x) {
  125.       hadd -m $sockname length $gettok(%x,2,32)
  126.     }
  127.     if (!%x) {
  128.       sockmark $sockname 1
  129.       if (!$hget($sockname,length)) { echo -ag did not receive content-length - size unknown | prog -c }
  130.     }
  131.   }
  132.   elseif ($sock($sockname).mark) {
  133.     sockread 4096 &moo
  134.     hinc -m $sockname dl.bytes $bvar(&moo,0)
  135.     bwrite $hget($sockname,fname) -1 -1 &moo
  136.     var %p = $round($calc($file($hget($sockname,fname)).size / $hget($sockname,length) * 100),0)
  137.     if (%p > $hget($sockname,perc)) {
  138.       hadd -m $sockname perc %p
  139.       var %speed = $round($calc($hget($sockname,dl.bytes) / ($ctime - $hget($sockname,starttime)) / 1024),2)
  140.       prog -p %p %speed $+ KB/s
  141.  
  142.     }
  143.   }
  144. }
  145.  
  146. on *:SOCKCLOSE:download.*:{
  147.   echo -ag download completed
  148.   prog -c
  149.   run downloads\ $+ $asctime(dd.mm.yyyy)
  150. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top