SHOW:
|
|
- or go back to the newest paste.
| 1 | package require http 2.4 | |
| 2 | bind PUBM - * mu | |
| 3 | proc mu {nick uhost hand chan text} {
| |
| 4 | set web(page) http://www.youtube.com | |
| 5 | - | set watch [regexp -nocase -- {\/watch\?v\=([^\s]{11})} $text youtubeid]
|
| 5 | + | set watch [regexp -nocase -- {((\/watch\?v\=)|(youtu\.be\/))([^\s]{11})} $text a1 a2 a3 youtubeid]
|
| 6 | set logoo "\002\00301,00You\00300,04Tube\002\017" | |
| 7 | ||
| 8 | if {$watch && $youtubeid != ""} {
| |
| 9 | set agent "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1" | |
| 10 | set t [::http::config -useragent $agent] | |
| 11 | set t [::http::geturl "$web(page)$youtubeid" -timeout 30000] | |
| 12 | set data [::http::data $t] | |
| 13 | ::http::cleanup $t | |
| 14 | ||
| 15 | set l [regexp -all -inline -- {<meta name="title" content="(.*?)">.*?<span class="watch-view-count">.*?<strong>(.*?)</strong>} $data]
| |
| 16 | ||
| 17 | regexp {"length_seconds": (\d+),} $data "" length
| |
| 18 | ||
| 19 | foreach {black a b c d e} $l {
| |
| 20 | ||
| 21 | set a [string map -nocase {\&\#39; \x27 & \x26 " \x22} $a]
| |
| 22 | set b [string map [list \n ""] $b] | |
| 23 | set c [string map [list \n ""] $c] | |
| 24 | set d [string map [list \n ""] $d] | |
| 25 | set e [string map -nocase {\&\#39; \x27 & \x26 " \x22} $e]
| |
| 26 | ||
| 27 | regsub -all {<.*?>} $a {} a
| |
| 28 | regsub -all {<.*?>} $b {} b
| |
| 29 | regsub -all {<.*?>} $c {} c
| |
| 30 | regsub -all {<.*?>} $d {} d
| |
| 31 | regsub -all {<.*?>} $e {} e
| |
| 32 | ||
| 33 | putserv "PRIVMSG $chan :$a' ( [duration $length] ) Viewed $b" | |
| 34 | ||
| 35 | proc duration {s} {
| |
| 36 | variable etube | |
| 37 | set hours [expr {$s / 3600}]
| |
| 38 | set minutes [expr {($s / 60) % 60}]
| |
| 39 | set seconds [expr {$s % 60}]
| |
| 40 | set res "" | |
| 41 | ||
| 42 | if {$hours != 0} {append res "$hours hours"}
| |
| 43 | if {$minutes != 0} {append res " $minutes minutes"}
| |
| 44 | if {$seconds != 0} {append res " $seconds seconds"}
| |
| 45 | return $res | |
| 46 | } | |
| 47 | } | |
| 48 | } | |
| 49 | } | |
| 50 | ||
| 51 | putlog "youtitle.tcl loaded..." |