Advertisement
Chewbakka85

Youtubetitle Solid

Dec 8th, 2020
1,642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 10.20 KB | None | 0 0
  1. # +-------------------------------------------------------------------------------------+
  2. # |                                                                                     |
  3. # |                         YouTUBE Script v2.0.0                                       |
  4. # |                                                                                     |
  5. # +-------------------------------------------------------------------------------------+
  6. # |                                                                                     |
  7. # | *** Website             @  http://www.EggdropTCL.com                                |
  8. # | *** GitHub              @  http://github.com/MadaliNTCL/eggdrop-tcl                 |
  9. # |                                                                                     |
  10. # +-------------------------------------------------------------------------------------+
  11. # | *** IRC Support:                                                                    |
  12. # |                    #EggdropTCL     @ QuakeNET                                       |
  13. # |                    #EggdropTCL     @ UnderNET                                       |
  14. # |                    #EggdropTCL     @ EfNET                                          |
  15. # |                                                                                     |
  16. # | *** Contact:                                                                        |
  17. # |                    Yahoo Messenger/Mail: madalinmen28@yahoo.com                     |
  18. # |                    Google Mail         : madalinmen28@gmail.com                     |
  19. # |                    Skype Messenger     : madalinmen28                               |
  20. # |                                                                                     |
  21. # +-------------------------------------------------------------------------------------+
  22. # + *** Commands ***                                                                    |
  23. # |     +---------------+                                                               |
  24. # |     [ OP - PUBLIC]                                                                  |
  25. # |     +---------------+                                                               |
  26. # |                                                                                     |
  27. # |     +++ !youtube on                                                                 |
  28. # |     +++ !youtube off                                                                |
  29. # |                                                                                     |
  30. # | IMPORTANT:                                                                          |
  31. # |                                                                                     |
  32. # | 500 requests per day                                                                |
  33. # | You need Google Api Key                                                             |
  34. # |                                                                                     |
  35. # | Updates:                                                                            |
  36. # | * v2                                                                                |
  37. # | -- It now catches the youtube link from /me and /ame                                |
  38. # +-------------------------------------------------------------------------------------+
  39.  
  40. bind PUBM - * youtube
  41. bind PUBM - * youtube:pubm
  42. bind CTCP - ACTION youtube:act
  43.  
  44. package require json
  45. package require http
  46. package require tls
  47.  
  48. set youtube(api) "INSERT API CODE HERE"
  49. set youtube(version) "2.0"
  50.  
  51. setudef flag youtube
  52.  
  53. proc youtube:pubm {nick uhost hand chan arg} {
  54.     global temp
  55.  
  56.     if {[string index $arg 0] in {! . `}} {
  57.         set temp(cmd) [string range $arg 1 end]
  58.         set temp(cmd) [lindex [split $temp(cmd)] 0]
  59.         set arg [join [lrange [split $arg] 1 end]]
  60.     } elseif {[isbotnick [lindex [split $arg] 0]]} {
  61.         set temp(cmd) [lindex [split $arg] 1]
  62.         set arg [join [lrange [split $arg] 2 end]]
  63.     } else { return 0 }
  64.  
  65.     if {[info commands ytpubm:$temp(cmd)] ne ""} { ytpubm:$temp(cmd) $nick $uhost $hand $chan $arg }
  66. }
  67.  
  68. proc ytpubm:youtube {nick uhost hand chan arg} {
  69.     global youtube tempYT
  70.  
  71.     switch -exact -- [lindex [split $arg] 0] {
  72.         on {
  73.             if {[isop $nick $chan] || [matchattr $hand n]} {
  74.                 channel set $chan +youtube
  75.  
  76.                 putserv "PRIVMSG $chan :\002$nick\002 - \00302Set channel mode \00306+youtube\0032 on \00304$chan"
  77.                 return
  78.             }
  79.         }
  80.         off {
  81.             if {[isop $nick $chan] || [matchattr $hand n]} {
  82.                 channel set $chan -youtube
  83.  
  84.                 putserv "PRIVMSG $chan :\002$nick\002 - \00302Set channel mode \00306-youtube\0032 on \00304$chan"
  85.                 return
  86.             }
  87.         }
  88.         top {}
  89.         search {
  90.             ::http::register https 443 [list ::tls::socket -tls1 1]
  91.  
  92.             if {[catch {http::geturl "https://www.googleapis.com/youtube/v3/videos?[http::formatQuery key $youtube(api) maxresults 5 part id,snippet type video order viewCount q [lindex [split $arg] 1]]"} tok]} {
  93.                 putlog "Socket error: $tok"
  94.                 return 0
  95.             }
  96.             if {[http::status $tok] ne "ok"} {
  97.                 set status [http::status $tok]
  98.  
  99.                 putlog "TCP error: $status"
  100.                 return 0
  101.             }
  102.             if {[http::ncode $tok] != 200} {
  103.                 set code [http::code $tok]
  104.                 http::cleanup $tok
  105.  
  106.                 putlog "HTTP Error: $code"
  107.                 return 0
  108.             }
  109.  
  110.             set data [http::data $tok]
  111.  
  112.             set parse [::json::json2dict $data]
  113.  
  114.             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]"
  115.             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]"
  116.             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]"
  117.             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]"          
  118.             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]"
  119.            
  120.             putserv "PRIVMSG $chan :\002\00301,00You\00300,04Tube\002\017 - \00304Top 5\00302 videos based on \00303viewCount\003"
  121.  
  122.             set number 0
  123.             foreach line [array names tempYT] {
  124.                 if {[llength $line]} {
  125.                     incr number
  126.                    
  127.                     set id "[lindex $tempYT($line) 0]"
  128.                     set title "[join [lrange $tempYT($line) 1 end]]"
  129.                    
  130.                     putserv "PRIVMSG $chan :$number. \00302Title - \00312$title\003 \037\002/\037\002 \00302Link\003: \00304https://www.youtube.com/watch?v=$id"
  131.                 }
  132.             }
  133.         }
  134.     }
  135. }
  136.  
  137. proc youtube:act {nick uhost hand dest key arg} {
  138.     global ytignore youtube
  139.  
  140.     if {![channel get $dest youtube]} { return 0 }
  141.     if {![string match -nocase *yout* $arg]} { return 0 }
  142.  
  143.     ## ++
  144.     set floodtime 10
  145.  
  146.     ## ++
  147.     if {![info exists ytignore($nick)]} {
  148.         set ytignore($nick) [unixtime]
  149.         utimer $floodtime [list unset -nocomplain ytignore($nick)]
  150.     }
  151.  
  152.     ## ++
  153.     if {[expr [unixtime]-$ytignore($nick)]>$floodtime} { putlog "ignoram"; return 0 }
  154.  
  155.     set youtubecheck [regexp -all -nocase {(?:\/watch\?v=|youtu\.be\/)([\d\w-]{11})} $arg match youtubeid]
  156.  
  157.     youtube:parse $youtubecheck $match $youtubeid $dest
  158. }
  159.  
  160. proc youtube {nick uhost hand chan arg} {
  161.     global ytignore youtube
  162.  
  163.     if {![channel get $chan youtube]} { return 0 }
  164.     if {![string match -nocase *yout* $arg]} { return 0 }
  165.  
  166.     ## ++
  167.     set floodtime 10
  168.  
  169.     ## ++
  170.     if {![info exists ytignore($nick)]} {
  171.         set ytignore($nick) [unixtime]
  172.         utimer $floodtime [list unset -nocomplain ytignore($nick)]
  173.     }
  174.  
  175.     ## ++
  176.     if {[expr [unixtime]-$ytignore($nick)]>$floodtime} { putlog "ignoram"; return 0 }
  177.  
  178.     set youtubecheck [regexp -all -nocase {(?:\/watch\?v=|youtu\.be\/)([\d\w-]{11})} $arg match youtubeid]
  179.  
  180.     youtube:parse $youtubecheck $match $youtubeid $chan
  181. }
  182.  
  183. proc youtube:parse {youtubecheck match youtubeid dest} {
  184.     global ytignore youtube
  185.  
  186.     ::http::register https 443 [list ::tls::socket -tls1 1]
  187.  
  188.     if {[catch {http::geturl "https://www.googleapis.com/youtube/v3/videos?[http::formatQuery id $youtubeid key $youtube(api) part snippet,contentDetails,statistics,status]"} tok]} {
  189.         putlog "Socket error: $tok"
  190.         return 0
  191.     }
  192.     if {[http::status $tok] ne "ok"} {
  193.         set status [http::status $tok]
  194.  
  195.         putlog "TCP error: $status"
  196.         return 0
  197.     }
  198.     if {[http::ncode $tok] != 200} {
  199.         set code [http::code $tok]
  200.         http::cleanup $tok
  201.  
  202.         putlog "HTTP Error: $code"
  203.         return 0
  204.     }  
  205.  
  206.     set data [http::data $tok]
  207.     set parse [::json::json2dict $data]
  208.  
  209.     set playtime [lindex [dict get [lindex [dict get $parse items] 0] snippet] 1]
  210.     set title [lindex [dict get [lindex [dict get $parse items] 0] snippet] 5]
  211.     set viewCount [lindex [dict get [lindex [dict get $parse items] 0] statistics] 1]
  212.     set likeCount [lindex [dict get [lindex [dict get $parse items] 0] statistics] 3]
  213.     set dislikeCount [lindex [dict get [lindex [dict get $parse items] 0] statistics] 5]
  214.     set commentCount [lindex [dict get [lindex [dict get $parse items] 0] statistics] 9]
  215.     set publishedAt [lindex [dict get [lindex [dict get $parse items] 0] snippet] 1]
  216.     set publishedAt [string map [list "T" " " ".000Z" ""] $publishedAt]
  217.     set channelTitle [lindex [dict get [lindex [dict get $parse items] 0] snippet] 11]
  218.     set duration [lindex [dict get [lindex [dict get $parse items] 0] contentDetails] 1]
  219.     set duration [string map [list "PT" "" "M" "m " "S" "s"] $duration]
  220.     set definition [string toupper [lindex [dict get [lindex [dict get $parse items] 0] contentDetails] 5]]
  221.  
  222.     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\003 by \00312$channelTitle"
  223. }
  224.  
  225. proc youtube:convert {num} { while {[regsub {^([-+]?\d+)(\d\d\d)} $num "\\1.\\2" num]} {}; return $num }
  226.  
  227. putlog "++ \[ - \00304PUBLIC\003 - \00306loaded\003 * \00303YouTUBE\003 \]"
  228.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement