This commit is contained in:
hummypkg 2013-07-12 22:43:15 +00:00
parent 3bbc25eccd
commit 5e700d72ed
4 changed files with 206 additions and 0 deletions

8
CONTROL/control Normal file
View File

@ -0,0 +1,8 @@
Package: sweeper
Priority: optional
Section: misc
Version: 1.0.0
Architecture: mipsel
Maintainer: af123@hummypkg.org.uk
Depends: webif(>=1.0.3-3)
Description: Automatically manage single recording files.

7
ignore:sync Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
for f in webif/plugin/sweeper/; do
rsync -avr humax:/mod/$f ./$f
done

View File

@ -0,0 +1,157 @@
set ::sweeper::cf "/mod/etc/sweeper.conf"
proc ::sweeper::unknown {cmd args} {
log "Unknown sweeper rule clause '$cmd'" 0
return 0
}
proc ::sweeper::intcomp {ref val} {
lassign $val op num
if {$num eq ""} {
set num $op
set op "=="
}
return [expr $ref $op $num]
}
proc ::sweeper::strcontains {ref val} {
return [expr \
[string first [string tolower $val] [string tolower $ref]] \
>= 0]
}
######################################################################
# Rule clauses
proc ::sweeper::flag {ts flag} {
return [$ts flag $flag]
}
proc ::sweeper::channum {ts num} {
return [::sweeper::intcomp [$ts get channel_num] $num]
}
proc ::sweeper::duration {ts dur} {
return [::sweeper::intcomp [$ts duration] $dur]
}
proc ::sweeper::schedduration {ts dur} {
return [::sweeper::intcomp [$ts get scheddur] $dur]
}
proc ::sweeper::size {ts size} {
return [::sweeper::intcomp [$ts size] $size]
}
proc ::sweeper::definition {ts def} {
return [::sweeper::strcontains [$ts get definition] $def]
}
proc ::sweeper::title {ts str} {
return [::sweeper::strcontains [$ts get title] $str]
}
proc ::sweeper::synopsis {ts str} {
return [::sweeper::strcontains [$ts get synopsis] $str]
}
proc ::sweeper::guidance {ts str} {
return [::sweeper::strcontains [$ts get guidance] $str]
}
proc ::sweeper::genre {ts genre} {
set glist [ts genrelist]
set tsg [$ts get genre]
if {![dict exists $glist $tsg]} { return 0 }
if {[lindex $glist($tsg) 0] eq $genre} { return 1 }
return 0
}
######################################################################
proc ::sweeper::action {ts cmd} {
global root
set rest [lassign $cmd cmd]
log "ACTION: $cmd\($rest)" 2
case $cmd {
preserve { return 1 }
move {
if {[file isdirectory "$root/$rest"]} {
log "Moving [$ts get file] to $rest" 0
foreach f [$ts fileset] {
log " ....... $f"
#file rename $f "$root/$rest/[file tail $f]"
}
return 1
}
}
}
return 0
}
proc ::sweeper::runrule {ts rule} {
log "Processing \[$rule]" 2
while {[llength $rule] > 1} {
set rule [lassign $rule cmd arg]
log " $cmd\($arg)" 2
set ret [::sweeper::$cmd $ts $arg]
if {$cmd eq "action"} { return $ret }
if {!$ret} {
log " Nomatch" 2
break
}
log " MATCH" 2
}
return 0
}
proc ::sweeper::scan {args} {
global root
if {[catch {set fp [open $::sweeper::cf r]} msg]} {
log "Error opening sweeper config, $msg" 0
return
}
set rules [split [read $fp] "\n"]
$fp close
log "Sweep scan starting" 2
foreach e [readdir -nocomplain $root] {
set entry "$root/$e"
if {[file isdirectory $entry]} continue
if {![string match {*.ts} $entry]} continue
log "+ Sweeper processing $entry" 2
if {[catch {set ts [ts fetch $entry]} msg} {
log "Error reading TS file, $msg" 0
continue
}
if {$ts == "0"} {
log "Invalid TS file." 0
continue
}
foreach rule $rules {
if {[::sweeper::runrule $ts $rule]} break
}
}
}
if {[file exists $::sweeper::cf]} {
register postdecryptscan ::sweeper::scan
}

34
webif/plugin/sweeper/test Executable file
View File

@ -0,0 +1,34 @@
#!/mod/bin/jimsh
source /mod/webif/lib/setup
require lock system.class ts.class tdelete pretty_size browse.class \
safe_delete settings.class plugin
proc log {msg {level 1}} {
puts "[\
clock format [clock seconds] -format "%d/%m/%Y %H:%M"\
] - $msg"
}
proc elapsed {start} {
return $(([clock milliseconds] - $start) / 1000.0)
}
proc startclock {} {
set ::startclock_s [clock milliseconds]
}
proc endclock {size} {
set el [elapsed $::startclock_s]
set rate $($size / $el)
return "[pretty_size $size] in $el seconds - [pretty_size $rate]/s"
}
proc register {args} {}
source auto.hook
set root [system mediaroot]
::sweeper::scan 0