i made it for our channel only so you have to edit it
http://wonziu.tk/sprawdzstream.tar.bz2
what you think?
It looks very resource heavy. Why didn't you write it in pure-tcl using http package instead? You also, inadvertently overwrote tcl's native [duration] command with one of your own. Not sure if this was intended... But to make it less of a drain on your bot, and your shell here's is something that should behave similar to what you are already doing.hayuto wrote:what you think?
Code: Select all
# dailymotion stream thing-a-mah-jig
# speechles/#roms-isos on June 2nd, 2013
#
# This will check every minute if the stream has gone up or down
# and will announce the start and ending. When the stream is enabled,
# it will also announce the url and how long the stream has been going
# on the hour and half hour. So every 30 minutes give or take a few
# seconds. It's using bind to time rather than timers too. So far less
# overhead is required tracking things.
#--> config start
# channel everything occurs in
set stream(channel) "#chan"
# url we announce for people to join
set stream(url) "http://www.dailymotion.com/video/xzlc83"
# url we use to obtain status information
set stream(api) "https://api.dailymotion.com/video/xzlc83"
# This one below you should _NEVER_ change unless you have
# issues with duration agos from start of videos
set stream(timezone) "%Y-%m-%d %H:%M:%S %Z"
# Use this to adjust minor clock sync issues -/+seconds
set stream(fixtime) "0"
# <-- config end
package require http
package require tls
::http::register https 443 [list ::tls::socket -require 0 -request 1]
if {![info exists stream(status)]} {
set stream(status) "false"
set stream(time) 0
}
proc streamDuration {time} {
global stream
set now [clock scan [clock format [clock seconds] -format $stream(timezone)] -gmt 1]
return [duration [expr {$now - $time + $stream(fixtime)}]]
}
foreach t {30* 60*} { bind time - $t streamSpam }
proc streamSpam {args} {
global stream
if {[string equal true $stream(status)]} {
putserv "privmsg $stream(channel) :Live stream in progress at $stream(url) started [streamDuration $stream(time)] ago."
}
}
bind time - * streamUpOrDown
proc streamUpOrDown {args} {
global stream
if {[catch { http::geturl "$stream(api)?fields=onair,start_time" -timeout 3000 } http]} {
putlog "Dailymotion: [string totitle $http]"
return 0
}
if {![string equal -nocase [::http::status $http] "ok"]} {
putlog "Dailymotion: [string totitle [::http::status $http]]"
http::cleanup $http
return 0
}
set data [http::data $http]
http::cleanup $http
regexp -- {"onair"\:(.*?),} $data - onair
regexp -- {"start_time"\:(.*?)\}} $data - start
if {![info exists onair]} {
if {[regexp -- {"message"\:"(.*?)"} $data - message]} {
putserv "privmsg $stream(channel) :$message"
} else {
putlog "Dailymotion: Parsing error; unexpected data."
}
} else {
if {![string equal $onair $stream(status)]} {
if {[string equal true $onair]} {
set message "\002Stream is UP\002 started [streamDuration $start] ago. Come watch us live at $stream(url)"
set stream(time) $start
} else {
set message "\002Stream is DOWN\002 after [streamDuration $stream(time)] at $stream(url)"
set stream(time) 0
}
set stream(status) $onair
putserv "privmsg $stream(channel) :$message"
}
}
}
Code: Select all
20:38 <suchybot> [20:38:00] Tcl error [streamUpOrDown]: can't use non-numeric string as operand of "-"
The problem is your stream, when its online, has no start_time given to it. It remains "null" the same as if it were offline. So when start_time isn't found, the script will now make use of [clock seconds] which will give an inaccurate time the stream has been up, but hey, thats the best you can do when you don't know how long it's been active eh?hayuto wrote:didn't edited anything yet just loaded it andCode: Select all
20:38 <suchybot> [20:38:00] Tcl error [streamUpOrDown]: can't use non-numeric string as operand of "-"
Code: Select all
# dailymotion stream thing-a-mah-jig
# speechles/#roms-isos on June 3rd, 2013
#
# This will check every minute if the stream has gone up or down
# and will announce the start and ending. When the stream is enabled,
# it will also announce the url and how long the stream has been going
# on the hour and half hour. So every 30 minutes give or take a few
# seconds. It's using bind to time rather than timers too. So far less
# overhead is required tracking things.
#--> config start
# channel everything occurs in
set stream(channel) "#kangaroopocket"
# url we announce for people to join
set stream(url) "http://www.dailymotion.com/video/xzlc83"
# url we use to obtain status information
set stream(api) "https://api.dailymotion.com/video/xzlc83"
# This one below you should _NEVER_ change unless you have
# issues with duration agos from start of videos
set stream(timezone) "%Y-%m-%d %H:%M:%S %Z"
# Use this to adjust minor clock sync issues -/+seconds
set stream(fixtime) "0"
# <-- config end
package require http
package require tls
::http::register https 443 [list ::tls::socket -require 0 -request 1]
if {![info exists stream(status)]} {
set stream(status) "false"
set stream(time) 0
}
proc streamDuration {time} {
global stream
set now [clock scan [clock format [clock seconds] -format $stream(timezone)] -gmt 1]
putlog "$now - $time + $stream(fixtime)"
return [duration [expr {$now - $time + $stream(fixtime)}]]
}
foreach t {30* 60*} { bind time - $t streamSpam }
proc streamSpam {args} {
global stream
if {[string equal true $stream(status)]} {
putserv "privmsg $stream(channel) :Live stream in progress at $stream(url) started [streamDuration $stream(time)] ago."
}
}
bind time - * streamUpOrDown
proc streamUpOrDown {args} {
global stream
if {[catch { http::geturl "$stream(api)?fields=onair,start_time" -timeout 3000 } http]} {
putlog "Dailymotion: [string totitle $http]"
return 0
}
if {![string equal -nocase [::http::status $http] "ok"]} {
putlog "Dailymotion: [string totitle [::http::status $http]]"
http::cleanup $http
return 0
}
set data [http::data $http]
http::cleanup $http
regexp -- {"onair"\:(.*?),} $data - onair
regexp -- {"start_time"\:(.*?)\}} $data - start
if {![info exists onair]} {
if {[regexp -- {"message"\:"(.*?)"} $data - message]} {
putserv "privmsg $stream(channel) :$message"
} else {
putlog "Dailymotion: Parsing error; unexpected data."
}
} else {
if {![string equal $onair $stream(status)]} {
if {[string equal true $onair]} {
if {[string equal null $start]} { set start [clock scan [clock format [clock seconds] -format $stream(timezone)] -gmt 1] }
set message "\002Stream is UP\002 started [streamDuration $start] ago. Come watch us live at $stream(url)"
set stream(time) $start
} else {
set message "\002Stream is DOWN\002 after [streamDuration $stream(time)] at $stream(url)"
set stream(time) 0
}
set stream(status) $onair
putserv "privmsg $stream(channel) :$message"
}
}
}