Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package require http
- catch {unbind raw - PRIVMSG *raw:irc:msg}
- catch {unbind raw - PRIVMSG *raw:PRIVMSG}
- bind raw - PRIVMSG striprivmsg
- proc striprivmsg {f k a} {
- set a [stripcodes abcgru $a]
- *raw:irc:msg $f $k $a
- *raw:PRIVMSG $f $k $a
- }
- bind pub - !yt pub:youtube
- proc pub:youtube {nick host hand chan args} {
- set args [lindex $args 0]
- if {$args == ""} {
- putmsg $chan "\037YouTube\037 \002::\002 \037HELP\037 Mostra il link al titolo dato. \037Utilizzo:\037 !yt titolo"
- return
- }
- set search [http::formatQuery v 2 alt jsonc q $args max-results 1 prettyprint true]
- set token [http::config -useragent "Mozilla/1.1"]
- set token [http::geturl "http://gdata.youtube.com/feeds/api/videos?$search"]
- set data [::http::data $token]
- http::cleanup $token
- set totalitems [lindex [regexp -all -nocase -inline {\"totalItems\"\: ([0-9]+)} $data] 1]
- set lines [split $data "\n"]
- set results ""
- foreach line $lines {
- if {[regexp -all -nocase -inline {\"id\"\: \"(.*)\"} $line] != ""} {
- set id [lindex [regexp -all -nocase -inline {\"id\"\: \"(.*)\"} $line] 1]
- lappend results $id
- }
- if {[regexp -all -nocase -inline {\"title\"\: \"(.*)\"} $line] != ""} {
- set result($id,title) [yturldehex [lindex [regexp -all -nocase -inline {\"title\"\: \"(.*)\"} $line] 1]]
- }
- if {[regexp -all -nocase -inline {\"duration\"\: ([0-9]+)} $line] != ""} {
- set result($id,duration) [lindex [regexp -all -nocase -inline {\"duration\"\: ([0-9]+)} $line] 1]
- }
- if {[regexp -all -nocase -inline {\"viewCount\"\: ([0-9]+)} $line] != ""} {
- set result($id,viewCount) [lindex [regexp -all -nocase -inline {\"viewCount\"\: ([0-9]+)} $line] 1]
- }
- }
- foreach res $results {
- putmsg $chan "\037YouTube\037 \002::\002 http://www.youtube.com/watch?v=$res"
- }
- }
- proc yturldehex {string} {
- regsub -all {[\[\]]} $string "" string
- set string [subst [regsub -nocase -all {\&#([0-9]{2,4});} $string {[format %c \1]}]]
- return [string map {" \"} $string]
- }
- proc shortduration {seconds} {
- set hours [expr int(floor($seconds/3600))]
- set minutes [expr int(floor(($seconds%3600)/60))]
- set seconds [expr $seconds - ($hours*3600) - ($minutes*60)]
- if {$hours<10} { set hours "0$hours" }
- if {$minutes<10} { set minutes "0$minutes" }
- if {$seconds < 10} { set seconds "0$seconds" }
- return "$hours:$minutes:$seconds"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement