Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##############################################################################################
- ## ## Youtube.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help ## ##
- ##############################################################################################
- ## To use this script you must set channel flag +youtubeURL (ie .chanset #chan +youtubeURL) ##
- ##############################################################################################
- package require tls
- ##############################################################################################
- ## ## Start Setup. ## ##
- ##############################################################################################
- proc youtubesurl {nick host hand chan text} {
- if {[lsearch -exact [channel info $chan] +youtubeURL] != -1} {
- ## Change the characters between the "" below to change the logo shown with each result. ##
- set youtubelogo "\002\00301,00You\00300,04Tube\002\017"
- ## Change the format codes between the "" below to change the color/state of the text. ##
- set textf "\002\017"
- set tagcolor "\002"
- set hostlang "en"
- ##############################################################################################
- ## ## End Setup. ## ##
- ##############################################################################################
- set youtubecheck [regexp -all -nocase {(?:\/watch\?v=|youtu\.be\/)([\d\w-]{11})} $text match youtubeid]
- if {$youtubeid != ""} {
- set youtubesite gdata.youtube.com
- set youtubeurl "/feeds/api/videos/${youtubeid}?v=2&hl=${hostlang}"
- set youtubeviews ""
- set youtubedesc ""
- set youtubeuser ""
- set youtubelikes ""
- set youtubedislikes ""
- set youtubedate ""
- set youtubefound ""
- set youtubeduration ""
- set youtubecategory ""
- if {[catch {set youtubesock [tls::socket $youtubesite 443]} sockerr]} {
- putlog "$youtubesite $youtubeurl $sockerr error"
- return 0
- } else {
- puts $youtubesock "GET $youtubeurl HTTP/1.0"
- puts $youtubesock "Host: $youtubesite"
- puts $youtubesock ""
- flush $youtubesock
- while {![eof $youtubesock]} {
- set youtubevar " [gets $youtubesock] "
- #title
- if {[regexp -nocase {<title>(.*)<\/title>} $youtubevar match youtubedesc]} {
- set youtubedesc "${tagcolor}Title: ${textf}${youtubedesc}"
- }
- #uploader
- if {[regexp -nocase {<name>(.*)<\/name>} $youtubevar match youtubeuser]} {
- set youtubeuser "${tagcolor}Uploader: ${textf}${youtubeuser}"
- }
- #views
- if {[regexp -nocase {viewCount='([^']*)} $youtubevar match youtubeviews]} {
- set youtubeviews "${tagcolor}Views: ${textf}[ytaddcomma ${youtubeviews}]"
- }
- #likes
- if {[regexp -nocase {numLikes='([^']*)'} $youtubevar match youtubelikes]} {
- set youtubelikes "${tagcolor}Likes: ${textf}[ytaddcomma ${youtubelikes}]"
- }
- #dislikes
- if {[regexp -nocase {numDislikes='([^']*)'} $youtubevar match youtubedislikes]} {
- set youtubedislikes "${tagcolor}Dislikes: ${textf}[ytaddcomma ${youtubedislikes}]"
- }
- #duration
- if {[regexp -nocase {seconds='([^']*)} $youtubevar match youtubeduration]} {
- set youtubeduration "${tagcolor}Duration: ${textf} [ytfixduration $youtubeduration]"
- }
- #.cat'>,<
- if {[regexp -nocase {\.cat'>([^<]*)<} $youtubevar match youtubecategory]} {
- set youtubecategory "${tagcolor}Type: ${textf}${youtubecategory}"
- }
- #date + Output
- if {[regexp {<published>([^T]*)T} $youtubevar match youtubedate]} {
- set youtubedate "${tagcolor}Uploaded: ${textf}[string map -nocase {"uploaded on" ""} ${youtubedate}]"
- }
- if {[regexp {<\/entry>} $youtubevar 1] != 0} {
- putserv "PRIVMSG $chan :[yturldehex "${youtubelogo} ${youtubedesc} ${youtubecategory} ${youtubeviews} ${youtubelikes} \
- ${youtubedislikes} ${youtubeuser} ${youtubedate} ${youtubeduration}"]"
- close $youtubesock
- return 0 }
- }
- close $youtubesock
- return 0
- }
- }
- }
- }
- proc ytfixduration {secs} {
- set h [expr {$secs/3600}]
- incr secs [expr {$h*-3600}]
- set m [expr {$secs/60}]
- set s [expr {$secs%60}]
- if {$h} {
- set h "$h hours"
- } else {
- set h ""
- }
- if {$m} {
- set m "$m minutes"
- } else {
- set m ""
- }
- if {$s} {
- set s "$s seconds"
- } else {
- set s ""
- }
- return "$h $m $s"
- }
- proc ytaddcomma {number} {regsub -all {\d(?=(\d{3})+($|\.))} $number {\0,}}
- proc yturldehex {string} {
- regsub -all {[\[\]]} $string "" string
- set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
- return [encoding convertfrom utf-8 [string map {" \" \xa0 "," & \&} $string]]
- }
- proc yturlencode {instring} {
- return [subst [regsub -nocase -all {([^a-z0-9])} $instring {%[format %x [scan "\\&" %c]]}]]
- }
- bind pubm -|- "*youtube.*watch?v=*" youtubesurl
- bind pubm -|- "*youtu.be/*" youtubesurl
- setudef flag youtubeURL
- putlog "\002*Loaded* \00301,00You\00300,04Tube\002\017 \002URL check api version by Ford_Lawnmower irc.GeekShed.net #Script-Help"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement