Advertisement
imk0tter

Untitled

Apr 21st, 2011
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 5.71 KB | None | 0 0
  1. alias youtube {
  2.   var %sock = youtube_ $+ $md5($ticks $+ $r(1,999999)), %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.     sockclose %sock
  6.     hadd -m %sock mark $1-
  7.     sockopen %sock youtube.com 80
  8.   }
  9.   else { echo -a Youtube Downloader: Invalid Link, Syntax: /youtube http://www.youtube.com/watch?v=Code  }
  10. }
  11. on *:sockopen:youtube_*:{
  12.   var %sw = sockwrite -n $sockname, %mark = $hget($sockname,mark)
  13.  
  14.   if (!$regex(%mark,/v=(.+)$/) || $sockerr) { echo -a Youtube Downloader: Connection Failed }
  15.   var %code = $regml(1)
  16.  
  17.   %sw GET $urlparse(%mark).path HTTP/1.1
  18.   %sw Host: www.youtube.com
  19.   %sw Connection: Close
  20.   %sw
  21.   hadd -m $sockname file %code $+ .tmp
  22. }
  23. on *:sockread:youtube_*:{
  24.   sockread -f &d
  25.   bwrite $hget($sockname,file) -1 -1 &d
  26. }
  27. on *:sockclose:youtube_*:{
  28.   bread $hget($sockname,file) 1 $file($hget($sockname,file)).size &d
  29.   var %1 = $bfind(&d,1,fmt_url_map=), %2 = $bfind(&d,%1,&)
  30.   var %url = $bvar(&d,%1 - %2).text
  31.   var %url = $urldecode(%url)
  32.   var %url = $gettok($gettok(%url,2,124),1,44)
  33.   .remove $hget($sockname,file)
  34.   youtube2 %url $hget($sockname,file)
  35.   .hfree -sw $sockname
  36. }
  37. alias youtube2 {
  38.   if ($regex($1-,/http://(.+)/(.+)/)) { var %host = $regml(1) }
  39.   var %sock = youtube2_ $+ $md5($ticks $+ $r(1,9999999))
  40.   var %file = $2
  41.   if ($regex($1-,/id=([a-z0-9]+)/$)) {  
  42.     sockclose %sock
  43.     .remove %file
  44.     hadd -m %sock mark $1
  45.     hadd -m %sock file %file
  46.     sockopen %sock %host 80
  47.   }
  48. }
  49. on *:sockopen:youtube2_*:{
  50.   var %sw = sockwrite -n $sockname, %mark = $hget($sockname,mark)
  51.   if ($regex(%mark,/http://(.+)/(.+)/)) {
  52.     %sw GET / $+ $regml(2) HTTP/1.1
  53.     %sw Host: $regml(1)
  54.     %sw Connection: Close
  55.     %sw
  56.   }
  57.   .timer_progress_ $+ $sockname 0 1 _progress $sockname
  58. }
  59.  
  60. on *:sockread:youtube2_*:{
  61.   sockread -f &1
  62.   if ($bfind(&1,1,Content-Length:)) {
  63.     var %s = $v1, %e = $bfind(&1,$v1,$lf)
  64.     var %head = $bvar(&1,%s,$calc(%e - %s)).text
  65.     if ($regex(%head,/Content-Length: (\d+)/i)) {
  66.       hadd -m $sockname length $regml(1)
  67.       if ($regml(1) > 0) { dialog -m $sockname Youtube_Download }
  68.     }
  69.   }
  70.   if (!$hget($sockname,count)) { hadd -m $sockname count 1 }
  71.   if (!$sockbr) { return }
  72.   hinc $sockname count $bvar(&1,0)
  73.   bwrite $hget($sockname,file) -1 -1 &1
  74. }
  75. alias _progress {
  76.   var %sock = $1
  77.   if (!$hget(%sock,ticks)) { hadd -m %sock ticks $ticks }
  78.   var %ticks = $hget(%sock,ticks)
  79.   var %speed = $int($calc(($file($hget(%sock,file)).size / (($ticks - %ticks) / 1000)) / 1024)) kb/s
  80.   did -ra %sock 1 Downloading: $strip($tpbar($hget(%sock,count),$hget(%sock,length),20,[,],|,·,15,4,5,2).p,c) %speed
  81. }
  82. on *:sockclose:youtube2_*:{
  83.   deheader $hget($sockname,file) $remove($hget($sockname,file),.tmp) $+ .flv
  84.   did -h $sockname 1
  85.   did -v $sockname 2
  86.   did -e $sockname 3
  87.   did -b $sockname 4
  88.   .timer_progress_ $+ $sockname off
  89.   .hfree -sw $sockname
  90. }
  91. alias deheader {
  92.   var %in = $1, %out = $2
  93.   bread %in 0 $file(%in).size &in
  94.   var %find = $bfind(&in,1,$crlf $+ $crlf)
  95.   bcopy &out 1 &in $calc(%find + 4) -1
  96.   bwrite %out 0 -1 &out
  97.   if ($exists(%in)) { .remove %in }
  98. }
  99. alias urlencode return $regsubex($1-,/G(.)/g,$iif(($prop && 1 !isalnum) || !$prop,$chr(37) $+ $base($asc(1),10,16),1))
  100. alias urldecode return $regsubex($replace($1-,+,$chr(32),% $+ 20,$chr(32)),/%([0-9A-Fa-f]{2})/g,$chr($base(\1,16,10)))
  101.  
  102. 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)) $+ 
  103. 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)) $+
  104.  
  105. dialog Youtube_Download {
  106.   title "Download"
  107.   size -1 -1 164 53
  108.   option dbu
  109.   text "Downloading:", 1, 23 14 146 11
  110.   text "Download Complete.", 2, 60 14 146 11, hide
  111.   button "OK", 3, 43 31 37 12, default disable
  112.   button "Cancel", 4, 95 31 37 12
  113. }
  114. on *:dialog:Youtube2_*:sclick:3:{ dialog -x $dname }
  115. on *:dialog:Youtube2_*:sclick:4:{
  116.   if ($exists($hget($dname,file))) { .remove $hget($dname,file) }
  117.   .hfree -sw $dname
  118.   .timer_progress_ $+ $dname off
  119.   .sockclose $dname
  120.   dialog -x $dname
  121. }
  122. alias urlparse {
  123.   if ($regex($1-,/^(?:([a-z.+-]+)://|())(?:([^@:]+)(?::(.*?)|())@|()())([a-z0-9.-]+)(?::(d+)|())(/.*)?$/i)) {
  124.     if ($prop == proto) return $iif($regml(1) != $null,$ifmatch,http)
  125.     elseif ($prop == user) return $regml(2)
  126.     elseif ($prop == pass) return $regml(3)
  127.     elseif ($prop == host) return $regml(4)
  128.     elseif ($prop == port) return $iif($regml(5) != $null,$ifmatch,$urlport($iif($regml(1) != $null,$ifmatch,http)))
  129.     elseif ($prop == path) return $iif($regml(6) != $null,$ifmatch,/)
  130.     else return $true
  131.   }
  132.   else return $iif(!$prop,$false)
  133. }
  134.  
  135. alias urlport {
  136.   return $iif($findtok(http ftp telnet nntp https gopher,$1,32),$gettok(80 21 23 119 443 70,$ifmatch,32),0)
  137. }
  138.  
  139. alias urlencode {
  140.   var %t = $1-, %r = "", %c
  141.   while ($len(%t)) {
  142.     %c = $asc($left(%t,1))
  143.     %r = %r $+ $iif((%c <= 32) || (%c >= 127),% $+ $base($ifmatch,10,16,2),$chr(%c))
  144.     %t = $right(%t,-1)
  145.   }
  146.   return %r
  147. }
  148.  
  149. alias urlpath {
  150.   var %t = $iif($right($1-,1) == /,/), %r = "", %i = 0
  151.   while (%i < $numtok($1-,47)) {
  152.     inc %i
  153.     if ($gettok($1-,%i,47) == .) %r = %r $+ $iif($right(%r,1) != /,/)
  154.     elseif ($gettok($1-,%i,47) != ..) %r = $instok(%r,$ifmatch,0,47)
  155.     else {
  156.       if (!$numtok(%r,47)) return $null
  157.       %r = $deltok(%r,-1,47) $+ /
  158.     }
  159.   }
  160.   return $iif(%r != /,/) $+ %r $+ $iif((%r != $null) && ($right(%r,1) != /),%t)
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement