To enable on channels , in dcc add user defined flag with:
.chanset #channel +ourtubeXTRA
or in the channel window:
/msg #channel !youtube enable
if a youtube URL is detected in channel, details are taken from youtube site. Videos can be searched for using:
!youtube <search criteria>
To enable on channels , in dcc add user defined flag with:
.chanset #channel +ourtubeXTRAsearch
or in the channel window:
/msg #channel !youtube enablesearch
Forgive the bad identation. Its perfect in my editor.
EDIT: now detects URLs in Title. Small modifiucation in how $data is set - no longer uses string map, afterall utf-8 decoding is done at time of output.
Parameters maxlen(max length of parsed text), color(00-15 - color of url) and styles(can be style_ul and/or style_bd) added to url_search proc. Called like:
Code: Select all
set text_parsed [url_search 40 07 "style_ul" $text]
Now has 2 user defined channel flags:
ourtubeXTRA for youtube URL detection in a channel.
ourtubeXTRAsearch for youtube video searching.
Code: Select all
setudef flag ourtubeXTRA
setudef flag ourtubeXTRAsearch
global ourtubeXTRA tcl_platform
#Flood Protection: after show a link, will ignore all links few seconds
# This means 1 link per 10 seconds.
set ourtubeXTRA(rest) 10
#What language you can receive the youTube data? (if works heh)
set ourtubeXTRA(lang) en
#Limit of links at same time
set ourtubeXTRA(max) 5
#youtube logo
set ourtubeXTRA(youtubelogo) "\002\00304,00You\00300,04Tube\017"
set ourtubeXTRA(output) "$ourtubeXTRA(youtubelogo) \00311::\00315 <title> \00311:: \00308Author: \00315<author> \00311:: \00308Added: \00315<added> \00311:: \00308Views: \00315<views> \00311:: \00308Duration: \00315<duration> \00311:: \00308Likes: \00309<likes> \00311:: \00308Dislikes: \00304<dislikes> \00311:: \00308Description: \00315<description>"
set ourtubeXTRA(outputsearch) "\00312\037<link>\003\037 \00311:: \00308Title: \00315<title> \00311:: \00308Author: \00315<author> \00311:: \00308Added: \00315<added> \00311:: ;\00308Views: \00315<views> \00311:: \00308Duration: \00315<duration> \00311:: \00308Description: \00315<description>"
set ourtubeXTRA(author) "WazzaUK"
set ourtubeXTRA(contact) "WazzaUK <wallison_uk@yahoo.co.uk>"
set ourtubeXTRA(originalauthor) "HackeMate"
set ourtubeXTRA(originalcontact) "HackeMate <Sentencia@eggdrop.es>"
set ourtubeXTRA(name) "ourtubeXTRA"
set ourtubeXTRA(projectName) "ourtubeXTRA"
set ourtubeXTRA(version) "1.0"
set ourtubeXTRA(package.http) [package require http]
set ourtubeXTRA(protection) ""
if {$tcl_platform(os) eq "Linux"} {
set platfrm "X11"
} else {
set platfrm $tcl_platform(os)
}
http::config -useragent "Mozilla/5.0 ($platfrm; U; $tcl_platform(os) $tcl_platform(machine); $ourtubeXTRA(lang); rv:1.9.0.3) ourtubeXTRA 1.0" -accept "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
bind pub - !youtube otYoutube
bind pubm - *http://www.youtube.com/watch?* otPub
proc url_search {maxlen color styles text} {
set i 0
set newtext ""
set style_ul ""
set style_bd ""
if {[string is integer -strict $maxlen]} {
if {($maxlen == "") || ($maxlen < 1)} {set maxlen 100}
} else { set maxlen 100 }
if {[string is list -strict $styles]} {
if {[string match -nocase "*style_ul*" [lrange [split $styles] 0 end]]} {set style_ul "\037"}
if {[string match -nocase "*style_bd*" [lrange [split $styles] 0 end]]} {set style_bd "\002"}
}
if {[string is integer -strict $color]} {
if {($color < 0) || ($color > 15)} {set color 07}
} else { set color "07" }
foreach word [split $text] {
if {[string length $word] >= 5 && [regexp {(f|ht)tp(s|)://} $word] && ![regexp {://([^/:]*:([^/]*@|\d+(/|$))|.*/\.)} $word]} {
set urlindex [string first "http" $word 0]
set newword [string range $word $urlindex [string length $word]]
set oldlen [expr [string first "http" $word 0] -1 ]
set oldword [string range $word 0 $oldlen]
incr i
set color "\3${color}"
set word "$oldword${color}${style_ul}${style_bd}$newword\00315${style_ul}${style_bd}"
if {$word != ""} {
set newtext [append newtext $word " "]
}
set olen [string length $newtext]
if {$olen >= $maxlen} {
set newtext [append newtext "..."]
return $newtext
}
}
return $newtext
}
proc utfdecodeclean {string} {
regsub -all -- {([\(\)\[\]\{\}\$\"\\])} $string {\\\1} string
return $string
}
proc utfdecode {content} {
if {![regexp -- & $content]} {
return $content
}
set escapes {
\xa0 ¡ \xa1 ¢ \xa2 £ \xa3 ¤ \xa4
¥ \xa5 ¦ \xa6 § \xa7 ¨ \xa8 © \xa9
ª \xaa « \xab ¬ \xac \xad ® \xae
¯ \xaf ° \xb0 ± \xb1 ² \xb2 ³ \xb3
´ \xb4 µ \xb5 ¶ \xb6 · \xb7 ¸ \xb8
¹ \xb9 º \xba » \xbb ¼ \xbc ½ \xbd
¾ \xbe ¿ \xbf À \xc0 Á \xc1 Â \xc2
à \xc3 Ä \xc4 Å \xc5 Æ \xc6 Ç \xc7
È \xc8 É \xc9 Ê \xca Ë \xcb Ì \xcc
Í \xcd Î \xce Ï \xcf Ð \xd0 Ñ \xd1
Ò \xd2 Ó \xd3 Ô \xd4 Õ \xd5 Ö \xd6
× \xd7 Ø \xd8 Ù \xd9 Ú \xda Û \xdb
Ü \xdc Ý \xdd Þ \xde ß \xdf à \xe0
á \xe1 â \xe2 ã \xe3 ä \xe4 å \xe5
æ \xe6 ç \xe7 è \xe8 é \xe9 ê \xea
ë \xeb ì \xec í \xed î \xee ï \xef
ð \xf0 ñ \xf1 ò \xf2 ó \xf3 ô \xf4
õ \xf5 ö \xf6 ÷ \xf7 ø \xf8 ù \xf9
ú \xfa û \xfb ü \xfc ý \xfd þ \xfe
ÿ \xff ƒ \u192 Α \u391 Β \u392 Γ \u393 Δ \u394
Ε \u395 Ζ \u396 Η \u397 Θ \u398 Ι \u399
Κ \u39A Λ \u39B Μ \u39C Ν \u39D Ξ \u39E
Ο \u39F Π \u3A0 Ρ \u3A1 Σ \u3A3 Τ \u3A4
Υ \u3A5 Φ \u3A6 Χ \u3A7 Ψ \u3A8 Ω \u3A9
α \u3B1 β \u3B2 γ \u3B3 δ \u3B4 ε \u3B5
ζ \u3B6 η \u3B7 θ \u3B8 ι \u3B9 κ \u3BA
λ \u3BB μ \u3BC ν \u3BD ξ \u3BE ο \u3BF
π \u3C0 ρ \u3C1 ς \u3C2 σ \u3C3 τ \u3C4
υ \u3C5 φ \u3C6 χ \u3C7 ψ \u3C8 ω \u3C9
ϑ \u3D1 ϒ \u3D2 ϖ \u3D6 • \u2022
… \u2026 ′ \u2032 ″ \u2033 ‾ \u203E
⁄ \u2044 ℘ \u2118 ℑ \u2111 ℜ \u211C
™ \u2122 ℵ \u2135 ← \u2190 ↑ \u2191
→ \u2192 ↓ \u2193 ↔ \u2194 ↵ \u21B5
⇐ \u21D0 ⇑ \u21D1 ⇒ \u21D2 ⇓ \u21D3 ⇔ \u21D4
∀ \u2200 ∂ \u2202 ∃ \u2203 ∅ \u2205
∇ \u2207 ∈ \u2208 ∉ \u2209 ∋ \u220B ∏ \u220F
∑ \u2211 − \u2212 ∗ \u2217 √ \u221A
∝ \u221D ∞ \u221E ∠ \u2220 ∧ \u2227 ∨ \u2228
∩ \u2229 ∪ \u222A ∫ \u222B ∴ \u2234 ∼ \u223C
≅ \u2245 ≈ \u2248 ≠ \u2260 ≡ \u2261 ≤ \u2264
≥ \u2265 ⊂ \u2282 ⊃ \u2283 ⊄ \u2284 ⊆ \u2286
⊇ \u2287 ⊕ \u2295 ⊗ \u2297 ⊥ \u22A5
⋅ \u22C5 ⌈ \u2308 ⌉ \u2309 ⌊ \u230A
⌋ \u230B 〈 \u2329 〉 \u232A ◊ \u25CA
♠ \u2660 ♣ \u2663 ♥ \u2665 ♦ \u2666
" \x22 & \x26 < \x3C > \x3E O&Elig; \u152 œ \u153
Š \u160 š \u161 Ÿ \u178 ˆ \u2C6
˜ \u2DC \u2002 \u2003 \u2009
\u200C \u200D \u200E \u200F – \u2013
— \u2014 ‘ \u2018 ’ \u2019 ‚ \u201A
“ \u201C ” \u201D „ \u201E † \u2020
‡ \u2021 ‰ \u2030 ‹ \u2039 › \u203A
€ \u20AC ' \u0027 "" "" "" ""
"" — \u2014
}
set content [string map $escapes $content]
regsub -all -- {&[a-zA-Z]+?;} [utfdecodeclean $content] {?} content
regsub -all -- {&#(\d{1,3});} $content {[format %c [scan \1 %d]]} content
return [subst $content]
}
proc otYoutube {nick uhost hand chan text} {
global ourtubeXTRA
if {![channel get $chan ourtubeXTRA]} {
if {$text eq "enable"} {
channel set $chan +ourtubeXTRA
if {[channel get $chan ourtubeXTRA]} {
putquick "NOTICE $nick :$ourtubeXTRA(youtubelogo) \00311:: \00315ourtubeXTRA 1.0"
putquick "NOTICE $nick :Youtube URL detection was successfully ENABLED on $chan"
return
}
return
}
}
if {![channel get $chan ourtubeXTRAsearch]} {
if {$text eq "enablesearch"} {
channel set $chan +ourtubeXTRAsearch
if {[channel get $chan ourtubeXTRAsearch]} {
putquick "NOTICE $nick :$ourtubeXTRA(youtubelogo) \00311:: \00315ourtubeXTRA 1.0"
putquick "NOTICE $nick :Video search was successfully ENABLED on $chan"
return
}
}
putquick "NOTICE $nick :$ourtubeXTRA(youtubelogo) \00311:: \00315ourtubeXTRA 1.0"
putquick "NOTICE $nick :$chan has the youtube search command DISABLED"
if {[matchattr $hand n]} {
putquick "NOTICE $nick :You can ENABLE it directly by typing:\002 /msg $chan !youtube enablesearch\002"
}
return
}
#This is a generic protection to prevent flood
#No utimer required
#
if {![info exists ourtubeXTRA(protection)]} {
set ourtubeXTRA(protection) [clock seconds]
} else {
if {![string is digit -strict $ourtubeXTRA(protection)]} {
set ourtubeXTRA(protection) [clock seconds]
} else {
set time [expr [clock seconds]-$ourtubeXTRA(protection)]
if {$time >= $ourtubeXTRA(rest)} {
set ourtubeXTRA(protection) [clock seconds]
} else {
set floodsecs [expr [clock seconds]-$ourtubeXTRA(protection)]
putserv "NOTICE $nick :$ourtubeXTRA(youtubelogo) \00311:: \00315Flood protection triggered: $floodsecs second(s) remaining."
return
}
}
}
if {$text eq ""} {
putquick "NOTICE $nick :$ourtubeXTRA(youtubelogo) \00311:: \00315Usage: !youtube <search criteria>"
return
}
if {[string length $text] <= 3} {
putquick "NOTICE $nick :$ourtubeXTRA(youtubelogo) \00311:: \00315Error - Search parameter '$arg' is too short."
return
}
set data [ourtubeXTRAGet $text]
if {[string length $data] == 0} {
set data "I was unable to connect to that website. Probably I get timeout."
return
}
#Display results
foreach line $data {
putquick "PRIVMSG $chan :$line"
}
}
proc ourtubeXTRAGet {ask} {
global ourtubeXTRA
set resultcount "0"
regsub -all -- {\s+} $ask "" search
set search [http::formatQuery $search]
http::config -useragent "Mozilla/5.0 (Windows NT; U; Windows NT x86; en-ES; rv:1.9.0.3) Firefox 3.0.7" -accept "text/html,application/xhtml,+xml,application/xml;q=0.9,*/*;q=0.8"
set token [http::geturl http://www.youtube.com/results?search_query=$search]
upvar #0 $token state
set data $state(body)
regsub -all {\n|\t} $data "" data
set ncode ""
regexp {[0-9]{3}} $state(http) ncode
if {$ncode eq ""} {
set ncode $state(http)
}
set list {}
switch -- $ncode {
"200" {
regexp {<p class=\"num-results\">About <strong>(.*?)</strong>} $data "" resultcount
regexp -- {<ol id=\"search-results\" class=\"result-list context-data-container\">(.*)$} $data -> data
set videos [regexp -all -inline {<li class=\"yt-lockup clearfix yt-uix-tile result-item-padding yt-lockup-video yt-lockup-tile vve-check context-data-item\"(.*?)</li></ul></div>} $data]
set total [expr [llength $videos] /2]
if {$total >= $ourtubeXTRA(max)} {
set numitems $ourtubeXTRA(max)
} else {
set numitems $total
}
if {$resultcount == 0} {
set numitems 0
set list [list "$ourtubeXTRA(youtubelogo) \00311:: \00315$resultcount \00315result(s) found for items matching '$ask'."]
} else {
set list [list "$ourtubeXTRA(youtubelogo) \00311:: \00315Showing \00300$numitems \00315of \00300$resultcount \00315result(s) found for items matching '$ask'."]
}
set i 2
if {$resultcount > 0} {
foreach {id line} $videos {
set map {}
set title ""
set description ""
set description_parsed ""
set added "Unknown"
set viewcount "0"
set author "Unknown"
set link ""
set duration ""
foreach {entity number} [regexp -all -inline {&#(\d+);} $line] {
lappend map $entity [format \\u%04x [scan $number %d]]
}
set line [string map [subst -nocomm -novar $map] $line]
regexp {data-context-item-title=\"(.*?)\"} $line "" title
regsub -all -- {\<[^\>]*\>|\t} $title "" title
set title_parsed [url_search 40 07 "style_ul" $title]
if {![regexp {data-context-item-views=\"(.*?)views} $line "" viewcount]} { set viewcount "0" }
regsub -all -- {\<[^\>]*\>|\t} $viewcount "" viewcount
regexp {data-context-item-time=\"(.*?)\"} $line "" duration
regsub -all -- {\<[^\>]*\>|\t} $duration "" duration
regexp {<div class=\"yt-lockup-description yt-ui-ellipsis yt-ui-ellipsis-2\" dir=\"ltr\">(.*?)</div>} $line "" description
regsub -all -- {\<[^\>]*\>|\t} $description "" description
if {$description == ""} {
set description "This video doesn't have any description ..."
}
set description_parsed [url_search 100 07 "style_ul" $description]
regexp {</a></li><li>(.*?)</li>} $line "" added
regexp {data-context-item-user=\"(.*?)\"} $line "" author
regsub -all -- {\<[^\>]*\>|\t} $author "" author
regexp {data-context-item-id=\"(.*?)\"} $line "" link
set link "http://www.youtube.com/watch?v=$link"
set output [string map [list "<link>" $link "<title>" $title_parsed "<author>" $author "<added>" $added "<views>" $viewcount "<duration>" $duration "<description>" $description_parsed] $ourtubeXTRA(outputsearch)]
lappend list $output
if {$i > $ourtubeXTRA(max)} {
break
}
incr i
}
}
set list [utfdecode $list]
return [encoding convertto utf-8 $list]
}
"404" {
http::cleanup $token
return [list "No such file or webpage."]
}
default {
http::cleanup $token
return [list "unforeseen circumstance. Server responded: $ncode"]
}
}
}
proc otPub {nick uhost hand chan text} {
global ourtubeXTRA
if {![channel get $chan ourtubeXTRA]} {
putquick "NOTICE $nick :$ourtubeXTRA(youtubelogo) \00311:: \00315ourtubeXTRA 1.0"
putquick "NOTICE $nick :$chan has the youtube URL detector DISABLED"
if {[matchattr $hand n]} {
putquick "NOTICE $nick :You can ENABLE it directly by typing:\002 /msg $chan !youtube enable\002"
}
return
}
set webTarget [lsearch -inline [split $text] {*http://*.youtube.*/watch?*}]
if {([info exists ourtubeXTRA(protection)]) && ([string is digit -strict $ourtubeXTRA(protection)])} {
set rest [expr [clock seconds]-$ourtubeXTRA(protection)]
if {$rest >= $ourtubeXTRA(rest)} {
set ourtubeXTRA(protection) ""
}
} else {
set ourtubeXTRA(protection) ""
}
if {$webTarget ne ""} {
if {! [regexp -nocase {^(http://)?([^/:]+)(:([0-9]+))?(/.*)?$} $webTarget]} {
return
}
if {$ourtubeXTRA(protection) ne ""} {
set floodsecs [expr [clock seconds]-$ourtubeXTRA(protection)]
putserv "NOTICE $nick :$ourtubeXTRA(youtubelogo) \00311:: \00315Flood protection triggered: $floodsecs second(s) remaining."
return
}
set ourtubeXTRA(protection) [clock seconds]
set data [otGet $webTarget]
if {[string length $data] == 0} {
set data "I was not able to reach Youtube's link. Probably I get a timeout. Try again."
}
putquick "PRIVMSG $chan :$data"
utimer $ourtubeXTRA(rest) [list set ourtubeXTRA(protection) ""]
}
}
proc otGet {web {relocation ""}} {
global ourtubeXTRA
set token [http::geturl $web -timeout 4000]
upvar #0 $token state
set lastcode $state(http)
set ncode ""
regexp {[0-9]{3}} $lastcode ncode
if {$ncode eq ""} {
set ncode $lastcode
}
switch -- $ncode {
"200" {
}
"302" {
foreach {flag value} $state(meta) {
if {$flag eq "Location"} {
# Due to invalid youtube link but valid url syntax we can
# receive an url forward. this handles that
http::cleanup $token
return [otGet $value "(Relocated)"]
}
}
}
"303" {
http::cleanup $token
return "That video does not exists. Server responded: $lastcode"
}
"404" {
http::cleanup $token
return "$web - No such webpage"
}
default {
http::cleanup $token
return "unforeseen circumstances. Server responded: $lastcode"
}
}
set data $state(body)
http::cleanup $token
set title ""
set author "Unknown"
set added "Unknown"
set description "This video doesn't have any description..."
set views "0"
set author "Unknown"
set likes "0"
set dislikes "0"
set userinfo ""
set duration ""
set totalseconds 0
set videosecs 0
set videomins 0
regexp {<title>(.*?)</title>} $data "" title
set title [string trimright $title " - YouTube"]
regsub -all -- {\<[^\>]*\>|\t} $title "" title
set title_parsed [url_search 40 07 "style_ul" $title]
regexp {<meta name=\"description\" content=\"(.*?)\">.*} $data " " description
regexp {<span id=\"eow-date\" class=\"watch-video-date\" >(.*?)</span>} $data "" added
# following two lines were edited from original
if {![regexp {<span class=\"watch-view-count \" >(.*?)</span>} $data "" views]} { set views "0" }
set views [string trim $views]
set added [string trimleft $added]
if {[regexp -nocase {<meta itemprop=\"duration\" content=\"(.*?)\">.*} $data match duration]} {
set youtubelength $duration
if {[regexp {M(.*?)S} $duration match duration]} {
set videosecs $duration
}
set duration $youtubelength
if {[regexp {PT(.*?)M} $duration match duration]} {
set videomins $duration
}
set totalseconds [expr {($videomins * 60) + $videosecs}]
set duration [clock format $totalseconds -format {%H:%M:%S}]
}
regexp -- {<div id=\"watch7-user-header\" class=\"spf-nolink\">(.*?)<div class=\"yt-dialog hid\">} $data -> userinfo
if {![regexp {data-name=\"watch\">(.*?)</a>} $userinfo "" author]} { set author "Unknown" }
if {![regexp {<span class=\"likes-count\">(.*?)</span>} $data "" likes]} { set likes "0" }
if {![regexp {<span class=\"dislikes-count\">(.*?)</span>} $data "" dislikes]} { set dislikes "0" }
regsub -all -- {\<[^\>]*\>|\t} $description "" description
regsub -all -- {\<[^\>]*\>|\t} $views "" views
if {$description eq ""} {
set description "This video doesn't have any description ..."
}
set description_parsed [url_search 100 07 "style_ul" $description]
set output [string map [list "<title>" $title_parsed "<author>" $author "<added>" $added "<views>" $views "<duration>" $duration "<likes>" $likes "<dislikes>" $dislikes "<description>" $description_parsed] $ourtubeXTRA(output)]
set output [utfdecode $output]
return [encoding convertto utf-8 $output]
}
putlog "\002\00304,00You\00300,04Tube\017 \00311:: \002\00300*Loaded* \002\00315ourtubeXTRA 1.0 by \002WazzaUK\002\00311 :: \00315based on ourtube by \002Hackemate\002."
set ourtubeXTRA(Loaded) 1