Advertisement
imk0tter

Untitled

Apr 21st, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 11.35 KB | None | 0 0
  1. alias youtube {
  2.   var %sock $Socket(youtube.com,80),%link = $1-
  3.   if (!%link) { var %link = $input(Enter Link,oe,Youtube Downloader) }
  4.   if (%link) && ($urlparse(%link).host == www.youtube.com) && (/watch?v=* iswm $urlparse(%link).path) {
  5.     - $Socket(%sock,%link).settag
  6.     - $Socket(%sock,OnYoutubeOpen).sockopen
  7.     - $Socket(%sock,OnYoutubeClose).sockclose
  8.     - $Socket(%sock,OnYoutubeRead).sockread
  9.     - $Socket(%sock).connect
  10.   }
  11.   else { echo -a Youtube Downloader: Invalid Link, Syntax: /youtube http://www.youtube.com/watch?v=Code  }
  12. }
  13. alias onYoutubeOpen {
  14.   var %sw = sockwrite -n $sockname, %mark = $Socket($1).tag
  15.   if (!$regex(%mark,/v=(.+)$/) || $sockerr) { echo -a Youtube Downloader: Connection Failed }
  16.   var %code = $regml(1)
  17.  
  18.   %sw GET $urlparse(%mark).path HTTP/1.1
  19.   %sw Host: www.youtube.com
  20.   %sw Connection: Close
  21.   %sw
  22.   - $Class($1,file,%code $+ .tmp).setv
  23. }
  24. alias onYoutubeRead {
  25.   sockread -f &d
  26.   bwrite $Class($1,file).getv -1 -1 &d
  27. }
  28. alias onYoutubeClose {
  29.   bread $Class($1,file).getv 1 $file($Class($1,file).getv).size &d
  30.   var %1 = $bfind(&d,1,fmt_url_map=), %2 = $bfind(&d,%1,&)
  31.   var %url = $bvar(&d,%1 - %2).text
  32.   var %url = $urldecode(%url)
  33.   var %url = $gettok($gettok(%url,2,124),1,44)
  34.   .remove $Class($1,file).getv
  35.   youtube2 %url $Class($1,file).getv
  36.   $Socket($1).delete
  37. }
  38. alias youtube2 {
  39.   if ($regex($1-,/http://(.+)/(.+)/)) { var %host = $regml(1) }
  40.   echo -a %host
  41.   var %sock = $Socket(%host,80)
  42.   var %file = $2
  43.   if ($regex($1-,/id=([a-z0-9]+)/$)) {  
  44.     - $Socket(%sock,$1).settag
  45.     - $Socket(%sock,OnYoutube2Close).sockclose
  46.     - $Socket(%sock,OnYoutube2Open).sockopen
  47.     - $Socket(%sock,OnYoutube2Read).sockread
  48.     - $Class(%sock,file,%file).setv
  49.     - $Class(%sock,dialog,Youtube2_ $+ %sock).setv
  50.     - $Socket(%sock).connect
  51.     .remove %file
  52.   }
  53. }
  54. alias OnYoutube2Open {
  55.   var %sw = sockwrite -n $sockname, %mark = $Socket($1).tag
  56.   if ($regex(%mark,/http://(.+)/(.+)/)) {
  57.     %sw GET / $+ $regml(2) HTTP/1.1
  58.     %sw Host: $regml(1)
  59.     %sw Connection: Close
  60.     %sw
  61.   }
  62.   .timer_progress_ $+ $1 0 1 _progress $1
  63. }
  64. ;http://www.youtube.com/watch?v=9x266qylESc
  65. alias onYoutube2Read {
  66.   sockread -f &1
  67.   if ($bfind(&1,1,Content-Length:)) {
  68.     var %s = $v1, %e = $bfind(&1,$v1,$crlf)
  69.     var %head = $bvar(&1,%s,$calc(%e - %s)).text
  70.     if ($regex(%head,/Content-Length: (\d+)/g)) {
  71.       echo -a $regml(1)
  72.       $Class($1,length,$regml(1)).setv
  73.       if ($regml(1) > 0) { dialog -m $Class($1,dialog).getv Youtube_Download }
  74.     }
  75.   }
  76.   if (!$Class($1,count).getv) { - $Class($1,count,1).setv }
  77.   if (!$sockbr) { return }
  78.   hinc $1 count $bvar(&1,0)
  79.   bwrite $Class($1,file).getv -1 -1 &1
  80. }
  81. alias _progress {
  82.   var %sock = $1
  83.   if (!$Class(%sock,ticks).getv) { - $Class(%sock,ticks,$ticks).setv }
  84.   var %ticks = $Class(%sock,ticks).getv
  85.   var %speed = $int($calc(($file($Class(%sock,file).getv).size / (($ticks - %ticks) / 1000)) / 1024)) kb/s
  86.   did -ra $Class(%sock,dialog).getv 1 Downloading: $strip($tpbar($Class(%sock,count).getv,$Class(%sock,length).getv,20,[,],|,·,15,4,5,2).p,c) %speed
  87. }
  88. alias OnYoutube2Close {
  89.   deheader $Class($1,file).getv $remove($class($1,file).getv,.tmp) $+ .flv
  90.   did -h $Class(%sock,dialog).getv 1
  91.   did -v $Class(%sock,dialog).getv 2
  92.   did -e $Class(%sock,dialog).getv 3
  93.   did -b $Class(%sock,dialog).getv 4
  94.   .timer_progress_ $+ $1 off
  95.   $Socket($1).delete
  96. }
  97. alias deheader {
  98.   var %in = $1, %out = $2
  99.   bread %in 0 $file(%in).size &in
  100.   var %find = $bfind(&in,1,$crlf $+ $crlf)
  101.   bcopy &out 1 &in $calc(%find + 4) -1
  102.   bwrite %out 0 -1 &out
  103.   if ($exists(%in)) { .remove %in }
  104. }
  105. alias urlencode return $regsubex($1-,/G(.)/g,$iif(($prop && 1 !isalnum) || !$prop,$chr(37) $+ $base($asc(1),10,16),1))
  106. alias tpbar return $+(,$8,$4,,$9,$str($6,$calc(($1 /$2)*$3)),,$10,$str($7,$calc($3 -($1 /$2)*$3)),,$8,$5) $iif($prop == p,$+(,$8,$4,,$base($11,10,10,2),$int($calc($1 /$2 *100)),%,,$8,$5)) $+ 
  107. alias pbar return $+(,$8,$4,,$9,$str($6,$calc(($1 /$2)*$3)),,$10,$str($7,$calc($3 -($1 /$2)*$3)),,$8,$5) $iif($prop == p,$+(,$8,$4,,$base($11,10,10,2),$int($calc($1 /$2 *100)),%,,$8,$5)) $+
  108. dialog Youtube_Download {
  109.   title "Download"
  110.   size -1 -1 164 53
  111.   option dbu
  112.   text "Downloading:", 1, 23 14 146 11
  113.   text "Download Complete.", 2, 60 14 146 11, hide
  114.   button "OK", 3, 43 31 37 12, default disable
  115.   button "Cancel", 4, 95 31 37 12
  116. }
  117. on *:dialog:Youtube2_*:sclick:3:{ dialog -x $dname }
  118. on *:dialog:Youtube2_*:sclick:4:{
  119.   var %sock $token($dname,2,95)
  120.   if ($exists($class(%sock,file).getv)) { .remove $class(%sock,file).getv }
  121.   .timer_progress_ $+ %sock off
  122.   - $Socket(%sock).delete
  123.   dialog -x $dname
  124. }
  125. alias urlparse {
  126.   if ($regex($1-,/^(?:([a-z.+-]+)://|())(?:([^@:]+)(?::(.*?)|())@|()())([a-z0-9.-]+)(?::(d+)|())(/.*)?$/i)) {
  127.     if ($prop == proto) return $iif($regml(1) != $null,$ifmatch,http)
  128.     elseif ($prop == user) return $regml(2)
  129.     elseif ($prop == pass) return $regml(3)
  130.     elseif ($prop == host) return $regml(4)
  131.     elseif ($prop == port) return $iif($regml(5) != $null,$ifmatch,$urlport($iif($regml(1) != $null,$ifmatch,http)))
  132.     elseif ($prop == path) return $iif($regml(6) != $null,$ifmatch,/)
  133.     else return $true
  134.   }
  135.   else return $iif(!$prop,$false)
  136. }
  137.  
  138. alias urlport {
  139.   return $iif($findtok(http ftp telnet nntp https gopher,$1,32),$gettok(80 21 23 119 443 70,$ifmatch,32),0)
  140. }
  141.  
  142. alias urlencode {
  143.   var %t = $1-, %r = "", %c
  144.   while ($len(%t)) {
  145.     %c = $asc($left(%t,1))
  146.     %r = %r $+ $iif((%c <= 32) || (%c >= 127),% $+ $base($ifmatch,10,16,2),$chr(%c))
  147.     %t = $right(%t,-1)
  148.   }
  149.   return %r
  150. }
  151.  
  152. alias urldecode {
  153.   var %t = $replace($1-,+,$chr(32),% $+ 20,$chr(32))
  154.   return $regsubex(%t,/%([0-9A-F]{2})/g,$chr($base(\1,16,10)))
  155. }
  156.  
  157. alias urlpath {
  158.   var %t = $iif($right($1-,1) == /,/), %r = "", %i = 0
  159.   while (%i < $numtok($1-,47)) {
  160.     inc %i
  161.     if ($gettok($1-,%i,47) == .) %r = %r $+ $iif($right(%r,1) != /,/)
  162.     elseif ($gettok($1-,%i,47) != ..) %r = $instok(%r,$ifmatch,0,47)
  163.     else {
  164.       if (!$numtok(%r,47)) return $null
  165.       %r = $deltok(%r,-1,47) $+ /
  166.     }
  167.   }
  168.   return $iif(%r != /,/) $+ %r $+ $iif((%r != $null) && ($right(%r,1) != /),%t)
  169. }
  170.  
  171. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  172. ; Description: This is a Socket class which contains   ;
  173. ; the basic structure of a class                       ;
  174. ; Usage: $Socket(<Instance>,<Params>,..).<Method>      ;
  175. ; Example: var %x $Socket(127.0.0.1,1337,LocalSock)    ;
  176. ; Example: $Socket(%x,SockOpenAlias).sockopen          ;
  177. ; Example: $Socket(%x,SockReadAlias).sockread          ;
  178. ; Example: $Socket(%x).connect                         ;
  179. ; Example: $Socket(%x).close                           ;
  180. ; Example: $Socket(%x).delete                          ;
  181. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  182. ; Public Declarations ;
  183. ;;;;;;;;;;;;;;;;;;;;;;;
  184. alias Socket.DELETE.Public
  185. alias Socket.PORT.Public
  186. alias Socket.IP.Public
  187. alias Socket.OPEN.Public
  188. alias Socket.CONNECT.Public
  189. alias Socket.LISTEN.Public
  190. alias Socket.CLOSE.Public
  191. alias Socket.SOCKREAD.Public
  192. alias Socket.SOCKOPEN.Public
  193. alias Socket.SOCKCLOSE.Public
  194. alias Socket.SOCKACCEPT.Public
  195. alias Socket.TAG.Public
  196. alias Socket.SETTAG.Public
  197. alias Socket.SETIP.Public
  198. alias Socket.SETPORT.Public
  199. alias Socket.WRITE.Public
  200. alias Socket.SOCK.Public
  201. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  202. ; Exception Declarations ;
  203. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  204. alias Socket.EXCEPTION.SockErr {
  205.   $Class($1,SockErr).getv $1-
  206.   return $iif($bvar(&SockErr,0),$bvar(&SockErr,1-).text)
  207. }
  208. ;;;;;;;;;;;;;;;;
  209. ; Socket Alias ;
  210. ;;;;;;;;;;;;;;;;
  211. alias Socket {
  212.   if (!$prop) goto init
  213.   if ($IsPublic(Socket,$prop)) goto $prop
  214.   return $catch($1,MemberErr, $qt($prop) is not a public member of Socket)
  215.   :init
  216.   return $Socket.INIT($1,$2,$3)
  217.   :delete
  218.   return $Socket.DELETE($1)
  219.   :open
  220.   :connect
  221.   if ($sock($1).status) $catch($1,SockOpenErr,Socket $1 is already open)
  222.   sockopen $1 $Class($1,IP).getv $Class($1,PORT).getv
  223.   return
  224.   :close
  225.   if ($sock($1).status) sockclose $1
  226.   else return $catch($1,SockCloseErr,Sock $1 was not open)
  227.   return
  228.   :listen
  229.   if ($sock($1).status) $catch($1,SockOpenErr,Socket $1 is already open)
  230.   var %x $iif($Class($1,IP).getv,$v1,127.0.0.1),%y $iif(%x != $null,-d)
  231.   socklisten %y %x $1 $Class($1,PORT).getv
  232.   ;socklisten $1 $Class($1,PORT).getv
  233.   return
  234.   :sockclose
  235.   return $iif($2,$Class($1,CLOSE,$2).setv,$Class($1,CLOSE).getv)
  236.   :sockopen
  237.   return $iif($2,$Class($1,OPEN,$2).setv,$Class($1,OPEN).getv)
  238.   :sockaccept
  239.   return $iif($2,$Class($1,ACCEPT,$2).setv,$Class($1,ACCEPT).getv)
  240.   :sockread
  241.   return return $iif($2,$Class($1,READ,$2).setv,$Class($1,READ).getv)
  242.   :settag
  243.   $Class($1,Tag,$2).setv
  244.   :tag
  245.   return $Class($1,Tag).getv
  246.   :setip
  247.   return $Class($1,IP,$2).setv
  248.   :setport
  249.   return $Class($1,PORT,$2).setv
  250.   :ip
  251.   return $Class($1,IP).getv
  252.   :port
  253.   return $Class($1,PORT).getv
  254.   :sock
  255.   return $Class($1,Handle).getv
  256.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  257.   ; Put your own method handlers here ;
  258.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  259.   :write
  260.   if ($sock($1).status != active) return $catch($1,SockErr,Socket $1 is not connected)
  261.   sockwrite $1 $2
  262.   return
  263.   :MethodHandler
  264. }
  265.  
  266. ;;;;;;;;;;;;;;;;;;
  267. ; Socket Methods ;
  268. ;;;;;;;;;;;;;;;;;;
  269. alias Socket.INIT {
  270.   var %instance $Class
  271.   $inheritsFrom(%instance,Socket)
  272.   $Class(%instance,IP,$1).setv
  273.   $Class(%instance,PORT,$2).setv
  274.   $Class(%instance,OPEN,Socket.DefaultSockOpen).setv
  275.   $Class(%instance,CLOSE,Socket.DefaultSockClose).setv
  276.   $Class(%instance,ACCEPT,Socket.DefaultSockAccept).setv
  277.   $Class(%instance,READ,Socket.DefaultSockRead).setv
  278.   $Class(%instance,SockErr,Socket.DefaultSockErr).setv
  279.   $Class(%instance,Tag,$iif($isinstance($3),$3,$3)).setv
  280.   $Class(%instance,Handle,%instance $+ ).setv
  281.   ;;;;;;;;;;;;;;;;;;;;;;;;
  282.   ; Do Initializing here ;
  283.   ;;;;;;;;;;;;;;;;;;;;;;;;
  284.   return %instance
  285. }
  286. alias Socket.DELETE {
  287.   ;;;;;;;;;;;;;;;;;;;;;;
  288.   ; Do Destroying here ;
  289.   ;;;;;;;;;;;;;;;;;;;;;;
  290.   if ($sock($1).status) sockclose $1
  291.   return $Class($1).DELETE
  292. }
  293. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  294. ; Default Event Handlers ;
  295. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  296. alias Socket.DefaultSockOpen {
  297.   + Successfully $iif($sock($sockname).status != Active,dis) $+ connected to $sock($sockname).ip $+ : $+ $sock($sockname).port
  298. }
  299. alias Socket.DefaultSockClose {
  300.   + Successfully disconnected from $sock($sockname).ip $+ : $+ $sock($sockname).port
  301.   $Socket($1).delete
  302. }
  303. alias Socket.DefaultSockRead {
  304.   sockread -f %temp
  305.   + Received data on socket: $1: %temp
  306. }
  307. alias Socket.DefaultSockAcceptW {
  308.   var %x $sockname $+ 
  309.   sockaccept %x
  310.   var %a $socket($sock(%x).ip,$sock(%x).port)
  311.   sockrename %x %a $+ 
  312.   $Class($left($sockname,-1),ACCEPT).getv $left($sockname,-1) %a
  313. }
  314. alias Socket.DefaultSockAccept {
  315.   var %socklistn $1
  316.   var %socknew $2
  317.   + Socket accepted from  $+ $socket($2).ip $+  on port  $+ $socket($2).port $+ : Handle = $2
  318. }
  319. alias Socket.DefaultSockErr {
  320.   ;sockclose $1
  321. }
  322. alias SockErr {
  323.   bset -t &SockErr $1-
  324. }
  325. ;;;;;;;;;;;;;;;;;;;;
  326. ; Trigger Handlers ;
  327. ;;;;;;;;;;;;;;;;;;;;
  328. on 1:sockopen:*: $Class($left($sockname,-1),OPEN).getv $left($sockname,-1)
  329. on 1:sockclose:*: $Class($left($sockname,-1),CLOSE).getv $left($sockname,-1)
  330. on 1:sockread:*: $Class($left($sockname,-1),READ).getv $left($sockname,-1)
  331. on 1:socklisten:*: Socket.DefaultSockAcceptW
  332. ;;;;;;;;;;;;;;
  333. ; End Socket ;
  334. ;;;;;;;;;;;;;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement