Advertisement
illpastethat

YouTube Script (Parse Vids and Search) v3.0

Aug 27th, 2011
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 14.62 KB | None | 0 0
  1. ;YouTube Script (Parse Vids and Search) v3.0
  2. ;Made by nick1
  3. ;Last edit August 27 2011
  4. ;For help type /YouTube in mIRC
  5.  
  6. alias YouTube {
  7.   dialog -m YouTube YouTube
  8. }
  9.  
  10. dialog Youtube {
  11.   title "YouTube Script (Parse Vids and Search) v3.0"
  12.   size -1 -1 187 133
  13.   option dbu
  14.   icon $mircdir $+ Youtube.ico, 0
  15.   link "View Script On Hawkee -- Report Bugs Here", 1, 39 2 105 8
  16.   button "Exit", 7, 54 120 72 12, cancel
  17.   tab "About", 10, 1 9 183 106
  18.   button "On", 15, 20 98 37 12, tab 10
  19.   button "Off", 16, 120 98 37 12, tab 10
  20.   text "This script was created by nick1 (Rizon Network)", 18, 2 24 140 8, tab 10
  21.   text "Last updated on August 27, 2011", 19, 2 32 104 11, tab 10
  22.   text "Please post suggestions, complaints, or bugs on the hawkee link", 20, 2 41 167 8, tab 10
  23.   text "The script automatically will attempt to protect itself from spam", 21, 2 50 174 8, tab 10
  24.   text "!commands will notice the user; @commands will be public to the channel", 13, 2 79 175 8, tab 10
  25.   text "On/Off Buttons will Enable/Disable the entire script", 17, 26 90 135 7, tab 10
  26.   text "By default the script will run on every channel.  To disable for a channel use Channel Settings. Or type !youtube <#chan> or !noyoutube <#chan> [[Only by the bot itself]]", 65, 2 59 176 21, tab 10
  27.   tab "Parse", 11
  28.   button "On", 111, 20 98 37 12, tab 11
  29.   button "Off", 9, 120 98 37 12, tab 11
  30.   text "This part of the script will automatically find youtube links that other people post and message the channel with info about the video.", 22, 3 26 177 14, tab 11
  31.   text "The script will return the following information: Title, Views, and User. ", 23, 3 43 174 10, tab 11
  32.   text "There is automatic flood protection enabled so the script will not process the same link twice in a row", 24, 3 56 179 13, tab 11
  33.   text "On/Off Buttons will Enable/Disable the parsing section of the script", 25, 8 90 162 7, tab 11
  34.   tab "Search", 2
  35.   button "On", 5, 20 98 37 12, tab 2
  36.   button "Off", 14, 120 98 37 12, tab 2
  37.   text "This part of the script will automatically find the most relevant YouTube video to the provided search terms.", 57, 4 24 174 13, tab 2
  38.   text "The script will return the following information: Link, Title, Length, Views, and User.", 58, 4 40 176 13, tab 2
  39.   text "Commands may be prefixed with an ! or an @; with !commands private and @commands public to the channel.", 59, 4 54 176 13, tab 2
  40.   box "Search Commands -- Prefix With ! or @ --", 60, 4 68 175 22, tab 2
  41.   text "On/Off Buttons will Enable/Disable the search section of the script", 61, 8 90 159 7, tab 2
  42.   text "ysearch <search terms>; ytsearch <search terms>;youtube <search terms>", 62, 15 75 156 14, tab 2
  43.   tab "Channel Settings", 3
  44.   list 6, 7 56 168 54, tab 3 sort size extsel hsbar vsbar
  45.   edit "", 8, 4 24 140 25, tab 3 multi return autohs autovs
  46.   text "List of channels the script will NOT run on", 12, 27 49 101 7, tab 3
  47.   button "Add", 4, 145 25 37 12, tab 3
  48.   button "Remove", 63, 145 38 37 12, tab 3
  49.   button "Click here to enter #channels ...", 64, 5 25 138 23, tab 3
  50.   tab "Just For Fun", 26
  51.   text "See if you can check all the checkboxes! Warning: there might not be a reward.", 27, 22 50 144 17, tab 26
  52.   check "Check Box", 28, 4 23 50 10, tab 26
  53.   check "Check Box", 29, 5 33 50 10, tab 26
  54.   check "Check Box", 30, 39 23 50 10, tab 26
  55.   check "Check Box", 31, 24 31 50 10, tab 26
  56.   check "Check Box", 32, 3 41 50 10, tab 26
  57.   check "Check Box", 33, 15 78 50 10, tab 26
  58.   check "Check Box", 34, 73 80 50 10, tab 26
  59.   check "Check Box", 35, 84 71 50 10, tab 26
  60.   check "Check Box", 36, 91 29 50 10, tab 26
  61.   check "Check Box", 37, 122 80 50 10, tab 26
  62.   check "Check Box", 38, 129 98 50 10, tab 26
  63.   check "Check Box", 39, 79 90 50 10, tab 26
  64.   check "Check Box", 40, 26 91 50 10, tab 26
  65.   check "Check Box", 41, 109 65 50 10, tab 26
  66.   check "Check Box", 42, 125 56 50 10, tab 26
  67.   check "Check Box", 43, 127 30 50 10, tab 26
  68.   check "Check Box", 44, 120 22 50 10, tab 26
  69.   check "Check Box", 45, 44 35 50 10, tab 26
  70.   check "Check Box", 46, 78 39 50 10, tab 26
  71.   check "Check Box", 47, 128 88 50 10, tab 26
  72.   check "Check Box", 48, 11 66 50 10, tab 26
  73.   check "Check Box", 49, 23 99 50 10, tab 26
  74.   check "Check Box", 50, 36 67 50 10, tab 26
  75.   check "Check Box", 51, 127 71 50 10, tab 26
  76.   check "Check Box", 52, 76 61 50 10, tab 26
  77.   check "Check Box", 53, 132 40 50 10, tab 26
  78.   check "Check Box", 54, 45 97 50 10, tab 26
  79.   check "Check Box", 55, 87 96 50 10, tab 26
  80.   check "Check Box", 56, 30 81 50 10, tab 26
  81. }
  82.  
  83. on *:dialog:youtube:init:0: {
  84.   FillChannelBox
  85. }
  86.  
  87. alias FillChannelBox {
  88.   did -r youtube 6
  89.   var %y 1
  90.   while (%y <= $numtok(%youtubefetch,44)) {
  91.     did -a youtube 6 $gettok(%youtubefetch,%y,44)
  92.     inc %y
  93.   }
  94. }
  95.  
  96. on *:dialog:youtube:sclick:*: {
  97.   if ($did == 1) {
  98.     run http://www.hawkee.com/snippet/8577/
  99.   }
  100.   elseif ($did == 15) {
  101.     enable #search
  102.     enable #parse
  103.   }
  104.   elseif ($did == 16) {
  105.     disable #search
  106.     disable #parse
  107.   }
  108.   elseif ($did == 111) {
  109.     enable #parse
  110.   }
  111.   elseif ($did == 9) {
  112.     disable #parse
  113.   }
  114.   elseif ($did == 5) {
  115.     enable #search
  116.   }
  117.   elseif ($did == 14) {
  118.     disable #search
  119.   }
  120.   elseif ($did == 4) {
  121.     set %youtubefetch $addtok(%youtubefetch,$iif(($left($did(8),1) == $chr(35)),$did(8),$+($chr(35),$did(8))),44)
  122.     did -r youtube 8
  123.     FillChannelBox
  124.   }
  125.   elseif ($did == 63) {
  126.     set %youtubefetch $remtok(%youtubefetch,$iif(($left($did(8),1) == $chr(35)),$did(8),$+($chr(35),$did(8))),44)
  127.     did -r youtube 8
  128.     FillChannelBox
  129.   }
  130.   elseif ($did isnum 28-56) {
  131.     $iif(($r(1,3) == 1),.timercheck -m 1 13 did -c youtube $r(28,56),.timeruncheck -m 1 13 did -u youtube $r(28,56))
  132.   }
  133. }
  134.  
  135. raw 408:*: msg $2 $remove($strip($13-),$chr(9))
  136.  
  137. #search on
  138. on $*:text:/^[!@]y(outube|t|tsearch|search|ousearch|outubesearch)/Si:*: {
  139.   $iif($istok(%youtubefetch,$chan,44),halt,noop)
  140.   if ($($+(%,botflood.,$nick),2)) {
  141.     if ($($+(%,botflood.,$nick),2) >= 50) {
  142.       ignore -u60 $address($nick,0)
  143.       msg $chan $+($nick,$chr(44)) You Have Been Put On Ignore For 60secs For Abusing The Bot.
  144.       halt
  145.     }
  146.     elseif ($($+(%,botflood.,$nick),2) >= 40) {
  147.       msg $chan $+($nick,$chr(44)) Please Do Not Abuse The Bot.
  148.       inc -z $+(%,botflood.,$nick) 20
  149.       halt
  150.     }
  151.     else {
  152.       inc -z $+(%,botflood.,$nick) 25
  153.     }
  154.   }
  155.   else {
  156.     inc -z $+(%,botflood.,$nick) 25
  157.   }
  158.   var %ticks $ticks
  159.   if ($2) {
  160.     set $+(%,ysearch.,%ticks,.msgtype) $iif($left($strip($1),1) == @,msg $chan,notice $nick)
  161.     set $+(%,ysearch.,%ticks,.search) $replace($2-,$chr(32),+)
  162.     sockopen $+(ysearch.,%ticks) youtube.com 80
  163.   }
  164.   elseif ($2 == $null) {
  165.     msg $nick $+(4,$nick,,$chr(44)) 10Incorrect Syntax: Try ! or @ 4YouTube10 <search term>
  166.   }
  167. }
  168.  
  169. on *:input:*:{
  170.   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)) {
  171.     set $+(%,ysearch.,$ticks,.msgtype) msg $active
  172.     set $+(%,ysearch.,$ticks,.search) $replace($2-,$chr(32),+)
  173.     sockopen $+(ysearch.,$ticks) youtube.com 80
  174.   }
  175.   elseif (*youtube.com* iswm $1-) {
  176.     var %i 1
  177.     while (%i <= $numtok($1-,32)) {
  178.       if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
  179.         set $+(%,youtube.,$ticks,.url) $($+($,%i),2)
  180.         set $+(%,youtube.,$ticks,.tag) $remove($strip($($+($,%i),2)),http://,www.,youtube.com,youtu.be/,/watch?v=,$chr(31),&feature=feedu)
  181.       }
  182.       inc %i
  183.     }
  184.     set $+(%,youtube.,$ticks,.msgtype) msg $active
  185.     set $+(%,youtube.,$ticks,.nick) $nick
  186.     set $+(%,youtube.,$ticks,.chan) $chan
  187.     set $+(%,youtube.,$ticks,.network) $network
  188.     sockopen $+(youtube.,$ticks) youtube.com 80
  189.   }
  190.   elseif (($1 == !youtubelinks) || ($1 == !youtubefetch) || ($1 == !youtube)) {
  191.     set %youtubefetch $remtok(%youtubefetch,$iif(($2),$2,$chan),44)
  192.     echo -ac info I will message $iif(($2),$2,$chan) with youtube info...
  193.   }
  194.   elseif (($1 == !noyoutubelinks) || ($1 == !noyoutubefetch) || ($1 == !noyoutube)) {
  195.     set %youtubefetch $addtok(%youtubefetch,$iif(($2),$2,$chan),44)
  196.     echo -ac info I won't message $iif(($2),$2,$chan) with youtube info...
  197.   }
  198. }
  199.  
  200. on *:sockopen:ysearch*: {  
  201.   sockwrite -nt $sockname GET /results?search_query= $+ $($+(%,ysearch.,$remove($sockname,ysearch.),.search),2) HTTP/1.1
  202.   sockwrite -nt $sockname Host: www.youtube.com
  203.   sockwrite -nt $sockname $crlf
  204. }
  205.  
  206. alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }
  207.  
  208. on *:SOCKREAD:ysearch*: {
  209.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  210.   sockread %sockreader
  211.   if (*<h3>* iswm %sockreader) {
  212.     set $+(%,ysearch.,$remove($sockname,ysearch.),.title) $regsubex($nohtml($replace($remove(%sockreader,|),<b>,,</b>,,&quot;,",&amp;,&)),/&#(\d\d?\d?\d?);/g,$chr(\1))
  213.     tokenize 34 %sockreader
  214.     set $+(%,ysearch.,$remove($sockname,ysearch.),.tag) $2
  215.   }
  216.   elseif (*</div><h3* iswm %sockreader) {
  217.     set $+(%,ysearch.,$remove($sockname,ysearch.),.title) $regsubex($nohtml($replace($remove(%sockreader,|),<b>,,</b>,,&quot;,",&amp;,&)),/&#(\d\d?\d?\d?);/g,$chr(\1))
  218.     tokenize 34 %sockreader
  219.     set $+(%,ysearch.,$remove($sockname,ysearch.),.tag) $4
  220.   }
  221.   elseif (*<span class="video-time">* iswm %sockreader) {
  222.     set $+(%,ysearch.,$remove($sockname,ysearch.),.time) $nohtml($remove(%sockreader,Add to,Added,to,queue))
  223.   }
  224.   elseif (*<span class="username-prepend">* iswm %sockreader) {
  225.     set $+(%,ysearch.,$remove($sockname,ysearch.),.user) $remove($nohtml(%sockreader),by)
  226.   }
  227.   elseif (*<span class="viewcount">* iswm %sockreader) {
  228.     set $+(%,ysearch.,$remove($sockname,ysearch.),.viewcount) $remove($nohtml(%sockreader),|,views)
  229.     $($+(%,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)
  230.     unset $+(%,ysearch.,$remove($sockname,ysearch.),*)
  231.     sockclose $sockname
  232.   }
  233. }
  234. #search end
  235.  
  236. #parse on
  237. on $*:text:/youtu(.be|be.com)/Si:*: {
  238.   $iif($istok(%youtubefetch,$chan,44),halt,noop)
  239.   if ($($+(%,botflood.,$nick),2)) {
  240.     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 }
  241.     elseif ($($+(%,botflood.,$nick),2) >= 40) { msg $chan $+($nick,$chr(44)) Please Do Not Abuse The Bot. | inc -z $+(%,botflood.,$nick) 20 | halt }
  242.     else { inc -z $+(%,botflood.,$nick) 10 }
  243.   }
  244.   else { inc -z $+(%,botflood.,$nick) 10 }
  245.   var %i 1
  246.   var %ticks $ticks
  247.   while (%i <= $numtok($1-,32)) {
  248.     if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
  249.       set $+(%,youtube.,%ticks,.url) $($+($,%i),2)
  250.       set $+(%,youtube.,%ticks,.tag) $remove($strip($($+($,%i),2)),http://,www,$chr(46),youtube,com,youtu,be,/,watch?v=,$chr(31),&feature=feedu)
  251.     }
  252.     inc %i
  253.   }
  254.   if (!$istok(%youtubefetch,$chan,44)) {
  255.     set $+(%,youtube.,%ticks,.msgtype) msg $chan
  256.   }
  257.   elseif ($istok(%youtubefetch,$chan,44)) {
  258.     set $+(%,youtube.,%ticks,.msgtype) echo -a
  259.   }
  260.   if (($($+(%,youtube.,%ticks,.tag),2) != %_youtube.last) && ($($+(%,youtube.,%ticks,.tag),2) != $null)) {
  261.     set $+(%,youtube.,%ticks,.nick) $nick
  262.     set $+(%,youtube.,%ticks,.chan) $chan
  263.     set $+(%,youtube.,%ticks,.network) $network
  264.     sockopen $+(youtube.,%ticks) youtube.com 80
  265.   }
  266. }
  267.  
  268. on *:sockopen:youtube*: {
  269.   sockwrite -nt $sockname GET $+(/,watch?v=,$($+(%,youtube.,$remove($sockname,youtube.),.tag),2)) HTTP/1.1
  270.   sockwrite -nt $sockname Host: www.youtube.com
  271.   sockwrite -nt $sockname $crlf
  272. }
  273.  
  274. on *:SOCKREAD:youtube*: {
  275.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  276.   else {
  277.     var %sockreader
  278.     sockread %sockreader
  279.     if (*Location: http://www.youtube.com/verify_age?next_url=* iswm %sockreader) {
  280.       if ($($+(%,youtube.,$remove($sockname,youtube.),.msgtype),2) != echo -a) {
  281.         $($+(%,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.
  282.         halt
  283.       }
  284.       set %_youtube.last $($+(%,youtube.,$remove($sockname,youtube.),.tag),2)
  285.       unset $+(%,youtube.,$remove($sockname,youtube.),*)
  286.       sockclose youtube
  287.       halt
  288.     }
  289.     elseif (*<meta name="title"* iswm %sockreader) {
  290.       tokenize 32 %sockreader
  291.       set $+(%,youtube.,$remove($sockname,youtube.),.title) $replace($remove(%sockreader,<meta name="title" content=",">),&amp;quot;,",&amp;#39;,',&quot;,",&amp;,&,&#39;,')
  292.     }
  293.     elseif (*<span class="watch-view-count">* iswm %sockreader) {
  294.       set $+(%,youtube.,$remove($sockname,youtube.),.viewcheck) on
  295.     }
  296.     elseif (*<a id="watch-username" class="inline-block" rel="author" href="/user/* iswm %sockreader) {
  297.       set $+(%,youtube.,$remove($sockname,youtube.),.user) $nohtml(%sockreader)
  298.     }
  299.     elseif (*<a id="watch-userbanner" class="inline-block" rel="author" href="/user/* iswm %sockreader) {
  300.       tokenize 34 %sockreader
  301.       set $+(%,youtube.,$remove($sockname,youtube.),.user) $10
  302.     }
  303.     elseif ((*<strong>* iswm %sockreader) && ($($+(%,youtube.,$remove($sockname,youtube.),.viewcheck),2) == on)) {
  304.       set $+(%,youtube.,$remove($sockname,youtube.),.viewcount) $nohtml(%sockreader)
  305.       if ($($+(%,youtube.,$remove($sockname,youtube.),.msgtype),2) == echo -a) {
  306.         $($+(%,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)    
  307.       }
  308.       elseif ($($+(%,youtube.,$remove($sockname,youtube.),.msgtype),2) != echo -a) {
  309.         $($+(%,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)
  310.       }
  311.       set %_youtube.last $($+(%,youtube.,$remove($sockname,youtube.),.tag),2)
  312.       unset $+(%,youtube.,$remove($sockname,youtube.),*)
  313.       sockclose youtube
  314.     }
  315.   }
  316. }
  317. #parse end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement