Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # +-------------------------------------------------------------------------------------+
- # | |
- # | YouTUBE Script v2.0.0 |
- # | |
- # +-------------------------------------------------------------------------------------+
- # | |
- # | *** Website @ http://www.EggdropTCL.com |
- # | *** GitHub @ http://github.com/MadaliNTCL/eggdrop-tcl |
- # | |
- # +-------------------------------------------------------------------------------------+
- # | *** IRC Support: |
- # | #EggdropTCL @ QuakeNET |
- # | #EggdropTCL @ UnderNET |
- # | #EggdropTCL @ EfNET |
- # | |
- # | *** Contact: |
- # | Yahoo Messenger/Mail: madalinmen28@yahoo.com |
- # | Google Mail : madalinmen28@gmail.com |
- # | Skype Messenger : madalinmen28 |
- # | |
- # +-------------------------------------------------------------------------------------+
- # + *** Commands *** |
- # | +---------------+ |
- # | [ OP - PUBLIC] |
- # | +---------------+ |
- # | |
- # | +++ !youtube on |
- # | +++ !youtube off |
- # | |
- # | IMPORTANT: |
- # | |
- # | 500 requests per day |
- # | You need Google Api Key |
- # | |
- # | Updates: |
- # | * v2 |
- # | -- It now catches the youtube link from /me and /ame |
- # | * minor fixes |
- # | -- Add HTML::Entities for decoding Titles |
- # | -- Convert UTF8 Titles to default codepage |
- # +-------------------------------------------------------------------------------------+
- bind PUBM - * youtube
- bind PUBM - * youtube:pubm
- bind CTCP - ACTION youtube:act
- package require json
- package require http
- package require tls
- namespace eval htmlentities {
- namespace ensemble create -subcommands {encode decode}
- variable encode {
- \u0027 '\; \u00a0  \; \u00a1 ¡\; \u00a2 ¢\; \u00a3 £\; \u00a4
- ¤\; \u00a5 ¥\; \u00a6 ¦\; \u00a7 §\; \u00a8 ¨\;
- \u00a9 ©\; \u00aa ª\; \u00ab «\; \u00ac ¬\; \u00ad
- ­\; \u00ae ®\; \u00af ¯\; \u00b0 °\; \u00b1 ±\;
- \u00b2 ²\; \u00b3 ³\; \u00b4 ´\; \u00b5 µ\; \u00b6
- ¶\; \u00b7 ·\; \u00b8 ¸\; \u00b9 ¹\; \u00ba º\;
- \u00bb »\; \u00bc ¼\; \u00bd ½\; \u00be ¾\;
- \u00bf ¿\; \u00c0 À\; \u00c1 Á\; \u00c2 Â\;
- \u00c3 Ã\; \u00c4 Ä\; \u00c5 Å\; \u00c6 Æ\; \u00c7
- Ç\; \u00c8 È\; \u00c9 É\; \u00ca Ê\; \u00cb
- Ë\; \u00cc Ì\; \u00cd Í\; \u00ce Î\; \u00cf
- Ï\; \u00d0 Ð\; \u00d1 Ñ\; \u00d2 Ò\; \u00d3
- Ó\; \u00d4 Ô\; \u00d5 Õ\; \u00d6 Ö\; \u00d7
- ×\; \u00d8 Ø\; \u00d9 Ù\; \u00da Ú\; \u00db
- Û\; \u00dc Ü\; \u00dd Ý\; \u00de Þ\; \u00df
- ß\; \u00e0 à\; \u00e1 á\; \u00e2 â\; \u00e3
- ã\; \u00e4 ä\; \u00e5 å\; \u00e6 æ\; \u00e7
- ç\; \u00e8 è\; \u00e9 é\; \u00ea ê\; \u00eb
- ë\; \u00ec ì\; \u00ed í\; \u00ee î\; \u00ef
- ï\; \u00f0 ð\; \u00f1 ñ\; \u00f2 ò\; \u00f3
- ó\; \u00f4 ô\; \u00f5 õ\; \u00f6 ö\; \u00f7
- ÷\; \u00f8 ø\; \u00f9 ù\; \u00fa ú\; \u00fb
- û\; \u00fc ü\; \u00fd ý\; \u00fe þ\; \u00ff ÿ\;
- \u0192 &fnof\; \u0391 &Alpha\; \u0392 &Beta\; \u0393 &Gamma\; \u0394
- &Delta\; \u0395 &Epsilon\; \u0396 &Zeta\; \u0397 &Eta\; \u0398 &Theta\;
- \u0399 &Iota\; \u039a &Kappa\; \u039b &Lambda\; \u039c &Mu\; \u039d
- &Nu\; \u039e &Xi\; \u039f &Omicron\; \u03a0 &Pi\; \u03a1 &Rho\; \u03a3
- &Sigma\; \u03a4 &Tau\; \u03a5 &Upsilon\; \u03a6 &Phi\; \u03a7 &Chi\;
- \u03a8 &Psi\; \u03a9 &Omega\; \u03b1 &alpha\; \u03b2 &beta\; \u03b3
- &gamma\; \u03b4 &delta\; \u03b5 &epsilon\; \u03b6 &zeta\; \u03b7 &eta\;
- \u03b8 &theta\; \u03b9 &iota\; \u03ba &kappa\; \u03bb &lambda\; \u03bc
- &mu\; \u03bd &nu\; \u03be &xi\; \u03bf &omicron\; \u03c0 &pi\; \u03c1
- &rho\; \u03c2 &sigmaf\; \u03c3 &sigma\; \u03c4 &tau\; \u03c5 &upsilon\;
- \u03c6 &phi\; \u03c7 &chi\; \u03c8 &psi\; \u03c9 &omega\; \u03d1
- &thetasym\; \u03d2 &upsih\; \u03d6 &piv\; \u2022 &bull\; \u2026
- &hellip\; \u2032 &prime\; \u2033 &Prime\; \u203e &oline\; \u2044
- &frasl\; \u2118 &weierp\; \u2111 &image\; \u211c &real\; \u2122
- &trade\; \u2135 &alefsym\; \u2190 &larr\; \u2191 &uarr\; \u2192 &rarr\;
- \u2193 &darr\; \u2194 &harr\; \u21b5 &crarr\; \u21d0 &lArr\; \u21d1
- &uArr\; \u21d2 &rArr\; \u21d3 &dArr\; \u21d4 &hArr\; \u2200 &forall\;
- \u2202 &part\; \u2203 &exist\; \u2205 &empty\; \u2207 &nabla\; \u2208
- &isin\; \u2209 ¬in\; \u220b &ni\; \u220f &prod\; \u2211 &sum\;
- \u2212 &minus\; \u2217 &lowast\; \u221a &radic\; \u221d &prop\; \u221e
- &infin\; \u2220 &ang\; \u2227 &and\; \u2228 &or\; \u2229 &cap\; \u222a
- &cup\; \u222b &int\; \u2234 &there4\; \u223c &sim\; \u2245 &cong\;
- \u2248 &asymp\; \u2260 &ne\; \u2261 &equiv\; \u2264 &le\; \u2265 &ge\;
- \u2282 &sub\; \u2283 &sup\; \u2284 &nsub\; \u2286 &sube\; \u2287
- &supe\; \u2295 &oplus\; \u2297 &otimes\; \u22a5 &perp\; \u22c5 &sdot\;
- \u2308 &lceil\; \u2309 &rceil\; \u230a &lfloor\; \u230b &rfloor\;
- \u2329 &lang\; \u232a &rang\; \u25ca &loz\; \u2660 &spades\; \u2663
- &clubs\; \u2665 &hearts\; \u2666 &diams\; \u0022 "\; \u0026 &\;
- \u003c <\; \u003e >\; \u0152 &OElig\; \u0153 &oelig\; \u0160
- &Scaron\; \u0161 &scaron\; \u0178 &Yuml\; \u02c6 &circ\; \u02dc
- &tilde\; \u2002 &ensp\; \u2003 &emsp\; \u2009 &thinsp\; \u200c &zwnj\;
- \u200d &zwj\; \u200e &lrm\; \u200f &rlm\; \u2013 &ndash\; \u2014
- &mdash\; \u2018 &lsquo\; \u2019 &rsquo\; \u201a &sbquo\; \u201c
- &ldquo\; \u201d &rdquo\; \u201e &bdquo\; \u2020 &dagger\; \u2021
- &Dagger\; \u2030 &permil\; \u2039 &lsaquo\; \u203a &rsaquo\; \u20ac
- &euro\;
- }
- variable decode [lreverse $encode]
- proc encode {string} {
- variable encode
- string map $encode $string
- }
- proc decode {string} {
- variable decode
- string map $decode $string
- }
- }
- set youtube(api) "AIzaSyDrsOKrP6_X5FIIdO9Ld4dwB_G7EH5Gtt8"
- set youtube(version) "2.0"
- setudef flag youtube
- proc youtube:pubm {nick uhost hand chan arg} {
- global temp
- if {[string index $arg 0] in {! . `}} {
- set temp(cmd) [string range $arg 1 end]
- set temp(cmd) [lindex [split $temp(cmd)] 0]
- set arg [join [lrange [split $arg] 1 end]]
- } elseif {[isbotnick [lindex [split $arg] 0]]} {
- set temp(cmd) [lindex [split $arg] 1]
- set arg [join [lrange [split $arg] 2 end]]
- } else { return 0 }
- if {[info commands ytpubm:$temp(cmd)] ne ""} { ytpubm:$temp(cmd) $nick $uhost $hand $chan $arg }
- }
- proc ytpubm:youtube {nick uhost hand chan arg} {
- global youtube tempYT
- switch -exact -- [lindex [split $arg] 0] {
- on {
- if {[isop $nick $chan] || [matchattr $hand n]} {
- channel set $chan +youtube
- putserv "PRIVMSG $chan :\002$nick\002 - \00302Set channel mode \00306+youtube\0032 on \00304$chan"
- return
- }
- }
- off {
- if {[isop $nick $chan] || [matchattr $hand n]} {
- channel set $chan -youtube
- putserv "PRIVMSG $chan :\002$nick\002 - \00302Set channel mode \00306-youtube\0032 on \00304$chan"
- return
- }
- }
- top {}
- search {
- ::http::register https 443 [list ::tls::socket -tls1 1]
- if {[catch {http::geturl "https://www.googleapis.com/youtube/v3/search?[http::formatQuery key $youtube(api) maxresults 5 part id,snippet type video order viewCount q [lindex [split $arg] 1]]"} tok]} {
- putlog "Socket error: $tok"
- return 0
- }
- if {[http::status $tok] ne "ok"} {
- set status [http::status $tok]
- putlog "TCP error: $status"
- return 0
- }
- if {[http::ncode $tok] != 200} {
- set code [http::code $tok]
- http::cleanup $tok
- putlog "HTTP Error: $code"
- return 0
- }
- set data [http::data $tok]
- set parse [::json::json2dict $data]
- set tempYT(video1) "[lindex [dict get [lindex [dict get $parse items] 0] id] 3] [lindex [dict get [lindex [dict get $parse items] 0] snippet] 5]"
- set tempYT(video2) "[lindex [dict get [lindex [dict get $parse items] 1] id] 3] [lindex [dict get [lindex [dict get $parse items] 1] snippet] 5]"
- set tempYT(video3) "[lindex [dict get [lindex [dict get $parse items] 2] id] 3] [lindex [dict get [lindex [dict get $parse items] 2] snippet] 5]"
- set tempYT(video4) "[lindex [dict get [lindex [dict get $parse items] 3] id] 3] [lindex [dict get [lindex [dict get $parse items] 3] snippet] 5]"
- set tempYT(video5) "[lindex [dict get [lindex [dict get $parse items] 4] id] 3] [lindex [dict get [lindex [dict get $parse items] 4] snippet] 5]"
- putserv "PRIVMSG $chan :\002\00301,00You\00300,04Tube\002\017 - \00304Top 5\00302 baseado no \00303viewCount\003"
- set number 0
- foreach line [array names tempYT] {
- if {[llength $line]} {
- incr number
- set id "[lindex $tempYT($line) 0]"
- set rawTitle "[join [lrange $tempYT($line) 1 end]]"
- set strTitle [htmlentities::decode $rawTitle]
- set title [encoding convertfrom utf-8 $strTitle]
- putserv "PRIVMSG $chan :$number. \00312$title\003 \037\002/\037\002 \00302Link\003: \00304https://www.youtube.com/watch?v=$id"
- }
- }
- }
- }
- }
- proc youtube:act {nick uhost hand dest key arg} {
- global ytignore youtube
- if {![channel get $dest youtube]} { return 0 }
- if {![string match -nocase *yout* $arg]} { return 0 }
- ## ++
- set floodtime 10
- ## ++
- if {![info exists ytignore($nick)]} {
- set ytignore($nick) [unixtime]
- utimer $floodtime [list unset -nocomplain ytignore($nick)]
- }
- ## ++
- if {[expr [unixtime]-$ytignore($nick)]>$floodtime} { putlog "ignoram"; return 0 }
- set youtubecheck [regexp -all -nocase {(?:\/watch\?v=|youtu\.be\/)([\d\w-]{11})} $arg match youtubeid]
- youtube:parse $youtubecheck $match $youtubeid $dest
- }
- proc youtube {nick uhost hand chan arg} {
- global ytignore youtube
- if {![channel get $chan youtube]} { return 0 }
- if {![string match -nocase *yout* $arg]} { return 0 }
- ## ++
- set floodtime 10
- ## ++
- if {![info exists ytignore($nick)]} {
- set ytignore($nick) [unixtime]
- utimer $floodtime [list unset -nocomplain ytignore($nick)]
- }
- ## ++
- if {[expr [unixtime]-$ytignore($nick)]>$floodtime} { putlog "ignoram"; return 0 }
- set youtubecheck [regexp -all -nocase {(?:\/watch\?v=|youtu\.be\/)([\d\w-]{11})} $arg match youtubeid]
- youtube:parse $youtubecheck $match $youtubeid $chan
- }
- proc youtube:parse {youtubecheck match youtubeid dest} {
- global ytignore youtube
- ::http::register https 443 [list ::tls::socket -tls1 1]
- if {[catch {http::geturl "https://www.googleapis.com/youtube/v3/videos?[http::formatQuery id $youtubeid key $youtube(api) part snippet,contentDetails,statistics,status]"} tok]} {
- putlog "Socket error: $tok"
- return 0
- }
- if {[http::status $tok] ne "ok"} {
- set status [http::status $tok]
- putlog "TCP error: $status"
- return 0
- }
- if {[http::ncode $tok] != 200} {
- set code [http::code $tok]
- http::cleanup $tok
- putlog "HTTP Error: $code"
- return 0
- }
- set data [http::data $tok]
- set parse [::json::json2dict $data]
- set playtime [lindex [dict get [lindex [dict get $parse items] 0] snippet] 1]
- set rawTitle [lindex [dict get [lindex [dict get $parse items] 0] snippet] 5]
- set viewCount [lindex [dict get [lindex [dict get $parse items] 0] statistics] 1]
- set likeCount [lindex [dict get [lindex [dict get $parse items] 0] statistics] 3]
- set dislikeCount [lindex [dict get [lindex [dict get $parse items] 0] statistics] 5]
- set commentCount [lindex [dict get [lindex [dict get $parse items] 0] statistics] 9]
- set publishedAt [lindex [dict get [lindex [dict get $parse items] 0] snippet] 1]
- set publishedAt [string map [list "T" " " ".000Z" ""] $publishedAt]
- set duration [lindex [dict get [lindex [dict get $parse items] 0] contentDetails] 1]
- set duration [string map [list "PT" "" "M" "m " "S" "s"] $duration]
- set definition [string toupper [lindex [dict get [lindex [dict get $parse items] 0] contentDetails] 5]]
- set strTitle [htmlentities::decode $rawTitle]
- set title [encoding convertfrom utf-8 $strTitle]
- putserv "PRIVMSG $dest :\002\00301,00You\00300,04Tube\002\017 \00312$title\003 \002\00304$definition\003\002 \037\002/\002\037 \00302Views\003: \00303[youtube:convert $viewCount]\003 \037\002/\002\037 \00302Likes\003: \00310[youtube:convert $likeCount]\003 \037\002/\002\037 \00302Dislikes\003: \00304[youtube:convert $dislikeCount]\003 \037\002/\002\037 \00302Comments\003: \00304[youtube:convert $commentCount]\003 \037\002/\002\037 \00302Duration: \00304$duration\003 \037\002/\002\037 \00302Published at: \00304$publishedAt"
- }
- proc youtube:convert {num} { while {[regsub {^([-+]?\d+)(\d\d\d)} $num "\\1.\\2" num]} {}; return $num }
- putlog "++ \[ - \00304PUBLIC\003 - \00306loaded\003 * \00303YouTUBE\003 \]"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement