webif/var/mongoose/cgi-bin/status.jim
hummypkg b691be415a quick edit, cli status, db.jim
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1164 2a923420-c742-0410-a762-8d5b09965624
2012-10-15 21:32:25 +00:00

146 lines
3.1 KiB
Plaintext
Executable File

#!/mod/bin/jimsh
package require cgi
source /mod/webif/lib/setup
require system.class findhsvc epg.class
set runmode cli
if {[string match {*jim} $argv0]} { set runmode cgi }
cgi_input
set type [cgi_get type "full"]
if {$runmode eq "cgi"} {
puts "Content-Type: text/html"
puts "Pragma: no-cache"
puts "Expires: Thu, 01 Jan 1970 00:00:00 GMT"
puts ""
}
if {[catch {set pid [exec pgrep humaxtv]}]} {
puts "Cannot find humaxtv process."
exit
}
proc get_data {} {
global pid
set ret {}
if {[catch {set data \
[exec /mod/bin/lsof -p $pid | grep Video | fgrep .ts]} ]} {
set ret {}
} else {
foreach line [split $data "\n"] {
regsub -all -- {[[:space:]]+} $line " " line
set name [file rootname [file tail $line]]
if {[dict exists $ret $name]} {
set ret($name) -1
} else {
set size [lindex [split $line " "] 6]
set ret($name) $size
}
}
}
return $ret
}
set play 0
set rec 0
set seen {}
set output {}
if {$type eq "full"} {
set data [get_data]
} else {
set data {}
}
if {[llength $data]} {
sleep 3
set ndata [get_data]
foreach name [array names ndata] {
if {![dict exists $seen $name]} { set seen($name) 0 }
if {![dict exists $data $name]} { set data($name) 0 }
if {$ndata($name) == -1} {
incr rec
incr play
set mode "Chase Playing"
set icon "745_1_11_Video_3REC_Live.png"
} elseif {$ndata($name) > $data($name) && $seen($name) < 1} {
incr rec
set mode "Recording"
set icon "745_1_11_Video_1REC.png"
} else {
incr play
set mode "Playing"
set icon "745_1_10_Video_2Live.png"
}
incr seen($name)
if {$runmode eq "cgi"} {
lappend output "<img class=va src=/images/$icon>
<span class=va>$mode&nbsp;<i>$name</i></span>"
} else {
lappend output "$mode $name"
}
}
}
if {![system instandby] && $play < 1} {
set hsvc [system param CUR_SVC Value USERCONFIG]
set ff [$rsvdb query "
select usSvcid as svcid, usLcn as lcn,
substr(szSvcName, 2) as name
from channel.TBL_SVC
where hSvc = $hsvc
limit 1
"]
if {[llength $ff] == 1} {
lassign [lindex $ff 0] x svcid x lcn x name
set epgs [epg dbfetch get \
-service $svcid \
-time [clock seconds]\
]
set prog ""
if {[llength $epgs] == 1} {
lassign $epgs epg
set prog "- [$epg get name] ("
append prog "[clock format [$epg get start] -format %H:%M] - "
append prog "[clock format $([$epg get start] + [$epg get duration]) -format %H:%M]"
append prog ") \[[$epg percent]%\]"
}
if {$runmode eq "cgi"} {
lappend output "[epg channelicon $name 30 \
{vertical-align: middle; padding: 0 4px 0 2px}]
<span class=va>
Watching <i>$lcn: $name $prog</i></span>"
} else {
lappend output "Watching $lcn: $name $prog"
}
}
}
if {[system instandby]} {
if {$runmode eq "cgi"} {
lappend output "<img class=va width=28 style=\"padding: 0 4px\"
src=/img/standby.png>
<span class=va>System is in standby.</span>"
} else {
lappend output "System is in standby."
}
}
if {[llength $output]} {
if {$runmode eq "cgi"} {
puts [join $output "<br>"]
} else {
puts [join $output "\n"]
}
}