This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

i made simple script that check dailymotion livestream

Support & discussion of released scripts, and announcements of new releases.
Post Reply
h
hayuto
Voice
Posts: 14
Joined: Tue May 28, 2013 6:52 pm

i made simple script that check dailymotion livestream

Post by hayuto »

i made it for our channel only so you have to edit it

http://wonziu.tk/sprawdzstream.tar.bz2
what you think? :D
Last edited by hayuto on Thu Aug 29, 2013 7:07 pm, edited 10 times in total.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: i made simple script that check dailymotion livestream

Post by speechles »

hayuto wrote:what you think? :D
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: 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"
		}
	}
}
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.
h
hayuto
Voice
Posts: 14
Joined: Tue May 28, 2013 6:52 pm

Post by hayuto »

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? :D 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 :P

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 :D)
h
hayuto
Voice
Posts: 14
Joined: Tue May 28, 2013 6:52 pm

Post by hayuto »

didn't edited anything yet just loaded it and

Code: Select all

20:38 <suchybot> [20:38:00] Tcl error [streamUpOrDown]: can't use non-numeric string as operand of "-"
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

hayuto wrote:didn't edited anything yet just loaded it and

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?

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"
      }
   }
}
h
hayuto
Voice
Posts: 14
Joined: Tue May 28, 2013 6:52 pm

Post by hayuto »

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 :P 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 :)
h
hayuto
Voice
Posts: 14
Joined: Tue May 28, 2013 6:52 pm

Post by hayuto »

i updated the stream and translated all variables (first post in topic updated) to english if anyone want it ;) it have many functions now :P
Post Reply