Version 0.1.2-1 - first version on Git

This commit is contained in:
Bob Buxton 2020-02-28 00:10:33 +00:00
commit ae56e34ceb
10 changed files with 640 additions and 0 deletions

12
CONTROL/control Normal file
View File

@ -0,0 +1,12 @@
Package: chaseget
Priority: optional
Section: misc
Version: 0.1.2-3
Architecture: mipsel
Maintainer: mymsman
Depends: webif(>=1.4.4-7), curl, ir (>=1.10-2), procps
Description: Retrieve and decrypt recording, can run whilst recording is still in progress
This is intended to be used as part of other packages (such as detectads) rather than used standalone
Runs as first stage of pipeline, output is always to stdout
Usage= /mod/bin/chaseget recording.ts start_offset logfile > output.ts
Tags: http://wiki.hummy.tv/wiki/DetectAds

15
CONTROL/postinst Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
export tmpf=/tmp/cronf.$$
# Add cron jobs
crontab=$PKG_ROOT/bin/crontab
if [ -x $crontab ]; then
$crontab -l | grep -v /mod/bin/chaseget > $tmpf
cat $tmpf - << EOM | $crontab -
13-59/20 * * * * /mod/bin/chaseget -standby>/dev/null 2>&1
EOM
fi
[ -f $tmpf ] && rm -f $tmpf

456
bin/chaseget Executable file
View File

@ -0,0 +1,456 @@
#!/mod/bin/jimsh
# Retrieve recording via dlna (using curl) whilst recording is still in progress and write it to stdout for use in pipelines
source /mod/webif/lib/setup
require lock system.class ts.class settings.class rsv.class
set loglevel 0
set status 0
catch {
# Use same logging option as auto log
set settings [settings]
set loglevel [$settings _nval_setting "autolog"]
set status [$settings _nval_setting "chaseget_status" ]
}
if {[lindex $argv 0] eq "-d"} {
set argv [lrange $argv 1 end]
set loglevel 2
}
proc log {msg {level 2}} {
if {$level > $::loglevel} return
system plog $::logfile "CG([pid])- $msg"
#puts $::logfd "[\
# clock format [clock seconds] -format "%d/%m/%Y %H:%M:%S"\
# ] CG([pid])- $msg"
#flush $::logfd
}
proc help_text {} {
puts "chaseget - Retrieve recording via dlna (using curl) whilst recording is still in progress and write it to stdout for use in pipelines"
puts ""
puts "chaseget -d options = Detailed debug output"
puts "chaseget recording.ts start_offset logfile = Retrieve recording"
puts "chaseget -standby ignoreTerminals logfile = Check whether safe to put system back into standby (ignoreTerminals 0=No 1=Yes)"
puts "chaseget -help = This help text"
puts "Author MymsMan see http://hummy.tv/forum/forums/hd-hdr-fox-t2-customised-firmware.28/ for more information"
}
set file [lindex $argv 0]
set fs [lindex $argv 1]
if {$fs eq ""} {set fs 0}
set logfile [lindex $argv 2]
if {$logfile eq ""} {set logfile "chaseget"}
#set logfd [open $logfile "a+"]
set ::awfile "/mod/etc/chaseget_awakened"
proc getfile {file {fs 0}} {
set ts [ts fetch $file]
log "ChaseGet $file" 0
set blksize $(256*1024)
# extract recording info & calculate
# - full recording size when complete
# - remaining recording time and retrieval rate
set stime [$ts get start]
set etime [$ts get end]
log "Recording start: [clock format $stime -format "%H:%M:%S"] end: [clock format $etime -format "%H:%M:%S"]"
set csize [file size "$file"]
set dlnaretry 0
set dlnaalert 0
while {$csize > $fs} {
if {[system dlnastatus]} {
set dlnaok 1
set dlnaretry 0
set dlnaalert 0
#log "DLNA Server is running." 2
} else {
set dlnaok 0
incr dlnaretry
log "DLNA Server is NOT running." 0
# Attempt to turn box fully on using IR package
if {[system instandby]} {
awake_from_standy
}
# Check file sharing enabled
if {![system param DMS_START_ON]} {
log "Content Sharing Disabled" 0
if {!$dlnaalert} {
set dlnaalert 1
system notify "ChaseGet: Contents sharing disabled, Enable via Humax Settings menu"
}
}
if {$dlnaretry >10} {
log "DLNA Server is still NOT running. Giving up" 0
return "DLNA Server is still NOT running. Giving up"
}
sleep 60
continue
}
set ctime [clock seconds]
set elapsed $($ctime-$stime)
set durn $($etime-$stime)
set remain $($etime-$ctime)
log "duration: $durn elapsed: $elapsed remaining: $remain" 2
if {$remain > 0} {
# Now using time slicing rather than throttling
# set totsize $($csize*$durn/$elapsed)
# set recrate $($csize/$elapsed)
# set drate $(($totsize-$fs)/($remain))
# log "est total size: $totsize recording rate: $recrate download rate limit: $drate"
# set lrate "--limit-rate $($drate*1)"
# sleep 10
set lrate ""
} else { set lrate ""}
set retrct 0
lassign [$ts dlnaloc "127.0.0.1"] url
if {$url ne ""} {
log " $file - has been indexed."
set helper 0
} else {
log " $file - Not yet indexed, trying helper."
if {[catch {
lassign [system dlnahelper [file normalize $file]] url
} msg]} {
log " $file - $msg"
system dlnahelper -release
}
if {$url eq ""} {
log " $file - Can't use helper. retry"
# system dlnahelper -release
if {$remain > 30} {sleep 15} else {sleep 5}
continue
}
set helper 1
}
log "Start at offset $fs cur recording size: $csize DLNA: $url" 2
if {!$::status} {
# show sctive on webif status display
set statustok [system startop -multiple chaseget $file]
}
if {[catch -break -eval -signal -- {
set input [open "|curl -C $fs $lrate $url 2> /dev/null "]
} msg opts]} {
log "Open caught: $msg $opts" 1
break
}
log "Curl pid [pid $input]" 2
while {1} {
if {[catch -break -eval -signal -- {
set block [read $input $blksize]
puts -nonewline $block
flush stdout
} msg opts]} {
log "caught: $msg $opts" 0
# set ps [exec ps -Af]
# log $ps
break
}
incr fs [string bytelength $block]
incr retrct [string bytelength $block]
if {[eof $input]} {
log "EOF detected $fs $retrct" 2
break
}
}
close $input
# Short sleep to allow pipeline to drain and for more data to accumulate on input
# Helper lock still held so parallel recording doesn't start getting and overload CPU
sleep 3
# Release the helper lock once finished.
if {$helper} { system dlnahelper -release }
if {!$::status} {
# not active for status
system endop $statustok
}
if {$retrct==0} {
log "No data returned" 1
break
}
set ctime [clock seconds]
set remain $($etime-$ctime)
if {$remain > 60} {
# Sleep if not close to recording end to allow other recordings a chance to get in and for more data to accumulate
log "snoozzzing" 2
sleep 30
} else {
sleep 3
}
set csize [file size "$file"]
}
if {[file size $file] >$fs } {
log " Failed to retrieve entire file $([file size $file] -$fs) bytes missing" 0
log " Attempt to recreate failure message" 1
set curlout ""; set msg ""; set opts ""
catch {set curlout [exec curl -C $fs $url > /dev/null]} msg opts
log "Curl message: $msg" 1
log "Curl error: $opts" 1
log "Curl output: $curlout" 1
return -code error $msg
}
log "ChaseGet end $file Size $fs bytes" 0
#log "-----------------------------------------------" 2
return $fs
}
# Check whether now is within time range, time formats hh:mm
proc inTimeRange {start end} {
set now [clock format [clock seconds] -format "%H:%M"]
log "Now $now Range $start - $end" 2
if {$start eq $end} {return 0}
if {$start <= $end} {
# start and stop times are in the same day
if {$now >= $start && $now <= $end} {
# current time is between start and stop
return 1
}
} else {
# start and stop times are in different days
if {$now >= $start || $now <= $end} {
# current time is between start and stop
return 1
}
}
# outside range
return 0
}
proc awake_from_standy {} {
catch {exec ir POWER}
log "System power on attempted" 0
set settings [settings]
set mute [$settings _nval_setting "chaseget_mute" ]
set standby_start [$settings _tval_setting "chaseget_standby_start1"]
set standby_end [$settings _tval_setting "chaseget_standby_end1"]
if {$mute && ![inTimeRange "$standby_start" "$standby_end"]} {
sleep 2
# Mute in case it comes on in middle of night and to provoke button push by passive viewer
catch {exec ir MUTE}
log "Sound mute attempted" 1
}
catch {exec touch $::awfile}
#[settings new] _nval_setting "chaseget_awakened" [clock seconds]
}
proc awakened_by_chaseget {} {
#set settings [settings]
#set ::awakened [$settings _nval_setting "chaseget_awakened"]
if {[file exists $::awfile]} {
set ::awakened [file mtime $::awfile]
log "Awakened by ChaseGet at [clock format $::awakened -format %T]" 2
return 1
} else {
set ::awakened 0
return 0
}
}
proc clear_awakened_status {} {
# [settings new] _nval_setting "chaseget_awakened" 0
file delete $::awfile
set ::awakened 0
}
proc standby_check {{ignoreTerm 1}} {
# Quit quietly if nothing to do
set settings [settings]
set standby_start [$settings _tval_setting "chaseget_standby_start1"]
set standby_end [$settings _tval_setting "chaseget_standby_end1"]
#set lastboot $([clock seconds] - round([system uptime]))
#log "Last boot time [clock format $lastboot -format %T]" 2
if {[inTimeRange "$standby_start" "$standby_end"]} {
log "Standby check disabled - quit" 2
exit
}
if {![awakened_by_chaseget]} {
log "Not awakened by chaseget - quit" 2
exit
}
log "ChaseGet - standby_check starting" 1
if {[system instandby]} {
log "System in standby - quit" 1
clear_awakened_status
exit
}
# foreach {process in detectads, auto, ...} {
# # process list should probably be in a config file to allow easy update
# # what others?
# if {process active} { exit }
# }
# open and read configuration file
set cf "/mod/etc/chaseget.conf"
if {![catch {set fp [open $cf r]}]} {
set clist [split [read $fp] "\n"]
} else {
set clist {}
}
# Check if proces in list is active
foreach process $clist {
if {![string length $process]} continue
log "Checking entry: $process" 2
set status [catch {exec pgrep -x $process} ]
if {$status == 0} {
log "Active process $process - quit" 1
return 0
}
}
# # can putty/telnet users be detected ?
set termct [exec ls /dev/pts | wc -l]
log "Pseudo terminals: $termct" 2
if {!$ignoreTerm && $termct > 0 } {
log "Active terminals $termct - quit" 1
return 0
}
#
# if { last boot time > chaseget awakened time} {
# Clear awakend by chaseget status
# exit
# }
# Ideally should be: set lastboot [system lastboottime]
#set lastboot [file mtime "/tmp/if-up"]
set lastboot $([clock seconds] - round([system uptime]))
log "Last boot time [clock format $lastboot -format %T]" 2
if {$lastboot > $::awakened} {
log "Boot time [clock format $lastboot -format %T] > Awakened time [clock format $::awakened -format %T] - quit" 1
clear_awakened_status
return 0
}
#
# if { any .ts in use (except recording) } { exit }
#
set ret {}
# Get a list of unique in-use .ts files
if {[catch {set data [exec /mod/webif/lib/bin/lsof -Fns | grep {\.ts} | sort -u ]} msg]} {
set ret {}
} else {
set flist ""
foreach line [split $data "\n"] {
set file [string range $line 1 end]
if {[file tail $file] eq "0.ts"} continue
set csize [file size "$file"]
log "In use $file size $csize" 2
lappend flist [list $file $csize]
}
sleep 2
# Check for files size change over last few seconds - indicates recording in progress
foreach line $flist {
lassign $line file csize
set nsize [file size "$file"]
log "In use $file size $csize -> $nsize" 2
if {$csize == $nsize} {
log "In use $file not recording -quit" 1
return
} else { log "In use $file is recording OK" 2 }
}
}
#
# # Need check for within a reminder period?
set now [clock seconds]
set events [rsv list tbl_reservation \
" where ersvtype = 2 and nsttime < $now and nsttime + nduration > $now "]
if {[llength $events]} {
foreach event $events {
log [concat \
"Reminder '[$event name]' " \
"on [$event channel_name] at " \
"[clock format [$event get nsttime] -format {%H:%M}]" \
" duration [clock format [$event get nduration] -format {%H:%M}]" \
] 2
}
log "Current reminders= [llength $events] - quit" 1
return 0
} else {log "No reminders found" 2}
# if {idle time < now - chaseget awakened time} {
# # Buttons pressed since woken
# if {last button != 'power'} {
# Clear awakend by chaseget status
# exit
# }
# }
set idletime [system idletime]
set now [clock seconds]
if {$idletime < $now - $::awakened} {
set lastir 0
if {[file readable /tmp/.lastir]} {
set lastir [file read /tmp/.lastir -nonewline]
}
# Buttons pressed since woken
log "Remote Buttons pressed (last button $lastir) - quit" 1
clear_awakened_status
return 0
}
# # No current activity since awakened
#
# ir power
# Clear awakend by chaseget status
# Check system hasn't re-entered standby of it its own accord whilst we werent looking
if {[system instandby]} {
log "System in standby - quit" 1
clear_awakened_status
exit
}
log "System power Off attempted, ChaseGet power On was at [clock format $::awakened -format %T] " 0
clear_awakened_status
catch {exec ir POWER}
}
switch -- $file {
"-standby" {
standby_check $fs
}
"--help" -
"-help" -
"--h" -
"-h" -
"" {
help_text
}
default {
getfile $file $fs
}
}
exit

10
etc/chaseget.conf Normal file
View File

@ -0,0 +1,10 @@
detectads
rset
srma
fix-disk
wget
curl
ffmpeg
deq
rs_process
chasedecrypt

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

28
webif/plugin/chaseget/save.jim Executable file
View File

@ -0,0 +1,28 @@
#!/mod/bin/jimsh
# mymsman 151008
package require cgi
source /mod/webif/lib/setup
require settings.class
httpheader
set mute [cgi_get chaseget_mute no ]
set status [cgi_get chaseget_status no ]
set standby_start1 [cgi_get chaseget_standby_start1 ""]
set standby_end1 [cgi_get chaseget_standby_end1 ""]
set val 1
if {$mute ne "yes"} { set val 0 }
[settings new] _nval_setting "chaseget_mute" $val
set val 1
if {$status ne "yes"} { set val 0 }
[settings new] _nval_setting "chaseget_status" $val
[settings new] _tval_setting "chaseget_standby_start1" $standby_start1
[settings new] _tval_setting "chaseget_standby_end1" $standby_end1
puts "Settings saved."

View File

@ -0,0 +1,113 @@
# Chasget settins - mymsman 151008
#source /mod/webif/lib/setup
#require settings.class
#set settings [settings]
set ::chaseget::status [$settings _nval_setting "chaseget_status"]
set ::chaseget::mute [$settings _nval_setting "chaseget_mute"]
set ::chaseget::standby_start1 [$settings _tval_setting "chaseget_standby_start1"]
set ::chaseget::standby_end1 [$settings _tval_setting "chaseget_standby_end1"]
puts "
<fieldset style=\"display: inline\">
<legend>
<a href=\"http://wiki.hummy.tv/wiki/DetectAds#ChaseGet_settings\" target=\"_blank\">ChaseGet (Get file whilst recording) settings</a>
</legend>
<p>See <b><a href=\"http://wiki.hummy.tv/wiki/DetectAds#ChaseGet_settings\" target=\"_blank\">DetectAds user guide</a></b> for help</p>
<form class=auto id=chaseget method=get
action=/plugin/chaseget/save.jim>
<table>"
puts "
<tr>
<th class=key>Hide ChaseGet on status display?
</th>
<td><input id=chaseget_status name=chaseget_status
type=checkbox value=yes"
if {$::chaseget::status} { puts -nonewline " checked" }
puts ">
</td>
</tr>"
puts "
<tr>
<th class=key>Mute sound on ChaseGet wake from standby?
</th>
<td><input id=chaseget_mute name=chaseget_mute
type=checkbox value=yes"
if {$::chaseget::mute} { puts -nonewline " checked" }
puts ">
</td>
</tr>"
proc timelist {sel} {
for {set t 0} {$t <=1440} {incr t 30} {
# (mis)use the the fact of 60 sec per min 60 min per hour to format hh:mm, t is min per period
set ft [clock format $t -format %M:%S]
puts -nonewline "<option value=\"$ft\""
if {$sel eq $ft} {
puts -nonewline " selected=yes"
}
puts ">$ft</option>"
}
}
puts "
<tr id=chaseget_timerange >
<th class=key>Don't mute or return to standby between
</th>
<th class=key>
<select id=chaseget_standby_start1 name=chaseget_standby_start1
class=\"ui-widget-content ui-corner-all\" >"
timelist $::chaseget::standby_start1
puts " </select>
and
<select id=chaseget_standby_end1 name=chaseget_standby_end1
class=\"ui-widget-content ui-corner-all\" >"
timelist $::chaseget::standby_end1
puts " </select>
</th>
</tr>"
puts "
<tr>
<td colspan=2><input type=submit value=\"Update settings\">
<div id=chaseget_output></div>
</td>
</tr>
</table>
</form>
</fieldset>
"
#puts "<datalist id=timelist>"
#for {set t 0} {$t <=1440} {incr t 30} {
# # (mis)use the the fact of 60 sec per min 60 min per hour to format hh:mm, t is min per period
# puts "<option value=\"[clock format $t -format %M:%S]\">"
#}
#puts "</datalist>"
#set pattern {([01]?[0-9]|2[0-4]):[0-5][0-9]}
#puts "
# <tr id=chaseget_timerange >
# <th class=key>Don't return to standby between
# </th>
# <th class=key>
# <input id=chaseget_standby_start1 name=chaseget_standby_start1
# type=text size=5 list=timelist value=\"$::chaseget::standby_start1\"
# class=\"ui-widget-content ui-corner-all\"
# pattern=$pattern title=\"hh:mm time\">
#
# and
# <input id=chaseget_standby_end1 name=chaseget_standby_end1
# type=text size=5 list=timelist value=\"$::chaseget::standby_end1\"
# class=\"ui-widget-content ui-corner-all\"
# pattern=$pattern title=\"hh:mm time\">
# </th>
# </tr>"
#puts "
# <tr>
# <td colspan=2><input type=submit value=\"Update settings\">
# <div id=chaseget_output></div>
# </td>
# </tr>
# </table>
# </form>
# </fieldset>
# "

View File

@ -0,0 +1,6 @@
register_statusop chaseget "Chaseget decrypting" "/plugin/chaseget/running.png"
# Icon by Ivan Boyko https://www.iconfinder.com/icons/310307/running_sport_icon
# Creative Commons (Attribution 3.0 Unported) https://creativecommons.org/licenses/by/3.0/