Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

YouTube Script (Parse Vids and Search) v2.3

By: illpastethat on Jun 13th, 2011  |  syntax: mIRC  |  size: 9.37 KB  |  hits: 385  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ;YouTube Script (Parse Vids and Search) v2.3
  2. ;Made by nick1
  3. ;Last edit June 13 2011
  4.  
  5. raw 408:*: msg $2 $remove($strip($13-),$chr(9))
  6.  
  7. on $*:text:/^[!@]y(outube|t|tsearch|search|ousearch|outubesearch)/Si:*:{
  8.   if ($($+(%,botflood.,$nick),2)) {
  9.     if ($($+(%,botflood.,$nick),2) >= 50) { ignore -u60 $address($nick,0) | msg $chan $+($nick,$chr(44)) You Have Been Put On Ignore For 60secs For Abusing The Bot. | halt }
  10.     elseif ($($+(%,botflood.,$nick),2) >= 40) { msg $chan $+($nick,$chr(44)) Please Do Not Abuse The Bot. | inc -z $+(%,botflood.,$nick) 20 | halt }
  11.     else { inc -z $+(%,botflood.,$nick) 25 }
  12.   }
  13.   else { inc -z $+(%,botflood.,$nick) 25 }
  14.   var %ticks $ticks
  15.   if ($2) {
  16.     set $+(%,ysearch.,%ticks,.msgtype) $iif($left($strip($1),1) == @,msg $chan,notice $nick)
  17.     set $+(%,ysearch.,%ticks,.search) $replace($2-,$chr(32),+)
  18.     sockopen $+(ysearch.,%ticks) youtube.com 80
  19.   }
  20.   elseif ($2 == $null) { msg $chan $+(4,$nick,,$chr(44)) 10Incorrect Syntax: Try ! or @ 4YOUTUBE10 <search term> }
  21. }
  22.  
  23. on *:input:*:{
  24.   if (($remove($1,$left($strip($1),1)) == ysearch) || ($remove($1,$left($strip($1),1)) == ytsearch) || ($remove($1,$left($strip($1),1)) == yt) || ($remove($1,$left($strip($1),1)) == youtubesearch)) {
  25.     set $+(%,ysearch.,$ticks,.msgtype) msg $active
  26.     set $+(%,ysearch.,$ticks,.search) $replace($2-,$chr(32),+)
  27.     sockopen $+(ysearch.,$ticks) youtube.com 80
  28.   }
  29.   elseif (*youtube.com* iswm $1-) {
  30.     var %i 1
  31.     while (%i <= $numtok($1-,32)) {
  32.       if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
  33.         set $+(%,youtube.,$ticks,.url) $($+($,%i),2)
  34.         set $+(%,youtube.,$ticks,.tag) $remove($strip($($+($,%i),2)),http://,www.,youtube.com,youtu.be/,/watch?v=,$chr(31))
  35.       }
  36.       inc %i
  37.     }
  38.     set $+(%,youtube.,$ticks,.msgtype) msg $active
  39.     set $+(%,youtube.,$ticks,.nick) $nick
  40.     set $+(%,youtube.,$ticks,.chan) $chan
  41.     set $+(%,youtube.,$ticks,.network) $network
  42.     sockopen $+(youtube.,$ticks) youtube.com 80
  43.   }
  44.   elseif (($1 == !youtubelinks) || ($1 == !youtubefetch) || ($1 == !youtube)) {
  45.     set %youtubefetch $addtok(%youtubefetch,$iif(($2),$2,$chan),44)
  46.     echo -ac info I will message $iif(($2),$2,$chan) with youtube info...
  47.   }
  48.   elseif (($1 == !noyoutubelinks) || ($1 == !noyoutubefetch) || ($1 == !noyoutube)) {
  49.     set %youtubefetch $remtok(%youtubefetch,$iif(($2),$2,$chan),44)
  50.     echo -ac info I wont message $iif(($2),$2,$chan) with youtube info...
  51.   }
  52. }
  53.  
  54. alias checkifsockopen {
  55.   if ($sock(%checksockname)) { sockclose %checksockname
  56.     $($+(%,youtube.,$remove(%checksockname,youtube.,ysearch.).msgtype),2) $+(12[4,YOUTUBE,12])10 Error Encountered!
  57.   }
  58. }
  59.  
  60. on *:sockopen:ysearch*: {  
  61.   set %checksockname $sockname
  62.   .timerCheck 1 5 checkifsockopen
  63.   sockwrite -nt $sockname GET /results?search_query= $+ $($+(%,ysearch.,$remove($sockname,ysearch.),.search),2) HTTP/1.1
  64.   sockwrite -nt $sockname Host: www.youtube.com
  65.   sockwrite -nt $sockname $crlf
  66. }
  67.  
  68. alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }
  69.  
  70. on *:SOCKREAD:ysearch*: {
  71.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  72.   sockread %sockreader
  73.   if (*<h3>* iswm %sockreader) {
  74.     set $+(%,ysearch.,$remove($sockname,ysearch.),.title) $regsubex($nohtml($replace($remove(%sockreader,|),<b>,,</b>,,&quot;,",&amp;,&)),/&#(\d\d?\d?\d?);/g,$chr(\1))
  75.     tokenize 34 %sockreader
  76.     set $+(%,ysearch.,$remove($sockname,ysearch.),.tag) $2
  77.   }
  78.   elseif (*</div><h3* iswm %sockreader) {
  79.     set $+(%,ysearch.,$remove($sockname,ysearch.),.title) $regsubex($nohtml($replace($remove(%sockreader,|),<b>,,</b>,,&quot;,",&amp;,&)),/&#(\d\d?\d?\d?);/g,$chr(\1))
  80.     tokenize 34 %sockreader
  81.     set $+(%,ysearch.,$remove($sockname,ysearch.),.tag) $4
  82.   }
  83.   elseif (*<span class="video-time">* iswm %sockreader) {
  84.     set $+(%,ysearch.,$remove($sockname,ysearch.),.time) $nohtml($remove(%sockreader,Add to,Added,to,queue))
  85.   }
  86.   elseif (*<span class="username-prepend">* iswm %sockreader) {
  87.     set $+(%,ysearch.,$remove($sockname,ysearch.),.user) $remove($nohtml(%sockreader),by)
  88.   }
  89.   elseif (*<span class="viewcount">* iswm %sockreader) {
  90.     set $+(%,ysearch.,$remove($sockname,ysearch.),.viewcount) $remove($nohtml(%sockreader),|,views)
  91.     $($+(%,ysearch.,$remove($sockname,ysearch.),.msgtype),2) 1,0You0,4Tube 10Link:4 http://youtube.com $+ $($+(%,ysearch.,$remove($sockname,ysearch.),.tag),2) 10Title:4 $($+(%,ysearch.,$remove($sockname,ysearch.),.title),2) 10Length:4 $($+(%,ysearch.,$remove($sockname,ysearch.),.time),2) 10Views:4 $($+(%,ysearch.,$remove($sockname,ysearch.),.viewcount),2) 10User:4 $($+(%,ysearch.,$remove($sockname,ysearch.),.user),2)
  92.     unset $+(%,ysearch.,$remove($sockname,ysearch.),*)
  93.     sockclose $sockname
  94.   }
  95. }
  96.  
  97.  
  98.  
  99. on $*:text:/youtu(.be|be.com)/Si:*: {
  100.   if (($chan != #nova) && ($nick != Runescript)) {
  101.     if ($($+(%,botflood.,$nick),2)) {
  102.       if ($($+(%,botflood.,$nick),2) >= 50) { ignore -u60 $address($nick,0) | msg $chan $+($nick,$chr(44)) You Have Been Put On Ignore For 60secs For Abusing The Bot. | halt }
  103.       elseif ($($+(%,botflood.,$nick),2) >= 40) { msg $chan $+($nick,$chr(44)) Please Do Not Abuse The Bot. | inc -z $+(%,botflood.,$nick) 20 | halt }
  104.       else { inc -z $+(%,botflood.,$nick) 10 }
  105.     }
  106.     else { inc -z $+(%,botflood.,$nick) 10 }
  107.     set %i 1
  108.     var %ticks $ticks
  109.     while (%i <= $numtok($1-,32)) {
  110.       if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
  111.         set $+(%,youtube.,%ticks,.url) $($+($,%i),2)
  112.         set $+(%,youtube.,%ticks,.tag) $remove($strip($($+($,%i),2)),http://,www,$chr(46),youtube,com,youtu,be,/,watch?v=,$chr(31))
  113.       }
  114.       inc %i
  115.     }
  116.     if (($me == Mafbot) || ($nick($chan,$me,@&~)) || ($istok(%youtubefetch,$chan,44))) {
  117.       set $+(%,youtube.,%ticks,.msgtype) msg $chan
  118.     }
  119.     elseif (($me != Mafbot) && (!$nick($chan,$me,@&~)) && (!$istok(%youtubefetch,$chan,44))) {
  120.       set $+(%,youtube.,%ticks,.msgtype) echo -a
  121.     }
  122.     if (($($+(%,youtube.,%ticks,.tag),2) != %_youtube.last) && ($($+(%,youtube.,%ticks,.tag),2) != $null)) {
  123.       set $+(%,youtube.,%ticks,.nick) $nick
  124.       set $+(%,youtube.,%ticks,.chan) $chan
  125.       set $+(%,youtube.,%ticks,.network) $network
  126.       sockopen $+(youtube.,%ticks) youtube.com 80
  127.     }
  128.   }
  129. }
  130.  
  131. on *:sockopen:youtube*: {
  132.   .timerSet 1 4 set %checksockname $sockname
  133.   .timerCheck 1 5 checkifsockopen
  134.   sockwrite -nt $sockname GET $+(/,watch?v=,$($+(%,youtube.,$remove($sockname,youtube.),.tag),2)) HTTP/1.1
  135.   sockwrite -nt $sockname Host: www.youtube.com
  136.   sockwrite -nt $sockname $crlf
  137. }
  138.  
  139. on *:SOCKREAD:youtube*: {
  140.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  141.   else {
  142.     var %sockreader
  143.     sockread %sockreader
  144.     if (*Location: http://www.youtube.com/verify_age?next_url=* iswm %sockreader) {
  145.       if ($($+(%,youtube.,$remove($sockname,youtube.),.msgtype),2) != echo -a) {
  146.         $($+(%,youtube.,$remove($sockname,youtube.),.msgtype),2) 1,0You0,4Tube 10This content may contain material flagged by YouTube's user community that may be inappropriate for some users.
  147.       }
  148.       set %_youtube.last $($+(%,youtube.,$remove($sockname,youtube.),.tag),2)
  149.       unset $+(%,youtube.,$remove($sockname,youtube.),*)
  150.       sockclose youtube
  151.       halt
  152.     }
  153.     elseif (*<meta name="title"* iswm %sockreader) {
  154.       tokenize 32 %sockreader
  155.       set $+(%,youtube.,$remove($sockname,youtube.),.title) $replace($remove(%sockreader,<meta name="title" content=",">),&amp;quot;,",&amp;#39;,',&quot;,",&amp;,&,&#39;,')
  156.     }
  157.     elseif (*<span class="watch-view-count">* iswm %sockreader) {
  158.       set $+(%,youtube.,$remove($sockname,youtube.),.viewcheck) on
  159.     }
  160.     elseif (*<a id="watch-username" class="inline-block" rel="author" href="/user/* iswm %sockreader) {
  161.       set $+(%,youtube.,$remove($sockname,youtube.),.user) $nohtml(%sockreader)
  162.     }
  163.     elseif (*<a id="watch-userbanner" class="inline-block" rel="author" href="/user/* iswm %sockreader) {
  164.       tokenize 34 %sockreader
  165.       set $+(%,youtube.,$remove($sockname,youtube.),.user) $10
  166.     }
  167.     elseif ((*<strong>* iswm %sockreader) && ($($+(%,youtube.,$remove($sockname,youtube.),.viewcheck),2) == on)) {
  168.       set $+(%,youtube.,$remove($sockname,youtube.),.viewcount) $nohtml(%sockreader)
  169.       if ($($+(%,youtube.,$remove($sockname,youtube.),.msgtype),2) == echo -a) {
  170.         $($+(%,youtube.,$remove($sockname,youtube.),.msgtype),2) 12[4 $+ $($+(%,youtube.,$remove($sockname,youtube.),.chan),2) $+ 12] 1,0You0,4Tube 10Title:4 $($+(%,youtube.,$remove($sockname,youtube.),.title),2) 10Views:4 $($+(%,youtube.,$remove($sockname,youtube.),.viewcount),2) 10User:4 $($+(%,youtube.,$remove($sockname,youtube.),.user),2) 12From4 $($+(%,youtube.,$remove($sockname,youtube.),.nick),2) 10on12 $($+(%,youtube.,$remove($sockname,youtube.),.network),2)    
  171.       }
  172.       elseif ($($+(%,youtube.,$remove($sockname,youtube.),.msgtype),2) != echo -a) {
  173.         $($+(%,youtube.,$remove($sockname,youtube.),.msgtype),2) 1,0You0,4Tube 10Title:4 $($+(%,youtube.,$remove($sockname,youtube.),.title),2) 10Views:4 $($+(%,youtube.,$remove($sockname,youtube.),.viewcount),2) 10User:4 $($+(%,youtube.,$remove($sockname,youtube.),.user),2)
  174.       }
  175.       set %_youtube.last $($+(%,youtube.,$remove($sockname,youtube.),.tag),2)
  176.       unset $+(%,youtube.,$remove($sockname,youtube.),*)
  177.       sockclose youtube
  178.     }
  179.   }
  180. }