Advertisement
Guest User

MyYoutube

a guest
Jul 26th, 2013
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. package require http
  2. catch {unbind raw - PRIVMSG *raw:irc:msg}
  3. catch {unbind raw - PRIVMSG *raw:PRIVMSG}
  4. bind raw - PRIVMSG striprivmsg
  5. proc striprivmsg {f k a} {
  6. set a [stripcodes abcgru $a]
  7. *raw:irc:msg $f $k $a
  8. *raw:PRIVMSG $f $k $a
  9. }
  10.  
  11. bind pub - !yt pub:youtube
  12. proc pub:youtube {nick host hand chan args} {
  13. set args [lindex $args 0]
  14. if {$args == ""} {
  15. putmsg $chan "\037YouTube\037 \002::\002 \037HELP\037 Mostra il link al titolo dato. \037Utilizzo:\037 !yt titolo"
  16.  
  17. return
  18. }
  19. set search [http::formatQuery v 2 alt jsonc q $args max-results 1 prettyprint true]
  20. set token [http::config -useragent "Mozilla/1.1"]
  21. set token [http::geturl "http://gdata.youtube.com/feeds/api/videos?$search"]
  22. set data [::http::data $token]
  23. http::cleanup $token
  24.  
  25. set totalitems [lindex [regexp -all -nocase -inline {\"totalItems\"\: ([0-9]+)} $data] 1]
  26. set lines [split $data "\n"]
  27. set results ""
  28. foreach line $lines {
  29. if {[regexp -all -nocase -inline {\"id\"\: \"(.*)\"} $line] != ""} {
  30. set id [lindex [regexp -all -nocase -inline {\"id\"\: \"(.*)\"} $line] 1]
  31. lappend results $id
  32. }
  33. if {[regexp -all -nocase -inline {\"title\"\: \"(.*)\"} $line] != ""} {
  34. set result($id,title) [yturldehex [lindex [regexp -all -nocase -inline {\"title\"\: \"(.*)\"} $line] 1]]
  35. }
  36. if {[regexp -all -nocase -inline {\"duration\"\: ([0-9]+)} $line] != ""} {
  37. set result($id,duration) [lindex [regexp -all -nocase -inline {\"duration\"\: ([0-9]+)} $line] 1]
  38. }
  39. if {[regexp -all -nocase -inline {\"viewCount\"\: ([0-9]+)} $line] != ""} {
  40. set result($id,viewCount) [lindex [regexp -all -nocase -inline {\"viewCount\"\: ([0-9]+)} $line] 1]
  41. }
  42. }
  43. foreach res $results {
  44. putmsg $chan "\037YouTube\037 \002::\002 http://www.youtube.com/watch?v=$res"
  45. }
  46. }
  47.  
  48. proc yturldehex {string} {
  49. regsub -all {[\[\]]} $string "" string
  50. set string [subst [regsub -nocase -all {\&#([0-9]{2,4});} $string {[format %c \1]}]]
  51. return [string map {" \"} $string]
  52. }
  53.  
  54. proc shortduration {seconds} {
  55. set hours [expr int(floor($seconds/3600))]
  56. set minutes [expr int(floor(($seconds%3600)/60))]
  57. set seconds [expr $seconds - ($hours*3600) - ($minutes*60)]
  58. if {$hours<10} { set hours "0$hours" }
  59. if {$minutes<10} { set minutes "0$minutes" }
  60. if {$seconds < 10} { set seconds "0$seconds" }
  61. return "$hours:$minutes:$seconds"
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement