| View previous topic :: View next topic |
| Author |
Message |
hayuto Voice
Joined: 28 May 2013 Posts: 14
|
Posted: Sun Jun 02, 2013 1:57 am Post subject: i made simple script that check dailymotion livestream |
|
|
i made it for our channel only so you have to edit it
http://wonziu.tk/sprawdzstream.tar.bz2
what you think? 
Last edited by hayuto on Thu Aug 29, 2013 7:07 pm; edited 10 times in total |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jun 02, 2013 4:46 am Post subject: Re: i made simple script that check dailymotion livestream |
|
|
| hayuto wrote: | 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.
| Code: | # 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"
}
}
} |
Yes, it does it all within this one script. If you have problems, notice bugs, let me know. I only tested this "in my head".
Note: The start time used for this is the "actual" time the stream began. So starting the stream, then 4 hours later the bot joins. It will announce the stream is up and started 4 hours ago. Then every 30 minutes it will keep announcing there is a live stream running and for how long its been up until you switch off the stream. At that point it will announce the stream is down and how long the stream was up previously. It will only issue up/down announcement if the status of the stream has changed. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
hayuto Voice
Joined: 28 May 2013 Posts: 14
|
Posted: Sun Jun 02, 2013 9:57 am Post subject: |
|
|
will it be less resource heavy if i check every 5 seconds within the script, instead of wget? i want to check every 5 seconds, what good from script that will tell us the stream started after it has been live for whole minute? i always tought wget is super fast and super optimized, and also i changed couple things here and there since i posted so i really dont know whats better now.
i now use duration from russian peak.tcl script which i translated to polish it works as supposed it use proper grammar for our language:
http://paste.tclhelp.net/?id=ddk (edit forgot about http://paste.tclhelp.net/?id=ddl)
i also use @reboot cron command and do; while bash script
i love your code and want to use it
will it be better, is it faster then wget? i dont know how to test it in long run
anyways i will load it later and tell you if it works ok (but it have to announce immidietly when stream starts and ends so i need to figure out first how to change it ) |
|
| Back to top |
|
 |
hayuto Voice
Joined: 28 May 2013 Posts: 14
|
Posted: Sun Jun 02, 2013 2:38 pm Post subject: |
|
|
didn't edited anything yet just loaded it and
| Code: |
20:38 <suchybot> [20:38:00] Tcl error [streamUpOrDown]: can't use non-numeric string as operand of "-"
|
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jun 02, 2013 3:22 pm Post subject: |
|
|
| hayuto wrote: | didn't edited anything yet just loaded it and
| Code: |
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?
| Code: | # 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"
}
}
} |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
hayuto Voice
Joined: 28 May 2013 Posts: 14
|
Posted: Mon Jun 03, 2013 12:43 pm Post subject: |
|
|
thanks
i dont know since yesterday i put much work in my own script maybe it isnt super pretty but it have now many function like having a list of all past streams with date and length, it can show status, and it announce immidietly when the stream starts and stops even if bot is restarted it will know if stream status changed while it was offline cause it is done by wget etc
its badly writen but it works
but thank you anyways for your effort im sure someone will look for something like this sooner or later on google and will find this topic, so i put here my script as well when im done (maybe) he will have a choice  |
|
| Back to top |
|
 |
hayuto Voice
Joined: 28 May 2013 Posts: 14
|
Posted: Tue Jun 04, 2013 12:58 pm Post subject: |
|
|
i updated the stream and translated all variables (first post in topic updated) to english if anyone want it it have many functions now  |
|
| Back to top |
|
 |
|