;YouTube Script (Parse Vids and Search) v5.2 ;Made by nick1 ;Last edit November 27 2013 ;For help/setup type /YouTube in mIRC ;2D0 -- Open to suggestions! ;EDITS -- bug fixes (no search limit set, bolded search words), code cleanup since last version, removed checkboxes, added badword line alias -l yversion { return v5.2 } menu status,channel,query { YouTube:youtube } alias YouTube { dialog -m YouTube YouTube } dialog Youtube { title "YouTube v5.2" size -1 -1 253 166 option dbu icon $mircdirYoutube.ico, 0 link "View Script On Hawkee", 1, 3 2 59 8 button "Exit", 7, 86 153 72 12, cancel tab "About", 10, 2 9 245 141 link "YouTube Script (Parse Vids and Search) v5.2 -- Post Bugs and Feature Requests Here", 24, 23 26 208 8, tab 10 text "Last updated on November 27 2013", 19, 7 66 95 8, tab 10 text "Please post suggestions, complaints, or bugs on the hawkee link (or in chat)", 20, 7 37 188 8, tab 10 text "!commands will notice the user; @commands will be public to the channel", 13, 7 101 175 8, tab 10 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 80 208 14, tab 10 link "Click here to chat (leave a message for nick1)", 66, 58 50 110 8, tab 10 text "Use the Basic Options Tab to adjust which parts of the script will run and basic formatting options.", 23, 7 118 207 13, tab 10 button "Check for Updates", 21, 109 64 54 12, tab 10 tab "Basic Options", 2 box "Search Commands/Options", 60, 7 52 209 29, tab 2 text "youtube ; ytsearch ; ysearch ", 62, 10 60 175 8, tab 2 box "Disable Options", 5, 7 23 209 27, tab 2 check "Disable Search - Disables search commands below", 11, 11 29 133 10, tab 2 flat check "Disable Parse - Disables the script from automatically sending info", 14, 11 38 175 10, tab 2 flat box "Output Options", 9, 7 83 209 64, tab 2 check "Disable Views - Removes 'Views: '", 15, 11 90 123 10, tab 2 check "Disable Length - Removes 'Length: '", 16, 11 99 130 10, tab 2 check "Disable User - Removes 'User: '", 17, 11 108 113 10, tab 2 check "Disable Formatting - Removes Colors and Bold", 22, 11 117 127 10, tab 2 edit "", 58, 99 69 15 10, tab 2 limit 1 text "Number of search results displayed:", 25, 10 70 87 8, tab 2 check "Enable Date - Adds 'Uploaded: '", 57, 11 126 120 10, tab 2 check "Enable Rating - Adds 'Rating: '", 59, 11 136 106 9, tab 2 tab "Channel Settings", 3 list 6, 8 56 223 87, tab 3 sort size extsel vsbar edit "", 8, 9 26 155 25, tab 3 multi autohs autovs text "List of channels the script will NOT run on", 12, 48 50 101 6, tab 3 button "Add", 4, 190 25 37 12, tab 3 button "Remove", 63, 190 42 37 12, tab 3 button "Click here to enter #channels ...", 64, 10 27 153 23, tab 3 tab "Nick Settings", 26 text "List of nicks the script will NOT run for", 70, 48 50 101 6, tab 26 list 71, 8 56 223 87, tab 26 sort size extsel vsbar button "Remove", 72, 190 42 37 12, tab 26 button "Add", 73, 190 25 37 12, tab 26 edit "", 69, 9 26 155 25, tab 26 multi autohs autovs button "Click here to enter Nicks ...", 74, 10 27 153 23, tab 26 text "This script created by nick1", 18, 179 2 66 8 } on *:dialog:youtube:init:0: { FillChannelBox FillNickBox $iif(%_youtube.nocolor == true,did -c youtube 22,noop) did -a youtube 58 $iif(%_youtube.limit == $null,1,%_youtube.limit) $iif(%_youtube.noviews == true,did -c youtube 15,noop) $iif(%_youtube.nolength == true,did -c youtube 16,noop) $iif(%_youtube.nouser == true,did -c youtube 17,noop) $iif(%_youtube.date == true,did -c youtube 57,noop) $iif(%_youtube.rating == true,did -c youtube 59,noop) $iif($group(#search) != on,did -c youtube 11,noop) $iif($group(#parse) != on,did -c youtube 14,noop) } alias FillChannelBox { did -r youtube 6 var %y 1 while (%y <= $numtok(%youtubefetch,44)) { did -a youtube 6 $gettok(%youtubefetch,%y,44) inc %y } } alias FillNickBox { did -r youtube 71 var %y 1 while (%y <= $numtok(%nolinks,44)) { did -a youtube 71 $gettok(%nolinks,%y,44) inc %y } } on *:dialog:youtube:edit:58: { if (($did(58).text < 1) || ($did(58).text !isnum) && ($did(58).text != $null)) { did -r youtube 58 noop $input(Enter a number between 1 and 9, owd, Invalid input!) } elseif ($did(58).text != $null) { set %_youtube.limit $did(58).text } } on *:dialog:youtube:sclick:*: { if (($did == 1) || ($did == 24)) { run http://www.hawkee.com/snippet/8577/ } elseif ($did == 66) { server -m irc.rizon.net:6667 -jn #rsbot_help } elseif ($did == 22) { set %_youtube.nocolor $iif($did(22).state,true,false) } elseif ($did == 15) { set %_youtube.noviews $iif($did(15).state,true,false) } elseif ($did == 16) { set %_youtube.nolength $iif($did(16).state,true,false) } elseif ($did == 17) { set %_youtube.nouser $iif($did(17).state,true,false) } elseif ($did == 57) { set %_youtube.date $iif($did(57).state,true,false) } elseif ($did == 59) { set %_youtube.rating $iif($did(59).state,true,false) } elseif ($did == 11) { $iif($group(#search) == on,.disable,.enable) #search } elseif ($did == 21) { yupdate } elseif ($did == 14) { $iif($group(#parse) == on,.disable,.enable) #parse } elseif ($did == 4) { set %youtubefetch $addtok(%youtubefetch,$iif(($left($did(8),1) == $chr(35)),$did(8),$+($chr(35),$did(8))),44) did -r youtube 8 FillChannelBox } elseif ($did == 73) { set %nolinks $addtok(%nolinks,$did(69),44) did -r youtube 69 FillNickBox } elseif ($did == 63) { if ($did(8) != $null) { set %youtubefetch $remtok(%youtubefetch,$iif(($left($did(8),1) == $chr(35)),$did(8),$+($chr(35),$did(8))),44) did -r youtube 8 } if ($did(6).seltext != $null) { set %youtubefetch $remtok(%youtubefetch,$did(6).seltext,44) } FillChannelBox } elseif ($did == 3) { did -t youtube 4 } elseif ($did == 26) { did -t youtube 73 } elseif ($did == 72) { if ($did(69) != $null) { set %nolinks $remtok(%nolinks,$did(69),44) did -r youtube 69 } if ($did(71).seltext != $null) { set %nolinks $remtok(%nolinks,$did(71).seltext,44) } FillNickBox } } raw 408:*: msg $2 $remove($strip($13-),$chr(9),$chr(8)) alias urlencode { return $replacex($regsubex($$1-,/([^\w\s])/Sg,$+(%,$base($asc(\t),10,16,2))),$chr(32),+,$chr(43),%2B) } on $*:text:/^[!@](disableyt|offyt|disableyoutube|offyoutube)(\s|$)/Si:?: { if ($2) { if ($me ison $2) { if ($nick isop $2) { msg $nick 4Youtube has been10 disabled on $+(,$2,) set %youtubefetch $addtok(%youtubefetch,$2,44) } else { msg $nick 4Sorry, you must be an10 op of $+(,$2,) to disable youtube there } } else { msg $nick 4Sorry, I am not10 currently in $+(,$2,) } } elseif ($2 == $null) { msg $nick 4Incorrect Syntax - Use10 $1 <#channel> } } on $*:text:/^[!@](enableyt|onyt|enableyoutube|onyoutube)(\s|$)/Si:?: { if ($2) { if ($me ison $2) { if ($nick isop $2) { msg $nick 4Youtube has been10 enabled on $+(,$2,) set %youtubefetch $remtok(%youtubefetch,$2,44) } else { msg $nick 4Sorry, you must be an10 op of $+(,$2,) to enable youtube there } } else { msg $nick 4Sorry, I am not10 currently in $+(,$2,) } } elseif ($2 == $null) { msg $nick 4Incorrect Syntax - Use10 $1 <#channel> } } #search on on $*:text:/^[!@]y(outube|t|tsearch|search|ousearch|outubesearch)(\s|$)/Si:*: { $iif($istok(%youtubefetch,$chan,44),halt,noop) $iif($istok(%nolinks,$nick,44),halt,noop) if ($($+(%,botflood.,$nick),2)) { if ($($+(%,botflood.,$nick),2) >= 50) { ignore -u60 $address($nick,2) msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot. halt } elseif ($($+(%,botflood.,$nick),2) >= 40) { msg $chan $+($nick,$chr(44)) Please do not flood the bot. inc -z $+(%,botflood.,$nick) 20 halt } else { inc -z $+(%,botflood.,$nick) 25 } } else { inc -z $+(%,botflood.,$nick) 25 } var %ticks $ticks if ($2) { set $+(%,youtube.,%ticks,.msgtype) $iif($chan,$iif($left($strip($1),1) == @,msg $chan,notice $nick),msg $nick) set $+(%,youtube.,%ticks,.search) $2- set $+(%,youtube.,%ticks,.query) $urlencode($2-) sockopen $+(youtube.,%ticks) gdata.youtube.com 80 } elseif ($2 == $null) { notice $nick 4Incorrect Syntax - Use10 $1  } } on *:input:*:{ $iif($istok(%nolinks,$active,44),return,noop) $iif($istok(%youtubefetch,$active,44),return,noop) var %ticks $ticks 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)) { if ($left($1,1) != /) { if ($2 != $null) { set $+(%,youtube.,%ticks,.msgtype) msg $active set $+(%,youtube.,%ticks,.search) $2- set $+(%,youtube.,%ticks,.query) $urlencode($2-) sockopen $+(youtube.,%ticks) gdata.youtube.com 80 } elseif ($2 == $null) { .timerYTInputSyntax -m 1 100 echo -at 4Incorrect Syntax - Use10 $1  } } } elseif ((*youtube.com* iswm $1-) || (*youtu.be* iswm $1-)) { if ($left($1,1) != /) { var %i 1 while (%i <= $numtok($1-,32)) { if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) { set $+(%,youtube.,%ticks,.url) $strip($($+($,%i),2)) var %tag $($+(%,youtube.,%ticks,.url),2) var %tag $iif($matchtok(%tag,v=,1,38),$v1,%tag) var %tag $deltok($deltok(%tag,2,35),2,38) 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),#!,/) } inc %i } if ($($+(%,youtube.,%ticks,.tag),2) == $null) { unset $+(%,youtube.,%ticks,.*) } else { set $+(%,youtube.,%ticks,.msgtype) msg $active set $+(%,youtube.,%ticks,.nick) $nick set $+(%,youtube.,%ticks,.chan) $chan set $+(%,youtube.,%ticks,.network) $network sockopen $+(youtube.,%ticks) gdata.youtube.com 80 } } } } #search end #parse on on $*:text:/youtu(.be|be.com)/Si:*: { $iif($istok(%youtubefetch,$chan,44),halt,noop) $iif($istok(%nolinks,$nick,44),halt,noop) if ($($+(%,botflood.,$nick),2)) { if ($($+(%,botflood.,$nick),2) >= 50) { ignore -u60 $address($nick,2) msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot. halt } elseif ($($+(%,botflood.,$nick),2) >= 40) { msg $chan $+($nick,$chr(44)) Please do not flood the bot. inc -z $+(%,botflood.,$nick) 20 halt } else { inc -z $+(%,botflood.,$nick) 10 } } else { inc -z $+(%,botflood.,$nick) 10 } var %i 1 var %ticks $ticks while (%i <= $numtok($1-,32)) { if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) { set $+(%,youtube.,%ticks,.url) $strip($($+($,%i),2)) var %tag $($+(%,youtube.,%ticks,.url),2) var %tag $iif($matchtok(%tag,v=,1,38),$v1,%tag) var %tag $deltok($deltok(%tag,2,35),2,38) 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),#!,/) } inc %i } set $+(%,youtube.,%ticks,.msgtype) msg $iif($chan,$v1,$nick) if (($($+(%,youtube.,%ticks,.tag),2) != %_youtube.last) && ($($+(%,youtube.,%ticks,.tag),2) != $null)) { set $+(%,youtube.,%ticks,.nick) $nick set $+(%,youtube.,%ticks,.chan) $chan set $+(%,youtube.,%ticks,.network) $network sockopen $+(youtube.,%ticks) gdata.youtube.com 80 } } #parse end on *:sockopen:youtube*: { var %ticks $remove($sockname,youtube.) var %x sockwrite -nt $sockname if ($($+(%,youtube.,%ticks,.search),2) != $null) { %x GET $+(/feeds/api/videos?q=,$($+(%,youtube.,%ticks,.query),2),&v=2&prettyprint=true&max-results=,$iif(%_youtube.limit == $null,1,%_youtube.limit)) HTTP/1.1 } else { %x GET $+(/feeds/api/videos/,$($+(%,youtube.,%ticks,.tag),2),?v=2&prettyprint=true) HTTP/1.1 } %x Host: gdata.youtube.com %x $crlf } alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) } on *:SOCKREAD:youtube*: { if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt } else { var %ticks $remove($sockname,youtube.) var %sockreader sockread %sockreader if (** iswm %sockreader) { set $+(%,youtube.,%ticks,.title) $replace($nohtml(%sockreader),",",',',",",&,&,',',",") if ($($+(%,youtube.,%ticks,.search),2) != $null) { var %i 0 while (%i <= $numtok($($+(%,youtube.,%ticks,.search),2),32)) { inc %i set $+(%,youtube.,%ticks,.title) $regsubex($($+(%,youtube.,%ticks,.title),2), /\b( $gettok($($+(%,youtube.,%ticks,.search),2),%i,32) )\b/gix, $+($chr(2), \1, $chr(2))) } } ;Badword replacement below--useful for bots that kick on badword list. Replace or add words to censor <word,replacement> set $+(%,youtube.,%ticks,.title) $replace($($+(%,youtube.,%ticks,.title),2),faggot,f****t,black,n****r) } elseif (*<id>* iswm %sockreader) { set $+(%,youtube.,%ticks,.tag) $gettok($nohtml(%sockreader),4,58) } elseif (*<name>* iswm %sockreader) { set $+(%,youtube.,%ticks,.user) $nohtml(%sockreader) } elseif (*<yt:duration seconds='* iswm %sockreader) { var %t $duration($gettok(%sockreader,2,39),3) if (($gettok(%t,2,58) == 00) && ($gettok(%t,1,58) == 00)) { %t = $puttok(%t,0,2,58) } if (($left($gettok(%t,2,58),1) == 0) && ($right($gettok(%t,2,58),1) != 0) && ($right($gettok(%t,2,58),1) isnum)) { if ($gettok(%t,1,58) == 00) { %t = $puttok(%t,$right($gettok(%t,2,58),1),2,58) } } if (($left($gettok(%t,1,58),1) == 0) && ($right($gettok(%t,1,58),1) != 0) && ($right($gettok(%t,1,58),1) isnum)) { %t = $puttok(%t,$right($gettok(%t,1,58),1),1,58) } $iif($gettok(%t,1,58) == 00,%t = $gettok(%t,2-3,58),noop) set $+(%,youtube.,%ticks,.time) %t } elseif (*<yt:uploaded>* iswm %sockreader) { set $+(%,youtube.,%ticks,.date) $gettok($nohtml(%sockreader),1,84) } elseif (*<gd:rating* iswm %sockreader) { set $+(%,youtube.,%ticks,.rating) $round($gettok(%sockreader,2,39),1) $+ /5 } elseif (*viewCount='* iswm %sockreader) { set $+(%,youtube.,%ticks,.viewcount) $bytes($gettok(%sockreader,4,39),bd) set %_youtube.last $($+(%,youtube.,%ticks,.tag),2) var %msg 1,0You0,4Tube $& $iif($($+(%,youtube.,%ticks,.search),2) == $null,$null,10Link:4 http://youtu.be/ $+ $($+(%,youtube.,%ticks,.tag),2)) $& 10Title:4 $($+(%,youtube.,%ticks,.title),2) $& $iif(%_youtube.noviews == true,$null,10Views:4 $($+(%,youtube.,%ticks,.viewcount),2)) $& $iif(%_youtube.nolength == true,$null,10Length:4 $($+(%,youtube.,%ticks,.time),2)) $& $iif(%_youtube.rating == true,$iif($($+(%,youtube.,%ticks,.rating),2) == $null,$null,10Rating:4 $($+(%,youtube.,%ticks,.rating),2)),$null) $& $iif(%_youtube.date == true,10Uploaded:4 $($+(%,youtube.,%ticks,.date),2),$null) $& $iif(%_youtube.nouser == true,$null,10User:4 $($+(%,youtube.,%ticks,.user),2)) $($+(%,youtube.,%ticks,.msgtype),2) $iif(%_youtube.nocolor == true,$strip(%msg),%msg) inc $+(%,youtube.,%ticks,.number) if ((%_youtube.limit == $($+(%,youtube.,%ticks,.number),2)) || ($($+(%,youtube.,%ticks,.search),2) == $null)) { unset $+(%,youtube.,$remove($sockname,youtube.),*) sockclose $sockname } } elseif (*</feed>* iswm %sockreader) { if ($($+(%,youtube.,%ticks,.number),2) == $null) { var %msg 1,0You0,4Tube 10No relevant results were found. Try different search terms. $($+(%,youtube.,%ticks,.msgtype),2) $iif(%_youtube.nocolor == true,$strip(%msg),%msg) } unset $+(%,youtube.,$remove($sockname,youtube.),*) sockclose $sockname } } } on *:sockclose:youtube*: { unset $+(%,youtube.,$remove($sockname,youtube.),*) } on *:start: .timerYTUpdate 1 60 yupdate alias yupdate { echo -atc info 12[04YouTube12] Checking for updates... sockopen yupdate www.hawkee.com 80 } on *:sockopen:yupdate: { sockwrite -nt $sockname GET /snippet/8577/ HTTP/1.1 sockwrite -nt $sockname Host: www.hawkee.com sockwrite -nt $sockname $crlf } on *:SOCKREAD:yupdate: { if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt } sockread %sockreader if (*<title>* iswm %sockreader) { var %x $gettok($nohtml(%sockreader),7,32) echo -atc info 12[04YouTube12] Current: $yversion Latest: %x Status: $iif($yversion == %x,Up to date,Please update at www.hawkee.com/snippet/8577/) unset %sockreader sockclose $sockname } }