Advertisement
illpastethat

YouTube Script (Parse Vids and Search) v4.9

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