forked from hummypkg/webif
Improve status, adding more possible outputs
- check for copying vs playing: the same file.ext is open twice - check for playing DLNA: localhost:n->host:9000 - on HDR, distinguish Playing a show vs streaming it over DLNA - distinguish between Watching, Watching (delayed) (timeshift), and Not Watching (eg Portal).
This commit is contained in:
parent
18bed926b3
commit
5d3b046c70
|
@ -7,7 +7,7 @@ require system.class epg.class rsv.class svc.class plugin
|
||||||
set runmode cli
|
set runmode cli
|
||||||
if {[string match {*jim} $argv0]} { set runmode cgi }
|
if {[string match {*jim} $argv0]} { set runmode cgi }
|
||||||
|
|
||||||
set schedtime 1200
|
set schedtime 1200
|
||||||
switch $runmode {
|
switch $runmode {
|
||||||
cgi {
|
cgi {
|
||||||
set type [cgi_get type "full"]
|
set type [cgi_get type "full"]
|
||||||
|
@ -15,8 +15,7 @@ switch $runmode {
|
||||||
}
|
}
|
||||||
cli {
|
cli {
|
||||||
set type "full"
|
set type "full"
|
||||||
if {"-X" in $argv} { set schedtime 7200 }
|
if {[lsearch -nocase $argv "-x"] >= 0} { set schedtime 7200 }
|
||||||
if {"-x" in $argv} { set schedtime 7200 }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,11 +60,11 @@ proc register_statusop {op name icon} {
|
||||||
eval_plugins status 1
|
eval_plugins status 1
|
||||||
|
|
||||||
proc get_data {} {
|
proc get_data {} {
|
||||||
global pid exts
|
global pid exts stream tsr tsrcnt
|
||||||
|
|
||||||
set ret {}
|
set ret {}
|
||||||
if {[catch {set data \
|
if {[catch {set data \
|
||||||
[exec /mod/webif/lib/bin/lsof -X -Fns -p $pid]} msg]} {
|
[exec /mod/webif/lib/bin/lsof -Fnsa -p $pid]} msg]} {
|
||||||
debug "Error: $msg"
|
debug "Error: $msg"
|
||||||
set ret {}
|
set ret {}
|
||||||
} else {
|
} else {
|
||||||
|
@ -73,35 +72,64 @@ proc get_data {} {
|
||||||
foreach line [split $data "\n"] {
|
foreach line [split $data "\n"] {
|
||||||
set typ [string index $line 0]
|
set typ [string index $line 0]
|
||||||
switch $typ {
|
switch $typ {
|
||||||
|
a {
|
||||||
|
set access [string index $line 1]
|
||||||
|
}
|
||||||
s {
|
s {
|
||||||
set size [string range $line 1 end]
|
set size [string range $line 1 end]
|
||||||
}
|
}
|
||||||
n {
|
n {
|
||||||
if {[string first Video/ $line] == -1 && \
|
# strip initial n and trailing " (...)" if
|
||||||
[string first /media/ $line] == -1} {
|
# present
|
||||||
|
regsub -all -- {(^n)|( \([^\)]+\)$)} \
|
||||||
|
$line "" line
|
||||||
|
set file [subst -nocommands -novariables $line]
|
||||||
|
set ext [file extension $line]
|
||||||
|
# Note but skip TSR buffers
|
||||||
|
if {[file rootname $file] eq $tsr} {
|
||||||
|
if {$ext eq ".nts"} {
|
||||||
|
incr tsrcnt
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
regsub -- { \([^\)]+\)$} $line "" line
|
|
||||||
set ext [file extension $line]
|
if {[string first Video/ $line] >= 0 ||
|
||||||
if {$ext ni $exts} continue
|
[string first /media/ $line] >= 0} {
|
||||||
set file [subst -nocommands -novariables \
|
if {$ext ni $exts} {
|
||||||
[string range $line 1 end]]
|
continue
|
||||||
# Skip HD-Fox TSR buffer
|
}
|
||||||
if {$file eq "/media/drive1/.tsr/0.ts"} {
|
} elseif {[string first $line /] >= 0} {
|
||||||
|
# fast skip other files
|
||||||
|
continue
|
||||||
|
} elseif {[regexp -- {[A-Za-z0-9._-]+:([0-9]+)->([A-Za-z0-9._-]+):([0-9]+)} $line _ sprt host dprt]} {
|
||||||
|
if {$sprt == 9000} {
|
||||||
|
incr stream
|
||||||
|
continue
|
||||||
|
} elseif {$dprt == 9000} {
|
||||||
|
set file [\
|
||||||
|
format "DLNA from %s" $host]
|
||||||
|
set size 0
|
||||||
|
set ext ""
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
# Handle chase play (same file open twice
|
# Handle chase play (same file open twice
|
||||||
# and recently written)
|
# and recently written)
|
||||||
if {[dict exists $ret $file] && \
|
if {[dict exists $ret $file] &&
|
||||||
$ext eq ".ts"} {
|
$ext eq ".ts"} {
|
||||||
set age [expr [clock seconds] - \
|
set age [expr [clock seconds] \
|
||||||
[file mtime $file]]
|
- [file mtime $file]]
|
||||||
if {$age < 60} {
|
if {$age < 60} {
|
||||||
set ret($file) -1
|
set access [lindex \
|
||||||
|
[dict get $ret $file] 1]
|
||||||
|
set ret($file) [list -1 $access]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug "$file = $size"
|
debug "$file = $size,$access"
|
||||||
set ret($file) $size
|
set ret($file) [list $size $access]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,11 +137,9 @@ proc get_data {} {
|
||||||
}
|
}
|
||||||
foreach file [dict keys $::ops] {
|
foreach file [dict keys $::ops] {
|
||||||
if {![dict exists $ret $file]} {
|
if {![dict exists $ret $file]} {
|
||||||
if {[file exists $file]} {
|
set sz 0
|
||||||
set ret($file) [file size $file]
|
if {[file exists $file]} { set sz [file size $file] }
|
||||||
} else {
|
set ret($file) [list $sz u]
|
||||||
set ret($file) 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $ret
|
return $ret
|
||||||
|
@ -139,9 +165,12 @@ proc add_output {icon mode name} {
|
||||||
|
|
||||||
set play 0
|
set play 0
|
||||||
set rec 0
|
set rec 0
|
||||||
|
set stream 0
|
||||||
set output {}
|
set output {}
|
||||||
set ops {}
|
set ops {}
|
||||||
set model [system model]
|
set model [system model]
|
||||||
|
set tsr [file rootname [system tsr]]
|
||||||
|
set tsrcnt 0
|
||||||
|
|
||||||
foreach opfile [glob -nocomplain -directory /tmp -tails -- ".bgop.*"] {
|
foreach opfile [glob -nocomplain -directory /tmp -tails -- ".bgop.*"] {
|
||||||
set op [string range $opfile 6 end]
|
set op [string range $opfile 6 end]
|
||||||
|
@ -179,8 +208,9 @@ if {[llength $data]} {
|
||||||
debug " NDATA: ($ndata)"
|
debug " NDATA: ($ndata)"
|
||||||
set rr 0
|
set rr 0
|
||||||
}
|
}
|
||||||
|
set bnames [lsort [lmap x [array names data] { file tail $x }]]
|
||||||
foreach file [array names data] {
|
foreach file [array names data] {
|
||||||
set bname [file rootname [file tail $file]]
|
set bname [file tail $file]
|
||||||
|
|
||||||
set name [string map {
|
set name [string map {
|
||||||
"/mnt/hd2/My Video/" ""
|
"/mnt/hd2/My Video/" ""
|
||||||
|
@ -189,17 +219,22 @@ if {[llength $data]} {
|
||||||
".ts" ""
|
".ts" ""
|
||||||
} $file]
|
} $file]
|
||||||
|
|
||||||
if {$data($file) == -1} {
|
if {[lindex $data($file) 0] == -1} {
|
||||||
set mode chase
|
set mode chase
|
||||||
} elseif {$rr} {
|
} elseif {$rr} {
|
||||||
if {$file in $recs} {
|
if {$file in $recs} {
|
||||||
set mode rec
|
set mode rec
|
||||||
|
} elseif {[llength [\
|
||||||
|
lsearch -all $bnames $bname]] == 2} {
|
||||||
|
# two different files having same file.ext open
|
||||||
|
set mode copy
|
||||||
} else {
|
} else {
|
||||||
set mode play
|
set mode play
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if {![dict exists $ndata $file]} continue
|
if {![dict exists $ndata $file]} continue
|
||||||
if {$ndata($file) > $data($file)} {
|
if {[lindex $ndata($file) 0] > \
|
||||||
|
[lindex $data($file) 0]} {
|
||||||
set mode rec
|
set mode rec
|
||||||
} else {
|
} else {
|
||||||
set mode play
|
set mode play
|
||||||
|
@ -231,8 +266,20 @@ if {[llength $data]} {
|
||||||
}
|
}
|
||||||
play {
|
play {
|
||||||
incr play
|
incr play
|
||||||
set mode "Playing"
|
if {$play > $stream} {
|
||||||
set icon "745_1_10_Video_2Live.png"
|
set mode "Playing"
|
||||||
|
set icon "745_1_10_Video_2Live.png"
|
||||||
|
} else {
|
||||||
|
set mode "Streaming"
|
||||||
|
set icon "/img/dlna.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
copy {
|
||||||
|
if {[lindex $data($file) 1] ne "r"} {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
set mode "Copying"
|
||||||
|
set icon "/img/dlna.png"
|
||||||
}
|
}
|
||||||
default {
|
default {
|
||||||
if {[dict exists $statusops $mode]} {
|
if {[dict exists $statusops $mode]} {
|
||||||
|
@ -272,23 +319,33 @@ if {![system instandby] && $play < 1} {
|
||||||
if {[llength $epgs] == 1} {
|
if {[llength $epgs] == 1} {
|
||||||
lassign $epgs epg
|
lassign $epgs epg
|
||||||
set prog "- [$epg get name] ("
|
set prog "- [$epg get name] ("
|
||||||
append prog "[clock format [$epg get start] -format %H:%M] - "
|
append prog "[clock format [\
|
||||||
append prog "[clock format $([$epg get start] + [$epg get duration]) -format %H:%M]"
|
$epg get start] -format %H:%M] - "
|
||||||
|
append prog "[clock format $([$epg get start] \
|
||||||
|
+ [$epg get duration]) -format %H:%M]"
|
||||||
append prog ") \[[$epg percent]%\]"
|
append prog ") \[[$epg percent]%\]"
|
||||||
}
|
}
|
||||||
|
|
||||||
if {$runmode eq "cgi"} {
|
# 0 => no TSR; >=2 => TSR
|
||||||
set s "
|
if {$tsrcnt == 0 || $tsrcnt == 2} {
|
||||||
<span class=\"va stitem\">
|
set s "Watching"
|
||||||
[epg channelicon $name 30 \
|
} elseif {$tsrcnt == 3} {
|
||||||
{vertical-align: middle; padding: 0 4px 0 2px}]
|
set s "Watching (delayed)"
|
||||||
<span>Watching <i>$lcn: $name $prog</i></span>
|
|
||||||
"
|
|
||||||
append s "</span>"
|
|
||||||
lappend output $s
|
|
||||||
} else {
|
} else {
|
||||||
set s "Watching $lcn: $name $prog"
|
debug "tsrcnt=$tsrcnt"
|
||||||
lappend output $s
|
set s "Not watching"
|
||||||
|
}
|
||||||
|
if {$runmode eq "cgi"} {
|
||||||
|
lappend output [format "
|
||||||
|
<span class=\"va stitem\">
|
||||||
|
[epg channelicon %s 30 \
|
||||||
|
{vertical-align: middle; padding: 0 4px 0 2px}]
|
||||||
|
<span>%s <i>%s: %s %s</i></span>
|
||||||
|
</span>
|
||||||
|
" $name $s $lcn $name $prog]
|
||||||
|
} else {
|
||||||
|
lappend output [format "%s %s: %s %s" \
|
||||||
|
$s $lcn $name $prog]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,7 +371,7 @@ if {[system instandby]} {
|
||||||
# Upcoming recordings
|
# Upcoming recordings
|
||||||
|
|
||||||
set events [rsv list tbl_reservation \
|
set events [rsv list tbl_reservation \
|
||||||
" where ersvtype = 3 and nsttime - [clock seconds] < $schedtime
|
" where ersvtype = 3 and nsttime - [clock seconds] < $schedtime
|
||||||
and nsttime > [clock seconds] "]
|
and nsttime > [clock seconds] "]
|
||||||
foreach event $events {
|
foreach event $events {
|
||||||
if {$runmode eq "cgi"} {
|
if {$runmode eq "cgi"} {
|
||||||
|
|
|
@ -398,6 +398,22 @@ proc {system disktemp} {} {
|
||||||
return $($temp + 0)
|
return $($temp + 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc {system tsrdir} {} {
|
||||||
|
switch [system model] {
|
||||||
|
HDR {
|
||||||
|
set tsrdir "/mnt/hd2/Tsr"
|
||||||
|
}
|
||||||
|
HD {
|
||||||
|
set tsrdir "/media/drive1/.tsr"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $tsrdir
|
||||||
|
}
|
||||||
|
|
||||||
|
proc {system tsr} {} {
|
||||||
|
return [file join [system tsrdir] "0.ts"]
|
||||||
|
}
|
||||||
|
|
||||||
require pretty_size
|
require pretty_size
|
||||||
|
|
||||||
proc {system diskspace} {{raw 0}} {
|
proc {system diskspace} {{raw 0}} {
|
||||||
|
@ -412,13 +428,12 @@ proc {system diskspace} {{raw 0}} {
|
||||||
set perc $($used * 100 / $size)
|
set perc $($used * 100 / $size)
|
||||||
set fperc $(100 - $perc)
|
set fperc $(100 - $perc)
|
||||||
|
|
||||||
|
set tsrdir [system tsrdir]
|
||||||
switch [system model] {
|
switch [system model] {
|
||||||
HDR {
|
HDR {
|
||||||
set tsrdir "/mnt/hd2/Tsr"
|
|
||||||
set tsrok [file isdirectory $tsrdir]
|
set tsrok [file isdirectory $tsrdir]
|
||||||
}
|
}
|
||||||
HD {
|
HD {
|
||||||
set tsrdir "/media/drive1/.tsr"
|
|
||||||
set tsrok [file exists "$tsrdir/0.ts"]
|
set tsrok [file exists "$tsrdir/0.ts"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue