This commit is contained in:
hummypkg 2013-09-04 23:20:59 +00:00
parent ef6139671f
commit ad72f6ceb1
2 changed files with 188 additions and 2 deletions

View File

@ -1,7 +1,7 @@
Package: sweeper Package: sweeper
Priority: optional Priority: optional
Section: misc Section: misc
Version: 1.0.4 Version: 1.0.5
Architecture: mipsel Architecture: mipsel
Maintainer: af123@hummypkg.org.uk Maintainer: af123@hummypkg.org.uk
Depends: webif(>=1.0.5-3) Depends: webif(>=1.0.5-3)

View File

@ -68,6 +68,11 @@ proc ::sweeper::duration {ts dur} {
return [::sweeper::intcomp [$ts duration] $dur] return [::sweeper::intcomp [$ts duration] $dur]
} }
proc ::sweeper::hour {ts str} {
set hour [clock format [$ts get start] -format "%H"]
return [::sweeper::intcomp $hour $str]
}
proc ::sweeper::schedduration {ts dur} { proc ::sweeper::schedduration {ts dur} {
return [::sweeper::intcomp [$ts get scheddur] $dur] return [::sweeper::intcomp [$ts get scheddur] $dur]
} }
@ -102,6 +107,16 @@ proc ::sweeper::genre {ts genre} {
return 0 return 0
} }
proc ::sweeper::lock {ts g} {
if {$g} {
log "Locked recording." 0
$ts lock
} else {
log "Unlocked recording." 0
$ts unlock
}
}
###################################################################### ######################################################################
proc ::sweeper::action {ts cmds} { proc ::sweeper::action {ts cmds} {
@ -139,6 +154,97 @@ proc ::sweeper::action {ts cmds} {
} }
return 1 return 1
} }
default {
log "Unknown action '$cmd'" 0
}
}
return 0
}
proc ::sweeper::find {root target orig} {
set dustbin [system dustbin 1]
foreach e [readdir -nocomplain $root] {
regsub -all -- {//} "$root/$e" "/" entry
if {![file isdirectory $entry]} continue
if {[string match {\[*} $e]} continue
if {$e eq $dustbin} continue
if {$entry eq $orig} continue
if {$e eq $target} { return $entry }
set ret [::sweeper::find $entry $target $orig]
if {$ret ne ""} { return $ret }
}
return ""
}
proc ::sweeper:folder_merge {src dst} {
log "Moving recordings from $src to $dst" 0
foreach e [readdir -nocomplain $src] {
if {![string match {*.ts} $e]} continue
set entry "$src/$e"
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
}
if {[$ts inuse]} {
log "Recording in use." 2
continue
}
foreach f [$ts fileset] {
log " ....... $f"
file rename $f "$dst/[file tail $f]"
}
}
file delete "$src/.series"
if {[catch {file delete $src} msg]} {
log "Failed to remove directory: $msg" 0
}
if {$dst ni $::sweeper::recalc} {
lappend ::sweeper::recalc $dst
}
}
proc ::sweeper::folder_action {ts cmds} {
global root
lassign $cmds cmd rest
set folder [file dirname [$ts get file]]
set lfolder [file tail $folder]
log "FOLDER ACTION: $cmd\($rest) @\[$folder]" 2
switch $cmd {
preserve { return 1 }
fileundercreate -
fileunder {
if {![file isdirectory "$root/$rest"]} {
log " ... No such directory $root/$rest" 2
return 1
}
log " - searching for $lfolder under $root/$rest" 2
set target [::sweeper::find $root/$rest $lfolder $folder]
log " = $target" 2
if {$target eq "" || ![file isdirectory $target]} {
log "Did not find directory." 2
if {$cmd ne "fileundercreate"} { return 1 }
log "Creating..." 2
set target "$root/$rest/$lfolder"
system mkdir_p $target
}
::sweeper:folder_merge $folder $target
}
default {
log "Unknown action '$cmd'" 0
}
} }
return 0 return 0
} }
@ -148,10 +254,19 @@ proc ::sweeper::runrule {ts rule} {
if {[string index $rule 0] eq "#" || [llength $rule] < 2} { return 0 } if {[string index $rule 0] eq "#" || [llength $rule] < 2} { return 0 }
set folder 0
if {[lindex $rule 0] eq "folder"} {
set folder 1
set rule [lrange $rule 1 end]
}
while {[llength $rule] > 1} { while {[llength $rule] > 1} {
set rule [lassign $rule cmd arg] set rule [lassign $rule cmd arg]
log " $cmd\($arg)" 2 log " $cmd\($arg)" 2
set ret [::sweeper::$cmd $ts $arg] if {$folder && [exists -proc ::sweeper::folder_$cmd]} {
set ret [::sweeper::folder_$cmd $ts $arg]
} else {
set ret [::sweeper::$cmd $ts $arg]
}
if {$cmd eq "action"} { return $ret } if {$cmd eq "action"} { return $ret }
if {!$ret} { if {!$ret} {
log " Nomatch" 2 log " Nomatch" 2
@ -174,6 +289,11 @@ proc ::sweeper::apply {dir cf} {
set rules [split [read $fp] "\n"] set rules [split [read $fp] "\n"]
$fp close $fp close
set runfolder 0
foreach rule $rules {
if {[lindex $rule 0] eq "folder"} { incr runfolder }
}
log "Sweep scan starting for $dir" 2 log "Sweep scan starting for $dir" 2
foreach e [readdir -nocomplain $dir] { foreach e [readdir -nocomplain $dir] {
@ -199,10 +319,76 @@ proc ::sweeper::apply {dir cf} {
} }
foreach rule $rules { foreach rule $rules {
if {[lindex $rule 0] eq "folder"} continue
if {[string index $rule 0] eq "#" || \
[llength $rule] < 2} continue
if {[::sweeper::runrule $ts $rule]} break if {[::sweeper::runrule $ts $rule]} break
} }
} }
if {$runfolder > 0} {
log "" 2
log " -- FOLDER RULES --" 2
log "" 2
set dustbin [system dustbin 1]
foreach e [readdir -nocomplain $dir] {
set entry "$dir/$e"
if {![file isdirectory $entry]} continue
if {[string match {\[*} $e]} continue
if {$e eq $dustbin} continue
log "+ Sweeper processing folder $entry" 2
if {![file exists "$entry/.series"]} {
log "Not series folder." 2
continue
}
set ts 0
foreach de [readdir -nocomplain $entry] {
set dentry "$entry/$de"
if {[file isdirectory $dentry]} {
set ts 0
break
}
if {$ts ne "0"} continue
if {![string match {*.ts} $dentry]} continue
log " --- Considering $dentry" 2
if {[catch {set ts [ts fetch $dentry]} msg} {
log "Error reading TS file, $msg" 2
continue
}
if {$ts == "0"} {
log "Invalid TS file." 2
continue
}
if {[$ts inuse]} {
log "Recording in use." 2
set ts 0
continue
}
break
}
if {$ts == "0"} {
log "No usable recordings in folder." 2
continue
}
foreach rule $rules {
if {[string index $rule 0] eq "#" || \
[llength $rule] < 2} continue
if {[lindex $rule 0] ne "folder"} continue
if {[::sweeper::runrule $ts $rule]} break
}
}
}
foreach dir $::sweeper::recalc { foreach dir $::sweeper::recalc {
ts resetnew "$::root/$dir" ts resetnew "$::root/$dir"
} }