Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
Bob Buxton | 1e3dc9cae7 | |
Bob Buxton | f03adf60e6 | |
Bob Buxton | ce261f218a | |
Bob Buxton | c87de2da93 |
|
@ -1,10 +1,10 @@
|
|||
Package: detectads
|
||||
Priority: optional
|
||||
Section: misc
|
||||
Version: 0.3.0
|
||||
Version: 0.3.0-1
|
||||
Architecture: mipsel
|
||||
Maintainer: mymsman (Created by njm)
|
||||
Depends: webif(>=1.4.0), chaseget(>=0.1.2-1), nicesplice(>=1.7), ffmpeg, libsndfile (>=1.0.25-2), procps,stripts(>=1.4.5)
|
||||
Depends: webif(>=1.4.0), chaseget(>=0.1.3), nicesplice(>=1.7), ffmpeg, libsndfile (>=1.0.25-2), procps,stripts(>=1.4.5)
|
||||
Description: Automatically detects adverts
|
||||
and inserts bookmarks or deletes adverts. Can run whilst recording is still in progress
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
## nothing to do
|
||||
|
||||
## Set link
|
||||
ln -f /mod/webif/plugin/detectads/detectads /mod/bin/detectads
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/bin/sh
|
||||
# nothing to do
|
||||
# remove program links
|
||||
rm /mod/bin/detectads
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
# Override options must be specified on the first line of this file above
|
||||
Option Default (unless changed in Settings)
|
||||
-d n = produce detailed debug output
|
||||
-d 0 = produce detailed debug output (0, 1, 2)
|
||||
-t 0 = target start time hh:mm or linux time value
|
||||
-crop n = Crop ad breaks from recording y|n
|
||||
-bmEnd n = Only bookmark end of ad breaks y|n
|
||||
|
@ -22,4 +22,4 @@ Option Default (unless changed in Settings)
|
|||
-padSec 0 = Adjust ends of ad breaks by n seconds
|
||||
-makeThm n = Make thumbnail if it doesn't already exist
|
||||
-thmOffset 0 = Thumbnail offset from detected programme start
|
||||
-dirDecrypt n = Use software decryption
|
||||
-dirDecrypt n = Use software decryption (y on HD)
|
||||
|
|
|
@ -14,6 +14,7 @@ set file ""
|
|||
set debug 0
|
||||
set time 0
|
||||
set ts "No file"
|
||||
|
||||
set ::logfd stdout
|
||||
set ::loglevel 0
|
||||
|
||||
|
@ -25,18 +26,13 @@ if {[info exists ::auto::logfile]} {
|
|||
} else {
|
||||
set logfile "/mod/tmp/detectads.log"
|
||||
}
|
||||
|
||||
if {$debug} {
|
||||
set loglevel 2
|
||||
if {![info exists ::auto::logfd]} {
|
||||
set logfd stdout
|
||||
}
|
||||
puts "DEBUG ON"
|
||||
} else {
|
||||
# Use same logging option as auto log - mymsman 150515
|
||||
set settings [settings]
|
||||
set loglevel [$settings _nval_setting "autolog"]
|
||||
if {![info exists ::auto::logfd]} {
|
||||
if {$debug} {
|
||||
set logfd stdout
|
||||
puts "DEBUG ON level $::loglevel"
|
||||
} else {
|
||||
set logfd [open $logfile "a+"]
|
||||
}
|
||||
}
|
||||
|
||||
# process command
|
||||
|
@ -82,7 +78,7 @@ switch -- $opt {
|
|||
puts "detectads -rs recording = reset ad-detection flag and bookmarks"
|
||||
puts ""
|
||||
puts "Option Default (unless changed in Settings) "
|
||||
puts "-d n = produce detailed debug on Stdout "
|
||||
puts "-d 0 = produce detailed debug on Stdout (0, 1, 2) "
|
||||
puts "-t 0 = -aq only, target start time hh:mm or linux time value"
|
||||
puts "-force n = -aq only, don't check if DetectAds flag set"
|
||||
puts "-crop n = Crop ad breaks from recording y|n"
|
||||
|
@ -104,7 +100,7 @@ switch -- $opt {
|
|||
puts "-padSec 0 = Adjust ends of ad breaks by n seconds"
|
||||
puts "-makeThm n = Make thumbnail if it doesn't already exist"
|
||||
puts "-thmOffset 0 = Thumbnail offset from programme start"
|
||||
puts "-dirDecrypt n = Use software decryption"
|
||||
puts "-dirDecrypt n = Use software decryption (y on HD)"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,18 +12,19 @@ proc ::detectads::delete_entry_queue_db {ts} {
|
|||
return [{queue delete} $ts detectads]
|
||||
}
|
||||
|
||||
proc ::detectads::delete_orphans {} {
|
||||
if {![catch {exec /mod/bin/pgrep -x chaseget }]} {return}
|
||||
#delete ophans that haven't been modified in an hour or are for the current recording
|
||||
proc ::detectads::delete_orphans {file} {
|
||||
#if {![catch {exec /mod/bin/pgrep -x chaseget }]} {return}
|
||||
set bname [file rootname [file tail $file]]
|
||||
|
||||
set fl [glob -nocomplain "/mod/tmp/*-inp.ts" "/mod/tmp/*-dec.ts"]
|
||||
log "orphan file list $fl" 2
|
||||
foreach file $fl {
|
||||
if {![system inuse $file]} {
|
||||
set bname [file rootname $file]
|
||||
file delete -force $bname.hmt
|
||||
file delete -force $bname.nts
|
||||
file delete -force $bname.thm
|
||||
file delete -force $file
|
||||
log "Deleted orphan file $file"
|
||||
foreach f $fl {
|
||||
set fname [file tail [string range $f 0 end-7]]
|
||||
log "$bname $fname [clock format [file mtime $f]]" 2
|
||||
if {[file mtime $f]+3600 < [clock seconds]
|
||||
|| $bname == $fname} {
|
||||
safedel $f "/orphans"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +41,9 @@ proc ::detectads::checkopts {argv} {
|
|||
set settings [settings]
|
||||
|
||||
set ::autologlevel [$settings _nval_setting "autolog"]
|
||||
if {![info exists ::auto::logfd]} {
|
||||
set logfd ::auto::logfd
|
||||
set ::loglevel $::autologlevel
|
||||
if {[info exists ::auto::logfd]} {
|
||||
set logfd ::auto::logfd
|
||||
}
|
||||
|
||||
# List of options with default values
|
||||
|
@ -69,6 +71,9 @@ proc ::detectads::checkopts {argv} {
|
|||
makethm 0
|
||||
thmoffset 0}
|
||||
|
||||
# dirDecrypt default on HD
|
||||
if {[system model] eq "HD"} {set ::opts(dirdecrypt) 1]}
|
||||
|
||||
# Override default from settings DB
|
||||
foreach {key defvalue} [array get optarray] {
|
||||
set ::opts($key) [$settings _nval_setting "detectads_$key"]
|
||||
|
@ -167,7 +172,6 @@ proc ::detectads::checkopts {argv} {
|
|||
}
|
||||
} else {
|
||||
log "Cannot process ($file) file does not exist" 0
|
||||
#puts "Cannot process ($file) file does not exist"
|
||||
set parmerror 1
|
||||
continue
|
||||
}
|
||||
|
@ -189,9 +193,12 @@ proc ::detectads::checkopts {argv} {
|
|||
}
|
||||
|
||||
if {$::opts(debug) || $::opts(d)} {
|
||||
set ll $::loglevel
|
||||
if {$::opts(debug) > $ll} {set ll $::opts(debug)}
|
||||
if {$::opts(d) > $ll} {set ll $::opts(d)}
|
||||
set ::debug 1
|
||||
set ::loglevel 2
|
||||
set ::auto::loglevel 2
|
||||
set ::loglevel $ll
|
||||
set ::auto::loglevel $ll
|
||||
}
|
||||
|
||||
if {$parmerror} {
|
||||
|
@ -270,7 +277,7 @@ proc ::detectads::chancheck {ts} {
|
|||
if {[$ts flag "ODEncrypted"]} {
|
||||
set cmd [list /mod/webif/plugin/detectads/detectads -pr "$file"]
|
||||
append cmd $opts
|
||||
exec {*}$cmd >@$::logfd &
|
||||
exec {*}$cmd >@$::logfd 2>@$::logfd &
|
||||
log " DETECTADS: Started $file for chaserun advert detection" 0
|
||||
} else {
|
||||
set queue_time [$settings _tval_setting "detectads_queue_time"]
|
||||
|
@ -524,6 +531,12 @@ proc ::detectads::run {ts} {
|
|||
|
||||
set base [file rootname $rfile]
|
||||
set shname [file tail $base]
|
||||
set cfile "$tgtpath/$shname-crop.ts"
|
||||
|
||||
# Check if old crop exists
|
||||
if {[file exists $cfile]} {
|
||||
safedel $cfile "/orphans" 0
|
||||
}
|
||||
|
||||
# Check if thumbnail exists
|
||||
if {[file exists "$bpath/$bname.thm"]} {
|
||||
|
@ -550,15 +563,12 @@ proc ::detectads::run {ts} {
|
|||
log " crop time taken: $croptime [clock format $(round($croptime)) -format %T]" 1
|
||||
|
||||
if {$delorig && ![system inuse $file]} { # Delete original file no longer wanted
|
||||
if {[safe_delete $file detectads]} {
|
||||
log "$file deleted" 0
|
||||
set cfile "$tgtpath/$shname-crop.ts"
|
||||
if {[safedel $file]} {
|
||||
if {![system inuse $cfile]} { # Rename crop file to original if not in use
|
||||
ts renamegroup "$cfile" "$shname"
|
||||
log "Renamed $cfile to $shname" 0
|
||||
}
|
||||
} else {
|
||||
log "$file safe_delete failed" 0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
set title [$ts get title]
|
||||
set newtitle [concat $title "-Crop"]
|
||||
|
@ -595,7 +605,7 @@ proc ::detectads::chaserun {ts {Qid 0} {retrynumb 0}} {
|
|||
set cropcmd " "
|
||||
|
||||
# Check for and delete any oprhaned files
|
||||
::detectads::delete_orphans
|
||||
::detectads::delete_orphans $file
|
||||
|
||||
if {![acquire_lock $file]} {
|
||||
log "Cannot acquire exclusive lock $file, terminating." 0
|
||||
|
@ -696,13 +706,13 @@ proc ::detectads::chaserun {ts {Qid 0} {retrynumb 0}} {
|
|||
log "starting" 2
|
||||
|
||||
# Create links to input in tmp for retrieval
|
||||
file delete -force "$ipath/$iname.ts"
|
||||
catch {file link -hard "$ipath/$iname.ts" "[file normalize [file rootname $file].ts]"}
|
||||
file delete -force "$ipath/$iname.nts"
|
||||
catch {file link -hard "$ipath/$iname.nts" "[file normalize [file rootname $file].nts]"}
|
||||
file delete -force "$ipath/$iname.hmt"
|
||||
catch {file link -hard "$ipath/$iname.hmt" "[file normalize [file rootname $file].hmt]"}
|
||||
set its [ts fetch $ifile]
|
||||
# file delete -force "$ipath/$iname.ts"
|
||||
# catch {file link -hard "$ipath/$iname.ts" "[file normalize [file rootname $file].ts]"}
|
||||
# file delete -force "$ipath/$iname.nts"
|
||||
# catch {file link -hard "$ipath/$iname.nts" "[file normalize [file rootname $file].nts]"}
|
||||
# file delete -force "$ipath/$iname.hmt"
|
||||
# catch {file link -hard "$ipath/$iname.hmt" "[file normalize [file rootname $file].hmt]"}
|
||||
# set its [ts fetch $ifile]
|
||||
|
||||
|
||||
# Use link for .nts so updates are visble
|
||||
|
@ -721,6 +731,10 @@ proc ::detectads::chaserun {ts {Qid 0} {retrynumb 0}} {
|
|||
set_HMT_durn "$tpath/$tname" $stime 0
|
||||
|
||||
set ftime [clock format $stime -format "%Y%m%d%H%M.%S"]
|
||||
# Check if old temp file exists
|
||||
if {[file exists $tfile]} {
|
||||
safedel $tfile "/orphans" 0
|
||||
}
|
||||
exec touch $tfile -t $ftime
|
||||
set tts [ts fetch $tfile]
|
||||
set tfilesize 0 ;# Silence/nsplice cant handle restart midway so force total file retrieval
|
||||
|
@ -730,6 +744,10 @@ proc ::detectads::chaserun {ts {Qid 0} {retrynumb 0}} {
|
|||
# title will be copied to output by nicesplice so we can change again after opening pipe
|
||||
set newtitle [concat $title "-Crop"]
|
||||
exec hmt "+settitle=${newtitle}" "$tpath/$tname.hmt"
|
||||
# Check if old crop exists
|
||||
if {[file exists $cfile]} {
|
||||
safedel $cfile "/orphans" 0
|
||||
}
|
||||
#exec touch "$cpath/$cname.ts" -t $ftime
|
||||
set cropInput [open "|\
|
||||
/mod/webif/plugin/detectads/nsplice -in {$tpath/$tname} -out {$cpath/$cname} -stdin |\
|
||||
|
@ -746,10 +764,10 @@ proc ::detectads::chaserun {ts {Qid 0} {retrynumb 0}} {
|
|||
|
||||
if {!$dirdecrypt} {
|
||||
# Use chaseget for decryption
|
||||
set decrypt "/mod/bin/chaseget {$ifile} $tfilesize"
|
||||
set decrypt "/mod/bin/chaseget {$file} $tfilesize"
|
||||
} else {
|
||||
# Use stripts for decryption
|
||||
set decrypt "/mod/bin/stripts -@@ -d -d {$ipath/$iname} - 2>@$::logfd"
|
||||
set decrypt "/mod/bin/stripts -@@ {$file} - 2>@$::logfd"
|
||||
}
|
||||
|
||||
set adDetectOutput [open "|\
|
||||
|
@ -928,7 +946,7 @@ proc ::detectads::chaserun {ts {Qid 0} {retrynumb 0}} {
|
|||
$tts setbookmarks $bookmarks
|
||||
|
||||
# Delete links to input from /mod/tmp
|
||||
$its delete
|
||||
#its delete
|
||||
|
||||
# Check that complete file has been retrieved & detected
|
||||
set ts [ts fetch $file]
|
||||
|
@ -991,48 +1009,40 @@ proc ::detectads::chaserun {ts {Qid 0} {retrynumb 0}} {
|
|||
close $recording
|
||||
|
||||
if {$delorig && ![system inuse $file]} { # Delete original file no longer wanted
|
||||
if {[safe_delete $file detectads]} {
|
||||
log "$file deleted" 0
|
||||
if {[safedel $file]} {
|
||||
|
||||
if {$crop} {
|
||||
if {![system inuse $cfile]} { # Rename crop file to original if not in use
|
||||
exec hmt "+settitle=$title" "$cpath/$cname.hmt"
|
||||
ts renamegroup "$cfile" "$bname"
|
||||
log "Renamed $cfile to $bname" 0
|
||||
}
|
||||
if {![system inuse $tfile]} { # Delete decrypt file no longer needed
|
||||
$tts delete
|
||||
log "$tfile deleted" 0
|
||||
}
|
||||
safedel $tfile "/decrypt"
|
||||
} else {
|
||||
if {![system inuse $tfile]} { # Rename decrypt file to original if not in use
|
||||
exec hmt "+settitle=$title" "$tpath/$tname.hmt"
|
||||
if {$tpath ne $tgtpath} { # Move to correct directory
|
||||
$tts move $tgtpath
|
||||
log "Moved $tfile to $tgtpath" 0
|
||||
}
|
||||
ts renamegroup "$tgtpath/$tname.ts" "$bname"
|
||||
log "Renamed $tgtpath/$tname.ts to $bname" 0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log "$file safe_delete failed" 0
|
||||
}
|
||||
}
|
||||
} else { # Keeping original, dont rename
|
||||
if {$crop} {
|
||||
if {![system inuse $tfile]} { # Delete decrypt file no longer needed
|
||||
$tts delete
|
||||
log "$tfile deleted" 0
|
||||
}
|
||||
safedel $tfile "/decrypt"
|
||||
} else {
|
||||
if {$tpath ne $tgtpath} { # Move decrypt to correct directory
|
||||
$tts move $tgtpath
|
||||
log "Moved $tfile to $tgtpath" 0
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# Somethings amiss with file length, keep original and -crop, delete -dec
|
||||
if {![system inuse $tfile]} { # Delete decrypt file no longer needed
|
||||
$tts delete
|
||||
log "$tfile deleted" 0
|
||||
}
|
||||
safedel $tfile "/decrypt"
|
||||
exec hmt $dadflag "$bpath/$bname.hmt"
|
||||
if {$crop} {
|
||||
exec hmt "+settitle=$newtitle" "$cpath/$cname.hmt"
|
||||
|
@ -1058,6 +1068,26 @@ proc ::detectads::chaserun {ts {Qid 0} {retrynumb 0}} {
|
|||
return [list $retcode $retmsg $qtime]
|
||||
}
|
||||
|
||||
# move file to dustbin if not is use (wait up to 5 seconds)
|
||||
proc safedel {file {suffx ""} {wait 1} } {
|
||||
set ct 0
|
||||
while {$wait && [system inuse $file]} {
|
||||
incr ct
|
||||
if {$ct <5} {
|
||||
log "Not deleted $file - inuse" 0
|
||||
return 0
|
||||
}
|
||||
sleep 1
|
||||
}
|
||||
if {[safe_delete $file detectads$suffx]} {
|
||||
log "$file safe deleted" 0
|
||||
return 1
|
||||
} else {
|
||||
log "$file safe_delete failed" 0
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
proc set_HMT_durn {hmtfn start durn} {
|
||||
# Update recording end & stored recording time in hmt file
|
||||
exec hmt "+patch32=0x284:$($durn+$start)" "$hmtfn.hmt"
|
||||
|
|
Loading…
Reference in New Issue