Advertisement
illpastethat

YouTube Script (Parse Vids and Search) v6.3

May 6th, 2016
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 22.42 KB | None | 0 0
  1. ;YouTube Script (Parse Vids and Search) v6.3
  2. ;Made by nick1
  3. ;Last edit May 06, 2016
  4. ;For help/setup type /YouTube in mIRC
  5. ;2D0 -- You tell me in the comments! http://hawkee.com/snippet/8577/
  6. ;EDITS -- Update check message only appears if needs an update, fixed &feature=youtu.be bug, doesn't parse channel links
  7. ;EDITS -- better variable cleanup, multiple search results displayed
  8.  
  9. alias -l yversion { return v6.3 }
  10. alias -l yapi { return AIzaSyBZFSgBuREDKNRwHqvHix68W3WiMyZ3N6c }
  11.  
  12. menu status,channel,query {
  13.   YouTube:youtube
  14. }
  15.  
  16. alias YouTube { dialog -m YouTube YouTube }
  17.  
  18. dialog Youtube {
  19.   title "YouTube v6.3"
  20.   size -1 -1 242 196
  21.   option dbu
  22.   icon $mircdirYoutube.ico, 0
  23.   link "View Script On Hawkee", 1, 3 2 59 8
  24.   button "Exit", 7, 88 181 72 12, cancel
  25.   tab "About", 10, 2 9 235 169
  26.   link "YouTube Script (Parse Vids and Search) v6.3 -- Post Bugs and Feature Requests Here", 24, 16 26 208 8, tab 10
  27.   text "Last updated on May 06 2016", 19, 7 66 95 8, tab 10
  28.   text "Please post suggestions, complaints, or bugs on the hawkee link (or in chat)", 20, 7 37 188 8, tab 10
  29.   text "!commands will notice the user; @commands will be public to the channel", 13, 7 93 175 8, tab 10
  30.   text "Default behavior is to run on every channel for every nick. Use the Nick and Channel Settings Tabs to change it for invidividual channels or nicks.", 65, 7 114 208 14, tab 10
  31.   link "Click here to chat (leave a message for nick1)", 66, 58 50 110 8, tab 10
  32.   text "Use the Basic Options Tab to adjust which parts of the script will run and basic formatting options.", 23, 7 142 195 13, tab 10
  33.   button "Check for Updates", 21, 102 64 54 12, tab 10
  34.   tab "Basic Options", 2
  35.   box "Search Commands/Options", 60, 7 52 209 29, tab 2
  36.   text "youtube <search terms>; ytsearch <search>; ysearch <search terms>", 62, 10 60 175 8, tab 2
  37.   box "Disable Options", 5, 7 23 209 27, tab 2
  38.   check "Disable Search - Disables search commands below", 11, 11 29 133 10, tab 2 flat
  39.   check "Disable Parse - Disables the script from automatically sending info", 14, 11 38 175 10, tab 2 flat
  40.   box "Output Options", 9, 7 83 209 93, tab 2
  41.   check "Disable Views - Removes 'Views: <Views>'", 15, 11 90 123 10, tab 2
  42.   check "Disable Length - Removes 'Length: <Length>'", 16, 11 99 130 10, tab 2
  43.   check "Disable User - Removes 'User: <User>'", 17, 11 108 113 10, tab 2
  44.   check "Disable Formatting - Removes Colors and Bold", 22, 11 117 127 10, tab 2
  45.   edit "", 58, 99 69 15 10, tab 2 limit 1
  46.   text "Number of search results displayed:", 25, 10 70 87 8, tab 2
  47.   check "Enable Date - Adds 'Uploaded: <Date>'", 57, 11 126 120 10, tab 2
  48.   check "Enable Likes - Adds 'Likes: <Likes>", 27, 11 135 130 10, tab 2
  49.   check "Enable Dislikes - Adds 'Dislikes: <Dislikes>", 28, 11 144 130 10, tab 2
  50.   check "Enable Description - Adds 'Description <Description>", 29, 11 153 139 10, tab 2
  51.   check "Enable Notice Mode (Does Not Message Channel)", 30, 11 163 139 10, tab 2
  52.   tab "Channel Settings", 3
  53.   list 6, 8 56 220 116, tab 3 sort size extsel vsbar
  54.   edit "", 8, 9 26 155 25, tab 3 multi autohs autovs
  55.   text "List of channels the script will NOT run on", 12, 48 50 101 6, tab 3
  56.   button "Add", 4, 190 25 37 12, tab 3
  57.   button "Remove", 63, 190 42 37 12, tab 3
  58.   button "Click here to enter #channels ...", 64, 10 27 153 23, tab 3
  59.   tab "Nick Settings", 26
  60.   text "List of nicks the script will NOT run for", 70, 48 50 101 6, tab 26
  61.   list 71, 8 56 220 116, tab 26 sort size extsel vsbar
  62.   button "Remove", 72, 190 42 37 12, tab 26
  63.   button "Add", 73, 190 25 37 12, tab 26
  64.   edit "", 69, 9 26 155 25, tab 26 multi autohs autovs
  65.   button "Click here to enter Nicks ...", 74, 10 27 153 23, tab 26
  66.   text "This script created by nick1", 18, 171 2 66 8
  67. }
  68.  
  69. on *:dialog:youtube:init:0: {
  70.   FillChannelBox
  71.   FillNickBox
  72.   $iif(%_youtube.nocolor == true,did -c youtube 22,noop)
  73.   did -a youtube 58 $iif(%_youtube.limit == $null,1,%_youtube.limit)
  74.   $iif(%_youtube.noviews == true,did -c youtube 15,noop)
  75.   $iif(%_youtube.nolength == true,did -c youtube 16,noop)
  76.   $iif(%_youtube.nouser == true,did -c youtube 17,noop)
  77.   $iif(%_youtube.date == true,did -c youtube 57,noop)
  78.   $iif(%_youtube.likes == true,did -c youtube 27,noop)
  79.   $iif(%_youtube.dislikes == true,did -c youtube 28,noop)
  80.   $iif(%_youtube.description == true,did -c youtube 29,noop)
  81.   $iif(%_youtube.notices == true,did -c youtube 30,noop)
  82.   $iif($group(#search) != on,did -c youtube 11,noop)
  83.   $iif($group(#parse) != on,did -c youtube 14,noop)  
  84. }
  85. alias FillChannelBox {
  86.   did -r youtube 6
  87.   var %y 1
  88.   while (%y <= $numtok(%youtubefetch,44)) {
  89.     did -a youtube 6 $gettok(%youtubefetch,%y,44)
  90.     inc %y
  91.   }
  92. }
  93. alias FillNickBox {
  94.   did -r youtube 71
  95.   var %y 1
  96.   while (%y <= $numtok(%nolinks,44)) {
  97.     did -a youtube 71 $gettok(%nolinks,%y,44)
  98.     inc %y
  99.   }
  100. }
  101. on *:dialog:youtube:edit:58: {
  102.   if (($did(58).text < 1) || ($did(58).text !isnum) && ($did(58).text != $null)) {
  103.     did -r youtube 58
  104.     noop $input(Enter a number between 1 and 9, owd, Invalid input!)
  105.   }
  106.   elseif ($did(58).text != $null) { set %_youtube.limit $did(58).text }
  107. }
  108. on *:dialog:youtube:sclick:*: {
  109.   if (($did == 1) || ($did == 24)) { run http://hawkee.com/snippet/8577/ }
  110.   elseif ($did == 66) { server -m irc.rizon.net:6667 -jn #rsbot_help }
  111.   elseif ($did == 22) { set %_youtube.nocolor $iif($did(22).state,true,false) }
  112.   elseif ($did == 15) { set %_youtube.noviews $iif($did(15).state,true,false) }
  113.   elseif ($did == 16) { set %_youtube.nolength $iif($did(16).state,true,false) }
  114.   elseif ($did == 17) { set %_youtube.nouser $iif($did(17).state,true,false) }
  115.   elseif ($did == 57) { set %_youtube.date $iif($did(57).state,true,false) }
  116.   elseif ($did == 27) { set %_youtube.likes $iif($did(27).state,true,false) }
  117.   elseif ($did == 28) { set %_youtube.dislikes $iif($did(28).state,true,false) }
  118.   elseif ($did == 29) { set %_youtube.description $iif($did(29).state,true,false) }
  119.   elseif ($did == 30) { set %_youtube.notices $iif($did(30).state,true,false) }
  120.   elseif ($did == 11) { $iif($group(#search) == on,.disable,.enable) #search }
  121.   elseif ($did == 21) { yupdate }
  122.   elseif ($did == 14) { $iif($group(#parse) == on,.disable,.enable) #parse }
  123.   elseif ($did == 4) {
  124.     set %youtubefetch $addtok(%youtubefetch,$iif(($left($did(8),1) == $chr(35)),$did(8),$+($chr(35),$did(8))),44)
  125.     did -r youtube 8
  126.     FillChannelBox
  127.   }
  128.   elseif ($did == 73) {
  129.     set %nolinks $addtok(%nolinks,$did(69),44)
  130.     did -r youtube 69
  131.     FillNickBox
  132.   }
  133.   elseif ($did == 63) {
  134.     if ($did(8) != $null) {
  135.       set %youtubefetch $remtok(%youtubefetch,$iif(($left($did(8),1) == $chr(35)),$did(8),$+($chr(35),$did(8))),44)
  136.       did -r youtube 8
  137.     }
  138.     if ($did(6).seltext != $null) { set %youtubefetch $remtok(%youtubefetch,$did(6).seltext,44) }
  139.     FillChannelBox
  140.   }
  141.   elseif ($did == 3) { did -t youtube 4 }
  142.   elseif ($did == 26) { did -t youtube 73 }
  143.   elseif ($did == 72) {
  144.     if ($did(69) != $null) {
  145.       set %nolinks $remtok(%nolinks,$did(69),44)
  146.       did -r youtube 69
  147.     }
  148.     if ($did(71).seltext != $null) { set %nolinks $remtok(%nolinks,$did(71).seltext,44) }
  149.     FillNickBox
  150.   }
  151. }
  152.  
  153. raw 408:*: msg $2 $remove($strip($13-),$chr(9),$chr(8))
  154.  
  155. alias urlencode { return $replacex($regsubex($$1-,/([^\w\s])/Sg,$+(%,$base($asc(\t),10,16,2))),$chr(32),+,$chr(43),%2B) }
  156.  
  157. on $*:text:/^[!@](disableyt|offyt|disableyoutube|offyoutube)(\s|$)/Si:?: {
  158.   if ($2) {
  159.     if ($me ison $2) {
  160.       if ($nick isop $2) {
  161.         msg $nick 4Youtube has been10 disabled on $+(,$2,)
  162.         set %youtubefetch $addtok(%youtubefetch,$2,44)
  163.       }
  164.       else { msg $nick 4Sorry, you must be an10 op of $+(,$2,) to disable youtube there }
  165.     }
  166.     else { msg $nick 4Sorry, I am not10 currently in $+(,$2,) }
  167.   }
  168.   elseif ($2 == $null) { msg $nick 4Incorrect Syntax - Use10 $1 <#channel> }
  169. }
  170. on $*:text:/^[!@](enableyt|onyt|enableyoutube|onyoutube)(\s|$)/Si:?: {
  171.   if ($2) {
  172.     if ($me ison $2) {
  173.       if ($nick isop $2) {
  174.         msg $nick 4Youtube has been10 enabled on $+(,$2,)
  175.         set %youtubefetch $remtok(%youtubefetch,$2,44)
  176.       }
  177.       else { msg $nick 4Sorry, you must be an10 op of $+(,$2,) to enable youtube there }
  178.     }
  179.     else { msg $nick 4Sorry, I am not10 currently in $+(,$2,) }
  180.   }
  181.   elseif ($2 == $null) { msg $nick 4Incorrect Syntax - Use10 $1 <#channel> }
  182. }
  183.  
  184. #search on
  185. on $*:text:/^[!@]y(outube|t|tsearch|search|ousearch|outubesearch)(\s|$)/Si:*: {
  186.   $iif($istok(%youtubefetch,$chan,44),halt,noop)
  187.   $iif($istok(%nolinks,$nick,44),halt,noop)
  188.   if ($($+(%,botflood.,$nick),2)) {
  189.     if ($($+(%,botflood.,$nick),2) >= 50) {
  190.       ignore -u60 $address($nick,2)
  191.       msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot.
  192.       halt
  193.     }
  194.     elseif ($($+(%,botflood.,$nick),2) >= 40) {
  195.       msg $chan $+($nick,$chr(44)) Please do not flood the bot.
  196.       inc -z $+(%,botflood.,$nick) 20
  197.       halt
  198.     }
  199.     else { inc -z $+(%,botflood.,$nick) 25 }
  200.   }
  201.   else { inc -z $+(%,botflood.,$nick) 25 }
  202.   var %ticks $ticks
  203.   if ($2) {
  204.     if ($chan) {
  205.       if (($left($strip($1),1) == @) && (%_youtube.notices != true)) { set $+(%,youtube.,%ticks,.msgtype) msg $chan }
  206.       else { set $+(%,youtube.,%ticks,.msgtype) notice $nick }
  207.     }
  208.     else { set $+(%,youtube.,%ticks,.msgtype) msg $nick }
  209.     set $+(%,youtube.,%ticks,.search) $2-
  210.     set $+(%,youtube.,%ticks,.query) $urlencode($2-)
  211.     sockopen -e $+(youtube.,%ticks) www.googleapis.com 443
  212.   }
  213.   elseif ($2 == $null) {
  214.     notice $nick 4Incorrect Syntax - Use10 $1 <search term>
  215.   }
  216. }
  217.  
  218. on *:input:*:{
  219.   $iif($istok(%nolinks,$active,44),return,noop)
  220.   $iif($istok(%youtubefetch,$active,44),return,noop)
  221.   var %ticks $ticks
  222.   if (($remove($1,$left($strip($1),1)) == ysearch) || ($remove($1,$left($strip($1),1)) == ytsearch) || ($remove($1,$left($strip($1),1)) == youtube) || ($remove($1,$left($strip($1),1)) == yt) || ($remove($1,$left($strip($1),1)) == youtubesearch)) {
  223.     if ($left($1,1) != /) {
  224.       if ($2 != $null) {
  225.         set $+(%,youtube.,%ticks,.msgtype) msg $active
  226.         set $+(%,youtube.,%ticks,.search) $2-
  227.         set $+(%,youtube.,%ticks,.query) $urlencode($2-)
  228.         sockopen -e $+(youtube.,%ticks) www.googleapis.com 443
  229.       }
  230.       elseif ($2 == $null) {
  231.         .timerYTInputSyntax -m 1 100 echo -at 4Incorrect Syntax - Use10 $1 <search term>
  232.       }
  233.     }
  234.   }
  235.   elseif ((*youtube.com* iswm $1-) || (*youtu.be* iswm $1-)) {
  236.     if ($left($1,1) != /) {
  237.       var %i 1
  238.       while (%i <= $numtok($1-,32)) {
  239.         if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
  240.           if (*/playlist* iswm $($+($,%i),2)) { halt }
  241.           set $+(%,youtube.,%ticks,.url) $strip($($+($,%i),2))
  242.           var %tag $($+(%,youtube.,%ticks,.url),2)
  243.           var %tag $iif($numtok(%tag,46) > 1,$gettok(%tag,$calc($numtok(%tag,46)-1) - $numtok(%tag,46),46),%tag)
  244.           var %tag $iif($matchtok(%tag,v=,1,38),$v1,%tag)
  245.           var %tag $deltok($deltok(%tag,2,35),2,38)
  246.           if (*youtu.be* iswm %tag) { var %tag $gettok(%tag,1,63) }
  247.           set $+(%,youtube.,%ticks,.tag) $remove(%tag,com/watch?v=,youtube.,$chr(40),$chr(41),?,m.,v=,/watch?src_vid=,https://,http://,www.,/v/,youtube.com,youtu.be,youtu.be/,/watch?v=,/watch,?v=,$chr(31),#!,/)
  248.         }
  249.         inc %i
  250.       }
  251.       if (($($+(%,youtube.,%ticks,.tag),2) == $null) || (*/channel/* iswm $($+(%,youtube.,%ticks,.url),2)) || (*/user/* iswm $($+(%,youtube.,%ticks,.url),2))) {
  252.         unset $+(%,youtube.,%ticks,.*)
  253.       }
  254.       else {
  255.         set $+(%,youtube.,%ticks,.msgtype) $iif(%_youtube.notices == true,echo -a,msg $active)
  256.         set $+(%,youtube.,%ticks,.nick) $nick
  257.         set $+(%,youtube.,%ticks,.chan) $chan
  258.         set $+(%,youtube.,%ticks,.network) $network
  259.         sockopen -e $+(youtube.,%ticks) www.googleapis.com 443
  260.       }
  261.     }
  262.   }
  263. }
  264.  
  265. #search end
  266.  
  267. #parse on
  268. on $*:text:/youtu(.be|be.com)/Si:*: {
  269.   $iif($istok(%youtubefetch,$chan,44),halt,noop)
  270.   $iif($istok(%nolinks,$nick,44),halt,noop)
  271.   if ($($+(%,botflood.,$nick),2)) {
  272.     if ($($+(%,botflood.,$nick),2) >= 50) {
  273.       ignore -u60 $address($nick,2)
  274.       msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot.
  275.       halt
  276.     }
  277.     elseif ($($+(%,botflood.,$nick),2) >= 40) {
  278.       msg $chan $+($nick,$chr(44)) Please do not flood the bot.  
  279.       inc -z $+(%,botflood.,$nick) 20
  280.       halt
  281.     }
  282.     else {
  283.       inc -z $+(%,botflood.,$nick) 10
  284.     }
  285.   }
  286.   else { inc -z $+(%,botflood.,$nick) 10 }
  287.   var %i 1
  288.   var %ticks $ticks
  289.   while (%i <= $numtok($1-,32)) {
  290.     if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
  291.       if (*/playlist* iswm $($+($,%i),2)) { halt }
  292.       set $+(%,youtube.,%ticks,.url) $strip($($+($,%i),2))
  293.       var %tag $($+(%,youtube.,%ticks,.url),2)
  294.       var %tag $iif($matchtok(%tag,v=,1,38),$v1,%tag)
  295.       var %tag $deltok($deltok(%tag,2,35),2,38)
  296.       if (*youtu.be* iswm %tag) { var %tag $gettok(%tag,1,63) }
  297.       set $+(%,youtube.,%ticks,.tag) $remove(%tag,com/watch?v=,youtube.,?,m.,v=,/watch?src_vid=,https://,http://,www.,/v/,youtube.com,youtu.be,youtu.be/,/watch?v=,/watch,?v=,$chr(31),#!,/)
  298.     }
  299.     inc %i
  300.   }
  301.   if ($chan) {
  302.     if (%_youtube.notices != true) { set $+(%,youtube.,%ticks,.msgtype) msg $chan }
  303.     else { set $+(%,youtube.,%ticks,.msgtype) notice $nick }
  304.   }
  305.   else { set $+(%,youtube.,%ticks,.msgtype) msg $nick }
  306.   if (($($+(%,youtube.,%ticks,.tag),2) == %_youtube.last) || ($($+(%,youtube.,%ticks,.tag),2) == $null) || (*/channel/* iswm $($+(%,youtube.,%ticks,.url),2)) || (*/user/* iswm $($+(%,youtube.,%ticks,.url),2))) {
  307.     unset $+(%,youtube.,%ticks,.*)
  308.   }
  309.   else {
  310.     set $+(%,youtube.,%ticks,.nick) $nick
  311.     set $+(%,youtube.,%ticks,.chan) $chan
  312.     set $+(%,youtube.,%ticks,.network) $network
  313.     sockopen -e $+(youtube.,%ticks) www.googleapis.com 443
  314.   }
  315.   else { .timerYoutubeVarDelete 1 1 unset $+(%,youtube.,%ticks,.*) }
  316. }
  317. on $*:action:/youtu(.be|be.com)/Si:*: {
  318.   $iif($istok(%youtubefetch,$chan,44),halt,noop)
  319.   $iif($istok(%nolinks,$nick,44),halt,noop)
  320.   if ($($+(%,botflood.,$nick),2)) {
  321.     if ($($+(%,botflood.,$nick),2) >= 50) {
  322.       ignore -u60 $address($nick,2)
  323.       msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot.
  324.       halt
  325.     }
  326.     elseif ($($+(%,botflood.,$nick),2) >= 40) {
  327.       msg $chan $+($nick,$chr(44)) Please do not flood the bot.  
  328.       inc -z $+(%,botflood.,$nick) 20
  329.       halt
  330.     }
  331.     else {
  332.       inc -z $+(%,botflood.,$nick) 10
  333.     }
  334.   }
  335.   else { inc -z $+(%,botflood.,$nick) 10 }
  336.   var %i 1
  337.   var %ticks $ticks
  338.   while (%i <= $numtok($1-,32)) {
  339.     if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
  340.       set $+(%,youtube.,%ticks,.url) $strip($($+($,%i),2))
  341.       var %tag $($+(%,youtube.,%ticks,.url),2)
  342.       var %tag $iif($numtok(%tag,46) > 1,$gettok(%tag,$calc($numtok(%tag,46)-1) - $numtok(%tag,46),46),%tag)
  343.       var %tag $iif($matchtok(%tag,v=,1,38),$v1,%tag)
  344.       var %tag $deltok($deltok(%tag,2,35),2,38)
  345.       if (*youtu.be* iswm %tag) { var %tag $gettok(%tag,1,63) }
  346.       set $+(%,youtube.,%ticks,.tag) $remove(%tag,$chr(40),$chr(41),?,m.,v=,/watch?src_vid=,https://,http://,www.,/v/,youtube.com,youtu.be,youtu.be/,/watch?v=,/watch,?v=,$chr(31),#!,/)
  347.     }
  348.     inc %i
  349.   }
  350.   set $+(%,youtube.,%ticks,.msgtype) msg $iif($chan,$v1,$nick)
  351.   if (($($+(%,youtube.,%ticks,.tag),2) != %_youtube.last) && ($($+(%,youtube.,%ticks,.tag),2) != $null)) {
  352.     set $+(%,youtube.,%ticks,.nick) $nick
  353.     set $+(%,youtube.,%ticks,.chan) $chan
  354.     set $+(%,youtube.,%ticks,.network) $network
  355.     sockopen -e $+(youtube.,%ticks) www.googleapis.com 443
  356.   }
  357.   else { .timerYoutubeVarDelete 1 1 unset $+(%,youtube.,%ticks,.*) }
  358. }
  359.  
  360. #parse end
  361.  
  362. on *:sockopen:youtube*: {
  363.   var %ticks $remove($sockname,youtube.)
  364.   var %x sockwrite -nt $sockname
  365.   if (($($+(%,youtube.,%ticks,.search),2) != $null) && ($($+(%,youtube.,%ticks,.round2),2) != true)) {
  366.     var %temp_search0 /youtube/v3/search?safeSearch=none&order=relevance&part=snippet&q=
  367.     %x GET $+(%temp_search0,$($+(%,youtube.,%ticks,.query),2),&maxResults=,$iif(%_youtube.limit == $null,1,%_youtube.limit),&key=,$yapi) HTTP/1.1
  368.   }
  369.   else {
  370.     var %temp_search1 $(/youtube/v3/videos?part=contentDetails%2Cstatistics%2Csnippet&id=,0)
  371.     var %temp_search2 &maxResults=1&fields=items $+ $chr(40) $+ $(contentDetails%2Csnippet%2Cstatistics,0) $+ $chr(41)
  372.     %x GET $+(%temp_search1,$($+(%,youtube.,%ticks,.tag),2),%temp_search2,&key=,$yapi) HTTP/1.1
  373.   }
  374.   %x Host: www.googleapis.com
  375.   %x $crlf
  376. }
  377. alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }
  378. alias yinfo {
  379.   var %step1 errRemoval $gettok($1-,2-,58) errRemoval
  380.   return $replace($gettok(%step1,$+(2-,$calc($numtok(%step1,34) - 1)),34),\r\n,$chr(32),\n,$chr(32),\","))
  381. }
  382. on *:SOCKREAD:youtube*: {
  383.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  384.   else {
  385.     var %ticks $gettok($sockname,2,46)
  386.     var %sockreader
  387.     sockread %sockreader
  388.     if ((*"title": * iswm %sockreader) && ($($+(%,youtube.,%ticks,.title),2) == $null)) {
  389.       set $+(%,youtube.,%ticks,.title) $yinfo(%sockreader)
  390.       if ($($+(%,youtube.,%ticks,.search),2) != $null) {
  391.         var %i 0
  392.         while (%i <= $numtok($($+(%,youtube.,%ticks,.search),2),32)) {
  393.           inc %i
  394.           set $+(%,youtube.,%ticks,.title) $regsubex($($+(%,youtube.,%ticks,.title),2), /\b( $gettok($($+(%,youtube.,%ticks,.search),2),%i,32) )\b/gix, $+($chr(2), \1, $chr(2)))
  395.         }
  396.       }
  397.       ;Badword replacement below--useful for bots that kick on badword list. Replace or add words to censor <word,replacement>
  398.       set $+(%,youtube.,%ticks,.title) $replace($($+(%,youtube.,%ticks,.title),2),faggot,f****t,nigger,n****r)
  399.     }
  400.     elseif (*"videoId": * iswm %sockreader) {
  401.       var %temp $ticks
  402.       set $+(%,youtube.,%temp,.round2) true
  403.       set $+(%,youtube.,%temp,.search) $($+(%,youtube.,%ticks,.search),2)
  404.       set $+(%,youtube.,%temp,.query) $($+(%,youtube.,%ticks,.query),2)
  405.       set $+(%,youtube.,%temp,.msgtype) $($+(%,youtube.,%ticks,.msgtype),2)
  406.       set $+(%,youtube.,%temp,.tag) $yinfo(%sockreader)
  407.       sockopen -e $+(youtube.,%temp) www.googleapis.com 443
  408.       inc $+(%,youtube.,%ticks,.number)
  409.       if (%_youtube.limit == $($+(%,youtube.,%ticks,.number),2)) {
  410.         unset $+(%,youtube.,$remove($sockname,youtube.),*)
  411.         sockclose $sockname
  412.       }
  413.     }
  414.     elseif (*channelTitle": * iswm %sockreader) { set $+(%,youtube.,%ticks,.user) $yinfo(%sockreader) }
  415.     elseif (*"duration": * iswm %sockreader) {
  416.       set $+(%,youtube.,%ticks,.time) $regsubex($duration($calc($replace( $remove($yinfo(%sockreader), P, T), W, *604800+, D, *86400+, H, *3600+, M, *60+, S,*1)), 3), /^[0:]+, )
  417.     }
  418.     elseif (*"publishedAt": * iswm %sockreader) { set $+(%,youtube.,%ticks,.date) $gettok($yinfo(%sockreader),1,84) }
  419.     elseif ((*"description": * iswm %sockreader) && ($($+(%,youtube.,%ticks,.description),2) == $null)) {
  420.       var %wrong errRemoval ", errRemoval
  421.       var %desc $yinfo(%sockreader)
  422.       if (($gettok(%sockreader,4,34) == $null) || (%desc == %wrong)) { set $+(%,youtube.,%ticks,.description) N/A }
  423.       else { set $+(%,youtube.,%ticks,.description) $iif($numtok(%desc,32) > 10,$+($gettok(%desc,1-8,32),...),%desc) }
  424.     }
  425.     elseif (*"viewCount": * iswm %sockreader) { set $+(%,youtube.,%ticks,.viewcount) $bytes($yinfo(%sockreader),bd) }
  426.     elseif (*"likeCount": * iswm %sockreader) { set $+(%,youtube.,%ticks,.likes) $bytes($yinfo(%sockreader),bd) }
  427.     elseif (*"dislikeCount": * iswm %sockreader) || (($($+(%,youtube.,%ticks,.viewcount),2) != $null) && (*}* iswm %sockreader)) {
  428.       set $+(%,youtube.,%ticks,.dislikes) $bytes($yinfo(%sockreader),bd)
  429.       set %_youtube.last $($+(%,youtube.,%ticks,.tag),2)
  430.       $iif($($+(%,youtube.,%ticks,.viewcount),2) == 301,set $+(%,youtube.,%ticks,.viewcount) 301+,noop)
  431.       var %msg 1,0You0,4Tube $&
  432.         $iif($($+(%,youtube.,%ticks,.search),2) ==  $null,$null,10Link:4 http://youtu.be/ $+ $($+(%,youtube.,%ticks,.tag),2)) $&
  433.         10Title:4 $($+(%,youtube.,%ticks,.title),2) $&
  434.         $iif(%_youtube.noviews == true,$null,10Views:4 $($+(%,youtube.,%ticks,.viewcount),2)) $&
  435.         $iif(%_youtube.nolength == true,$null,10Length:4 $($+(%,youtube.,%ticks,.time),2)) $&
  436.         $iif(%_youtube.date == true,10Uploaded:4 $($+(%,youtube.,%ticks,.date),2),$null) $&
  437.         $iif(%_youtube.nouser == true,$null,10User:4 $($+(%,youtube.,%ticks,.user),2)) $&
  438.         $iif(%_youtube.likes == true,10Likes:4 $($+(%,youtube.,%ticks,.likes),2),$null) $&
  439.         $iif(%_youtube.dislikes == true,10Dislikes:4 $($+(%,youtube.,%ticks,.dislikes),2),$null) $&
  440.         $iif(%_youtube.description == true,10Description:4 $($+(%,youtube.,%ticks,.description),2),$null)
  441.       var %msg = $remove(%msg,$chr(9))
  442.       $($+(%,youtube.,%ticks,.msgtype),2) $iif(%_youtube.nocolor == true,$strip(%msg),%msg)
  443.       unset $+(%,youtube.,$remove($sockname,youtube.),*)
  444.       sockclose $sockname
  445.     }
  446.     elseif (*"totalResults": 0,* iswm %sockreader) {
  447.       var %msg 1,0You0,4Tube 10No relevant results were found. Try different search terms.
  448.       $($+(%,youtube.,%ticks,.msgtype),2) $iif(%_youtube.nocolor == true,$strip(%msg),%msg)
  449.  
  450.       unset $+(%,youtube.,$remove($sockname,youtube.),*)
  451.       sockclose $sockname
  452.     }
  453.     elseif (*"items": []* iswm %sockreader) {
  454.       var %msg 1,0You0,4Tube 10This video was removed or is no longer available.
  455.       $($+(%,youtube.,%ticks,.msgtype),2) $iif(%_youtube.nocolor == true,$strip(%msg),%msg)
  456.       unset $+(%,youtube.,$remove($sockname,youtube.),*)
  457.       sockclose $sockname
  458.     }
  459.   }
  460. }
  461. on *:sockclose:youtube*: { unset $+(%,youtube.,$remove($sockname,youtube.),*) }
  462. on *:start: .timerYTUpdate 1 60 yupdate
  463. alias yupdate {
  464.   unset %youtube.* | unset %ysearch.*
  465.   ;echo -atc info 12[04YouTube12] Checking for updates and clearing variables...
  466.   sockopen yupdate hawkee.com 80
  467. }
  468. on *:sockopen:yupdate: {  
  469.   var %x sockwrite -nt $sockname
  470.   %x GET /snippet/8577/ HTTP/1.1
  471.   %x Host: hawkee.com
  472.   %x $crlf
  473. }
  474. on *:SOCKREAD:yupdate: {
  475.   if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  476.   sockread %sockreader
  477.   if (*<title>* iswm %sockreader) {
  478.     var %x $remove($gettok($nohtml(%sockreader),7-,32),- mIRC)
  479.     if ($yversion != %x) {
  480.       echo -atc info 12[04YouTube12] Current: $yversion Latest: %x Status: Please check for updates at http://hawkee.com/snippet/8577/
  481.     }
  482.     unset %sockreader
  483.     sockclose $sockname
  484.   }
  485. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement