2013-07-12 22:43:15 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-07-13 19:57:31 +00:00
|
|
|
if {[$ts inuse]} {
|
|
|
|
log "Recording in use." 2
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2013-07-12 22:43:15 +00:00
|
|
|
foreach rule $rules {
|
|
|
|
if {[::sweeper::runrule $ts $rule]} break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[file exists $::sweeper::cf]} {
|
|
|
|
register postdecryptscan ::sweeper::scan
|
|
|
|
}
|
|
|
|
|