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
|
||||
if {[string match {*jim} $argv0]} { set runmode cgi }
|
||||
|
||||
set schedtime 1200
|
||||
set schedtime 1200
|
||||
switch $runmode {
|
||||
cgi {
|
||||
set type [cgi_get type "full"]
|
||||
|
@ -15,8 +15,7 @@ switch $runmode {
|
|||
}
|
||||
cli {
|
||||
set type "full"
|
||||
if {"-X" in $argv} { set schedtime 7200 }
|
||||
if {"-x" in $argv} { set schedtime 7200 }
|
||||
if {[lsearch -nocase $argv "-x"] >= 0} { set schedtime 7200 }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,11 +60,11 @@ proc register_statusop {op name icon} {
|
|||
eval_plugins status 1
|
||||
|
||||
proc get_data {} {
|
||||
global pid exts
|
||||
global pid exts stream tsr tsrcnt
|
||||
|
||||
set ret {}
|
||||
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"
|
||||
set ret {}
|
||||
} else {
|
||||
|
@ -73,35 +72,64 @@ proc get_data {} {
|
|||
foreach line [split $data "\n"] {
|
||||
set typ [string index $line 0]
|
||||
switch $typ {
|
||||
a {
|
||||
set access [string index $line 1]
|
||||
}
|
||||
s {
|
||||
set size [string range $line 1 end]
|
||||
}
|
||||
n {
|
||||
if {[string first Video/ $line] == -1 && \
|
||||
[string first /media/ $line] == -1} {
|
||||
# strip initial n and trailing " (...)" if
|
||||
# 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
|
||||
}
|
||||
regsub -- { \([^\)]+\)$} $line "" line
|
||||
set ext [file extension $line]
|
||||
if {$ext ni $exts} continue
|
||||
set file [subst -nocommands -novariables \
|
||||
[string range $line 1 end]]
|
||||
# Skip HD-Fox TSR buffer
|
||||
if {$file eq "/media/drive1/.tsr/0.ts"} {
|
||||
|
||||
if {[string first Video/ $line] >= 0 ||
|
||||
[string first /media/ $line] >= 0} {
|
||||
if {$ext ni $exts} {
|
||||
continue
|
||||
}
|
||||
} 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
|
||||
}
|
||||
# Handle chase play (same file open twice
|
||||
# and recently written)
|
||||
if {[dict exists $ret $file] && \
|
||||
if {[dict exists $ret $file] &&
|
||||
$ext eq ".ts"} {
|
||||
set age [expr [clock seconds] - \
|
||||
[file mtime $file]]
|
||||
set age [expr [clock seconds] \
|
||||
- [file mtime $file]]
|
||||
if {$age < 60} {
|
||||
set ret($file) -1
|
||||
set access [lindex \
|
||||
[dict get $ret $file] 1]
|
||||
set ret($file) [list -1 $access]
|
||||
}
|
||||
} else {
|
||||
debug "$file = $size"
|
||||
set ret($file) $size
|
||||
} else {
|
||||
debug "$file = $size,$access"
|
||||
set ret($file) [list $size $access]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,11 +137,9 @@ proc get_data {} {
|
|||
}
|
||||
foreach file [dict keys $::ops] {
|
||||
if {![dict exists $ret $file]} {
|
||||
if {[file exists $file]} {
|
||||
set ret($file) [file size $file]
|
||||
} else {
|
||||
set ret($file) 0
|
||||
}
|
||||
set sz 0
|
||||
if {[file exists $file]} { set sz [file size $file] }
|
||||
set ret($file) [list $sz u]
|
||||
}
|
||||
}
|
||||
return $ret
|
||||
|
@ -139,9 +165,12 @@ proc add_output {icon mode name} {
|
|||
|
||||
set play 0
|
||||
set rec 0
|
||||
set stream 0
|
||||
set output {}
|
||||
set ops {}
|
||||
set model [system model]
|
||||
set tsr [file rootname [system tsr]]
|
||||
set tsrcnt 0
|
||||
|
||||
foreach opfile [glob -nocomplain -directory /tmp -tails -- ".bgop.*"] {
|
||||
set op [string range $opfile 6 end]
|
||||
|
@ -179,8 +208,9 @@ if {[llength $data]} {
|
|||
debug " NDATA: ($ndata)"
|
||||
set rr 0
|
||||
}
|
||||
set bnames [lsort [lmap x [array names data] { file tail $x }]]
|
||||
foreach file [array names data] {
|
||||
set bname [file rootname [file tail $file]]
|
||||
set bname [file tail $file]
|
||||
|
||||
set name [string map {
|
||||
"/mnt/hd2/My Video/" ""
|
||||
|
@ -189,17 +219,22 @@ if {[llength $data]} {
|
|||
".ts" ""
|
||||
} $file]
|
||||
|
||||
if {$data($file) == -1} {
|
||||
if {[lindex $data($file) 0] == -1} {
|
||||
set mode chase
|
||||
} elseif {$rr} {
|
||||
if {$file in $recs} {
|
||||
set mode rec
|
||||
} elseif {[llength [\
|
||||
lsearch -all $bnames $bname]] == 2} {
|
||||
# two different files having same file.ext open
|
||||
set mode copy
|
||||
} else {
|
||||
set mode play
|
||||
}
|
||||
} else {
|
||||
if {![dict exists $ndata $file]} continue
|
||||
if {$ndata($file) > $data($file)} {
|
||||
if {[lindex $ndata($file) 0] > \
|
||||
[lindex $data($file) 0]} {
|
||||
set mode rec
|
||||
} else {
|
||||
set mode play
|
||||
|
@ -231,8 +266,20 @@ if {[llength $data]} {
|
|||
}
|
||||
play {
|
||||
incr play
|
||||
set mode "Playing"
|
||||
set icon "745_1_10_Video_2Live.png"
|
||||
if {$play > $stream} {
|
||||
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 {
|
||||
if {[dict exists $statusops $mode]} {
|
||||
|
@ -272,23 +319,33 @@ if {![system instandby] && $play < 1} {
|
|||
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 "[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"} {
|
||||
set s "
|
||||
<span class=\"va stitem\">
|
||||
[epg channelicon $name 30 \
|
||||
{vertical-align: middle; padding: 0 4px 0 2px}]
|
||||
<span>Watching <i>$lcn: $name $prog</i></span>
|
||||
"
|
||||
append s "</span>"
|
||||
lappend output $s
|
||||
# 0 => no TSR; >=2 => TSR
|
||||
if {$tsrcnt == 0 || $tsrcnt == 2} {
|
||||
set s "Watching"
|
||||
} elseif {$tsrcnt == 3} {
|
||||
set s "Watching (delayed)"
|
||||
} else {
|
||||
set s "Watching $lcn: $name $prog"
|
||||
lappend output $s
|
||||
debug "tsrcnt=$tsrcnt"
|
||||
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
|
||||
|
||||
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] "]
|
||||
foreach event $events {
|
||||
if {$runmode eq "cgi"} {
|
||||
|
|
|
@ -398,6 +398,22 @@ proc {system disktemp} {} {
|
|||
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
|
||||
|
||||
proc {system diskspace} {{raw 0}} {
|
||||
|
@ -412,13 +428,12 @@ proc {system diskspace} {{raw 0}} {
|
|||
set perc $($used * 100 / $size)
|
||||
set fperc $(100 - $perc)
|
||||
|
||||
set tsrdir [system tsrdir]
|
||||
switch [system model] {
|
||||
HDR {
|
||||
set tsrdir "/mnt/hd2/Tsr"
|
||||
set tsrok [file isdirectory $tsrdir]
|
||||
}
|
||||
HD {
|
||||
set tsrdir "/media/drive1/.tsr"
|
||||
set tsrok [file exists "$tsrdir/0.ts"]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue