adding flag/unflag/fileexists/%asfilename...
This commit is contained in:
parent
6ae2d773d5
commit
f717c85921
@ -1,7 +1,7 @@
|
||||
Package: sweeper
|
||||
Priority: optional
|
||||
Section: misc
|
||||
Version: 2.0.10
|
||||
Version: 2.0.11
|
||||
Architecture: mipsel
|
||||
Maintainer: af123@hummypkg.org.uk
|
||||
Depends: webif(>=1.2.4-3)
|
||||
|
@ -2,6 +2,7 @@
|
||||
set ::sweeper::cf "/mod/etc/sweeper.conf"
|
||||
set ::sweeper::dryrun 0
|
||||
set ::sweeper::lastruleresult 0
|
||||
set ::sweeper::stack {}
|
||||
|
||||
proc ::sweeper::unknown {cmd args} {
|
||||
log "Unknown sweeper rule clause '$cmd'" 0
|
||||
@ -36,6 +37,7 @@ proc ::sweeper::strcontains {ref val} {
|
||||
set ::sweeper::expand_fns {
|
||||
replace {2}
|
||||
regsub {2}
|
||||
asfilename {1 {inline}}
|
||||
}
|
||||
|
||||
proc ::sweeper::expand_replace {ts &ret search replace} {
|
||||
@ -50,6 +52,12 @@ proc ::sweeper::expand_regsub {ts &ret search replace} {
|
||||
}
|
||||
}
|
||||
|
||||
proc ::sweeper::expand_asfilename {ts &ret arg} {
|
||||
return [system filename $arg]
|
||||
}
|
||||
|
||||
set ::sweeper::brmap "( ) \[ ] \\{ \\}"
|
||||
|
||||
# Expand a string containing tokens
|
||||
proc ::sweeper::expand {ts str {orig ""}} {
|
||||
if {[string first "%" $str] == -1} {
|
||||
@ -88,6 +96,10 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||
"%channel" [$ts get channel_name] \
|
||||
"%duration" [$ts duration] \
|
||||
\
|
||||
"%filename" [$ts get file] \
|
||||
"%basename" [$ts bfile] \
|
||||
"%folder" [$ts dir] \
|
||||
\
|
||||
%epname [$ts episode_name] \
|
||||
%series [$ts get seriesnum] \
|
||||
%episodes [$ts get episodetot] \
|
||||
@ -125,7 +137,7 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||
foreach {fn params} $::sweeper::expand_fns {
|
||||
# log " Looking for %$fn" 2
|
||||
|
||||
lassign $params numargs
|
||||
lassign $params numargs flags
|
||||
|
||||
set li -1
|
||||
while {[set i [string first "%$fn" $ret]] >= 0} {
|
||||
@ -136,7 +148,7 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||
set chpos $($i + [string length $fn] + 1)
|
||||
set ch [string index $ret $chpos]
|
||||
|
||||
log " - found at $i (delim\[$ch])" 2
|
||||
# log " - found at $i (delim\[$ch])" 2
|
||||
|
||||
# Extract the arguments
|
||||
set pos $chpos
|
||||
@ -144,6 +156,11 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||
while {[llength $fnargs] < $numargs} {
|
||||
incr pos
|
||||
set e [string first $ch $ret $pos]
|
||||
if {$e == -1 && [ \
|
||||
dict exists $::sweeper::brmap $ch]} {
|
||||
set bch $::sweeper::brmap($ch)
|
||||
set e [string first $bch $ret $pos]
|
||||
}
|
||||
if {$e == -1} {
|
||||
log "Error. %$fn - [llength $fnargs]/$numargs parameters found."
|
||||
break
|
||||
@ -153,11 +170,24 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||
set pos $e
|
||||
}
|
||||
|
||||
set ret [string replace $ret $i $pos]
|
||||
# log "FNARGS: ($fnargs)" 2
|
||||
|
||||
if {[llength $fnargs] == $numargs} {
|
||||
log " - Calling expand_$fn\($fnargs)" 2
|
||||
::sweeper::expand_$fn $ts ret {*}$fnargs
|
||||
set fnret [
|
||||
::sweeper::expand_$fn $ts ret {*}$fnargs]
|
||||
log " - Result: ($ret) ($fnret)" 2
|
||||
}
|
||||
|
||||
if {"inline" in $flags} {
|
||||
set nret [string range $ret 0 $($i - 1)]
|
||||
append nret $fnret
|
||||
append nret [string range $ret $($pos + 1) end]
|
||||
set ret $nret
|
||||
} else {
|
||||
set ret [string replace $ret $($i - 1) $pos]
|
||||
}
|
||||
log " FN expanded \[$str] -> \[$ret]" 2
|
||||
}
|
||||
}
|
||||
|
||||
@ -428,6 +458,26 @@ proc ::sweeper::foldername {ts str folder} {
|
||||
return [::sweeper::strcontains [$ts dir] $str]
|
||||
}
|
||||
|
||||
proc ::sweeper::fileexists {ts str folder} {
|
||||
if {[string index $str 0] ne "/"} {
|
||||
set str "[$ts dir]/[::sweeper::expand $ts $str]"
|
||||
} else {
|
||||
set str [::sweeper::expand $ts $str]
|
||||
}
|
||||
log " FILEEXISTS($str)" 2
|
||||
return [file isfile $str]
|
||||
}
|
||||
|
||||
proc ::sweeper::direxists {ts str folder} {
|
||||
if {[string index $str 0] ne "/"} {
|
||||
set str "[$ts dir]/[::sweeper::expand $ts $str]"
|
||||
} else {
|
||||
set str [::sweeper::expand $ts $str]
|
||||
}
|
||||
log " DIREXISTS($str)" 2
|
||||
return [file isdirectory $str]
|
||||
}
|
||||
|
||||
proc ::sweeper::series {ts flag folder} {
|
||||
if {!$folder} { return 0 }
|
||||
set dir [$ts dir]
|
||||
@ -705,6 +755,22 @@ proc ::sweeper::action_delete {ts cmd arg folder} {
|
||||
return 1
|
||||
}
|
||||
|
||||
proc ::sweeper::action_flag {ts cmd arg folder} {
|
||||
log "Flagged [$ts get file] as $arg" 0
|
||||
if {!$::sweeper::dryrun} {
|
||||
$ts setflag $arg
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
proc ::sweeper::action_unflag {ts cmd arg folder} {
|
||||
log "Unflagged [$ts get file] as $arg" 0
|
||||
if {!$::sweeper::dryrun} {
|
||||
$ts unsetflag $arg
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
eval_plugins sweeper
|
||||
|
||||
######################################################################
|
||||
|
@ -186,6 +186,22 @@ var schema = {
|
||||
negate: true,
|
||||
def: ""
|
||||
},
|
||||
fileexists: {
|
||||
'class': 'all',
|
||||
type: 'string',
|
||||
desc: 'File exists',
|
||||
idesc: "File does not exist",
|
||||
negate: true,
|
||||
def: ""
|
||||
},
|
||||
direxists: {
|
||||
'class': 'all',
|
||||
type: 'string',
|
||||
desc: 'Directory exists',
|
||||
idesc: "Directory does not exist",
|
||||
negate: true,
|
||||
def: ""
|
||||
},
|
||||
textmatch: {
|
||||
'class': 'all',
|
||||
type: 'textmatch',
|
||||
@ -297,6 +313,18 @@ var schema = {
|
||||
desc: 'Unlock recordings',
|
||||
continues: true
|
||||
},
|
||||
flag: {
|
||||
'class': 'all',
|
||||
argtype: 'string',
|
||||
desc: 'Set recording flag...',
|
||||
continues: true
|
||||
},
|
||||
unflag: {
|
||||
'class': 'all',
|
||||
argtype: 'string',
|
||||
desc: 'Unset recording flag...',
|
||||
continues: true
|
||||
},
|
||||
'delete': {
|
||||
'class': 'all',
|
||||
argtype: 'none',
|
||||
|
Loading…
Reference in New Issue
Block a user