Advertisement
illpastethat

YouTube Script (Parse Vids and Search) v2.6b

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