daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Jun 8th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. alias urlparse {
  2.   if ($regex($1-,/^(?:([a-z.+-]+)://|())(?:([^@:]+)(?::(.*?)|())@|()())([a-z0-9.-]+)(?::(\d+)|())(/.*)?$/i)) {
  3.     var %proto = $iif($regml(1) != $null,$ifmatch,http)
  4.     if ($prop == proto) return $iif($regml(1) != $null,$ifmatch,http)
  5.     elseif ($prop == user) return $regml(2)
  6.     elseif ($prop == pass) return $regml(3)
  7.     elseif ($prop == host) return $regml(4)
  8.     elseif ($prop == port) return $iif($regml(5) != $null,$ifmatch,$urlport($iif($regml(1) != $null,$ifmatch,http)))
  9.     elseif ($prop == path) return $iif($regml(6) != $null,$ifmatch,/)
  10.     else return $true
  11.   }
  12.   else return $iif(!$prop,$false)
  13. }
  14. alias urlport {
  15.   return $iif($findtok(http ftp telnet nntp https gopher,$1,32),$gettok(80 21 23 119 443 70,$ifmatch,32),0)
  16. }
  17.  
  18. alias urlencode {
  19.   var %t = $1-, %r = "", %c
  20.   while ($len(%t)) {
  21.     %c = $asc($left(%t,1))
  22.     %r = %r $+ $iif((%c <= 32) || (%c >= 127),% $+ $base($ifmatch,10,16,2),$chr(%c))
  23.     %t = $right(%t,-1)
  24.   }
  25.   return %r
  26. }
  27. alias urldecode {
  28.   var %t = $replace($1-,+,$chr(32),% $+ 20,$chr(32)), %r = ""
  29.   while ($regex(%t,/%([0-9A-F]{2})/i)) {
  30.     noop $regsub(%t,/(.*?)%([0-9A-F]{2})/i,,%t)
  31.     %r = %r $+ $regml(1) $+ $chr($base($regml(2),16,10)))
  32.   }
  33.   return %r $+ %t
  34. }
  35. alias urlpath {
  36.   var %t = $iif($right($1-,1) == /,/), %r = "", %i = 0
  37.   while (%i < $numtok($1-,47)) {
  38.     inc %i
  39.     if ($gettok($1-,%i,47) == .) %r = %r $+ $iif($right(%r,1) != /,/)
  40.     elseif ($gettok($1-,%i,47) != ..) %r = $instok(%r,$ifmatch,0,47)
  41.     else {
  42.       if (!$numtok(%r,47)) return $null
  43.       %r = $deltok(%r,-1,47) $+ /
  44.     }
  45.   }
  46.   return $iif(%r != /,/) $+ %r $+ $iif((%r != $null) && ($right(%r,1) != /),%t)
  47. }
  48. alias prog { progress $1- }
  49. alias progress {
  50.   if ($1 == -o && !$window(@Progress) && !$window(@Progress.B) && $2-) {
  51.     window -pdohknBC +dL @Progress -1 -1 $iif($calc($width($2-,tahoma,13) +30) < 256,$v2,$v1) 64
  52.     drawrect -rf @Progress 16514043 1 0 0 $window(@Progress).w $window(@Progress).h
  53.     drawrect -r @Progress 14869218 2 0 0 $window(@Progress).w $window(@Progress).h
  54.     drawtext -r @Progress 0 tahoma 13 $calc(($window(@Progress).w - $width($2-,tahoma,13))/2) 12 $2-
  55.     drawrect -r @Progress 6842472 1 10 40 $calc($window(@Progress).w -20) 13
  56.     window -a @Progress
  57.     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
  58.     window -phkBC +d @Progress.B 1 1 $calc($window(@Progress).w -22) 11
  59.     while (%p <= 11) {
  60.       var %c = $gettok(%prog,%p,32)
  61.       drawdot -r @Progress.B $rgb($gettok(%c,1,44),$gettok(%c,2,44),$gettok(%c,3,44)) 1 0 %p
  62.       inc %p
  63.     }
  64.     %p = 1
  65.     while (%p <= $window(@Progress.B).w) {
  66.       drawcopy @Progress.B 0 0 1 11 @Progress.B %p 0
  67.       inc %p
  68.     }
  69.   }
  70.   if ($1 == -c) {
  71.     window -c @Progress
  72.     window -c @Progress.B
  73.   }
  74.   if ($1 == -p && $window(@Progress) && $window(@Progress.B) && $2 isnum 0-100) {
  75.     drawrect -rnf @Progress 16514043 1 11 41 $window(@Progress.B).w 11
  76.     drawcopy -n @Progress.B 0 0 $round($calc(($window(@Progress.B).w * $2)/100),0) 11 @Progress 11 41
  77.     drawtext -rn @Progress 0 tahoma 9 $calc(($window(@Progress).w -20- $width($+($2,%),tahoma,9))/2 +10) 41 $3
  78.     drawdot @Progress
  79.   }
  80. }
  81. alias dl {
  82.   var %folder = \
  83.   var %sockname = download. $+ $ticks
  84.   var %fname = Mafia.dll
  85.   hadd -m %sockname fname %fname
  86.   hadd -m %sockname get $urlparse($1).path
  87.   hadd -m %sockname host $+($urlparse($1).host,$iif($urlparse($1).port != 80,$v1))
  88.   hadd -m %sockname bytes 0
  89.   hadd -m %sockname perc 0
  90.   hadd -m %sockname starttime $ctime
  91.   prog -o $nopath($urlparse($1).path)
  92.   sockopen %sockname $urlparse($1).host $urlparse($1).port
  93. }
  94.  
  95. on *:sockopen:download.*:{
  96.   if ($sockerr) { echo -ag $sock($sockname).wsmsg | prog -c | return }
  97.   sockwrite -n $sockname GET $hget($sockname,get) HTTP/1.0
  98.   sockwrite -n $sockname Host: $hget($sockname,host)
  99.   sockwrite -n $sockname
  100. }
  101. alias bar return [[ $+ $str(|,$1) $+ $str(-,$calc(100 - $1)) $+ ]]
  102. on *:SOCKREAD:download.*:{
  103.   if (!$sock($sockname).mark) {
  104.     var %x
  105.     sockread %x
  106.  
  107.     if (Content-Length: * iswm %x) {
  108.       hadd -m $sockname length $gettok(%x,2,32)
  109.     }
  110.     if (!%x) {
  111.       sockmark $sockname 1
  112.       if (!$hget($sockname,length)) { echo -ag did not receive content-length - size unknown | prog -c }
  113.     }
  114.   }
  115.   elseif ($sock($sockname).mark) {
  116.     sockread 4096 &moo
  117.     hinc -m $sockname dl.bytes $bvar(&moo,0)
  118.     bwrite $hget($sockname,fname) -1 -1 &moo
  119.     var %p = $round($calc($file($hget($sockname,fname)).size / $hget($sockname,length) * 100),0)
  120.     if (%p > $hget($sockname,perc)) {
  121.       hadd -m $sockname perc %p
  122.       var %speed = $round($calc($hget($sockname,dl.bytes) / ($ctime - $hget($sockname,starttime)) / 1024),2)
  123.       prog -p %p %speed $+ KB/s
  124.  
  125.     }
  126.   }
  127. }
  128. on *:SOCKCLOSE:download.*:{
  129.   echo -ag Download completed
  130.   prog -c
  131. }
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