add variables,example dedup rules
This commit is contained in:
parent
2a15e1b6d6
commit
54165e57aa
|
@ -1,9 +1,9 @@
|
||||||
Package: sweeper
|
Package: sweeper
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Section: misc
|
Section: misc
|
||||||
Version: 2.0.14
|
Version: 2.0.15
|
||||||
Architecture: mipsel
|
Architecture: mipsel
|
||||||
Maintainer: af123@hummypkg.org.uk
|
Maintainer: af123@hummypkg.org.uk
|
||||||
Depends: webif(>=1.2.5)
|
Depends: webif(>=1.2.5-10)
|
||||||
Description: Sweeper is a package for managing recordings in a variety of ways using custom rules [See forum for details]
|
Description: Sweeper is a package for managing recordings in a variety of ways using custom rules [See forum for details]
|
||||||
Tags: http://hummy.tv/forum/threads/5138/
|
Tags: http://hummy.tv/forum/threads/5138/
|
||||||
|
|
|
@ -39,6 +39,7 @@ set ::sweeper::expand_fns {
|
||||||
regsub {2}
|
regsub {2}
|
||||||
asfilename {1 {inline}}
|
asfilename {1 {inline}}
|
||||||
format {2 {inline}}
|
format {2 {inline}}
|
||||||
|
var {1 {inline}}
|
||||||
}
|
}
|
||||||
|
|
||||||
proc ::sweeper::expand_replace {ts &ret search replace} {
|
proc ::sweeper::expand_replace {ts &ret search replace} {
|
||||||
|
@ -65,6 +66,14 @@ proc ::sweeper::expand_format {ts &ret format arg} {
|
||||||
return $r
|
return $r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::expand_var {ts &ret arg} {
|
||||||
|
if {![dict exists $::sweeper::stack $arg]} {
|
||||||
|
log "Error. Variable does not exist."
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return $::sweeper::stack($arg)
|
||||||
|
}
|
||||||
|
|
||||||
# Expand a string containing tokens
|
# Expand a string containing tokens
|
||||||
proc ::sweeper::expand {ts str {orig ""}} {
|
proc ::sweeper::expand {ts str {orig ""}} {
|
||||||
if {[string first "%" $str] == -1} {
|
if {[string first "%" $str] == -1} {
|
||||||
|
@ -193,7 +202,14 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||||
"%emm" $emm \
|
"%emm" $emm \
|
||||||
]
|
]
|
||||||
|
|
||||||
# log $map 2
|
#log "STACK: $::sweeper::stack" 2
|
||||||
|
|
||||||
|
foreach {key val} $::sweeper::stack {
|
||||||
|
#log "MAP(%%$key) -> $val" 2
|
||||||
|
set map(%%$key) $val
|
||||||
|
}
|
||||||
|
|
||||||
|
#log $map 2
|
||||||
|
|
||||||
set ret [string map $map $ret]
|
set ret [string map $map $ret]
|
||||||
log " Expanded \[$str] -> \[$ret]" 2
|
log " Expanded \[$str] -> \[$ret]" 2
|
||||||
|
@ -512,13 +528,18 @@ proc ::sweeper::series {ts flag folder} {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::varset {ts var folder} {
|
||||||
|
return [dict exists $::sweeper::stack $var]
|
||||||
|
}
|
||||||
|
|
||||||
proc ::sweeper::textmatch {ts str folder} {
|
proc ::sweeper::textmatch {ts str folder} {
|
||||||
if {![regexp -- {^([^~]+)~~(.*)$} $str x target pattern]} {
|
if {![regexp -- {^([^~]+)~~(.*)$} $str x target pattern]} {
|
||||||
log "No pattern in textmatch." 1
|
log "No pattern in textmatch." 1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
log "Textmatch ($target) against ($pattern)" 2
|
log "Textmatch ($target) against ($pattern)" 2
|
||||||
return [::sweeper::strcontains [::sweeper::expand $ts $target] $pattern]
|
return [::sweeper::strcontains [::sweeper::expand $ts $target] \
|
||||||
|
[::sweeper::expand $ts $pattern]]
|
||||||
}
|
}
|
||||||
|
|
||||||
proc ::sweeper::intmatch {ts str folder} {
|
proc ::sweeper::intmatch {ts str folder} {
|
||||||
|
@ -779,10 +800,24 @@ proc ::sweeper::action_log {ts cmd arg folder} {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::action_set {ts cmd arg folder} {
|
||||||
|
set val [join [lassign [split $arg =] var] "="]
|
||||||
|
set val [::sweeper::expand $ts $val]
|
||||||
|
log "Set '$var'='$val'"
|
||||||
|
if {![string length $val]} {
|
||||||
|
unset -nocomplain $::sweeper::stack($var)
|
||||||
|
} else {
|
||||||
|
set ::sweeper::stack($var) $val
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
proc ::sweeper::action_flag {ts cmd arg folder} {
|
proc ::sweeper::action_flag {ts cmd arg folder} {
|
||||||
log "Flagged [$ts get file] as $arg" 0
|
log "Flagged [$ts get file] as $arg" 0
|
||||||
if {!$::sweeper::dryrun} {
|
if {!$::sweeper::dryrun} {
|
||||||
$ts setflag $arg
|
$ts setflag $arg
|
||||||
|
} else {
|
||||||
|
$ts setflag $arg 1
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -791,6 +826,8 @@ proc ::sweeper::action_unflag {ts cmd arg folder} {
|
||||||
log "Unflagged [$ts get file] as $arg" 0
|
log "Unflagged [$ts get file] as $arg" 0
|
||||||
if {!$::sweeper::dryrun} {
|
if {!$::sweeper::dryrun} {
|
||||||
$ts unsetflag $arg
|
$ts unsetflag $arg
|
||||||
|
} else {
|
||||||
|
$ts unsetflag $arg 1
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -934,6 +971,7 @@ proc ::sweeper::apply {dir cf} {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set ::sweeper::stack {}
|
||||||
foreach rule $rules {
|
foreach rule $rules {
|
||||||
if {[string index $rule 0] eq "#" ||
|
if {[string index $rule 0] eq "#" ||
|
||||||
[llength $rule] < 2} continue
|
[llength $rule] < 2} continue
|
||||||
|
@ -998,6 +1036,7 @@ proc ::sweeper::apply {dir cf} {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set ::sweeper::stack {}
|
||||||
foreach rule $rules {
|
foreach rule $rules {
|
||||||
if {[string index $rule 0] eq "#" ||
|
if {[string index $rule 0] eq "#" ||
|
||||||
[llength $rule] < 3} continue
|
[llength $rule] < 3} continue
|
||||||
|
|
|
@ -44,6 +44,155 @@ var macros = {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
dedup: {
|
||||||
|
desc: 'De-duplicate/tidy',
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
"raw": "!flag Deduped intmatch {%episode~~> 0} action {set {newname=s%format:%02d:%series:e%format:%02d:%episode: - %epname}}",
|
||||||
|
"name": "For a new recording with detected episode number, create a new title and store it in the 'newname' variable",
|
||||||
|
"type": "file",
|
||||||
|
"enabled": "1",
|
||||||
|
"criteria": [
|
||||||
|
{
|
||||||
|
"negate": 1,
|
||||||
|
"cmd": "flag",
|
||||||
|
"arg": "Deduped"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"negate": 0,
|
||||||
|
"cmd": "intmatch",
|
||||||
|
"arg": "%episode~~> 0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": {
|
||||||
|
"cmd": "set",
|
||||||
|
"arg": "newname=s%format:%02d:%series:e%format:%02d:%episode: - %epname"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "lastrule "" action {set newfile=%asfilename/%%newname/}",
|
||||||
|
"name": "Set the new filename too",
|
||||||
|
"type": "file",
|
||||||
|
"enabled": "1",
|
||||||
|
"criteria": [
|
||||||
|
{
|
||||||
|
"negate": 0,
|
||||||
|
"cmd": "lastrule",
|
||||||
|
"arg": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": {
|
||||||
|
"cmd": "set",
|
||||||
|
"arg": "newfile=%asfilename/%%newname/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "lastrule "" textmatch %basename~~%%newfile action {flag dedup}",
|
||||||
|
"name": "If this recording already has this name, then flag as already de-duped.",
|
||||||
|
"type": "file",
|
||||||
|
"enabled": "1",
|
||||||
|
"criteria": [
|
||||||
|
{
|
||||||
|
"negate": 0,
|
||||||
|
"cmd": "lastrule",
|
||||||
|
"arg": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"negate": 0,
|
||||||
|
"cmd": "textmatch",
|
||||||
|
"arg": "%basename~~%%newfile"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": {
|
||||||
|
"cmd": "flag",
|
||||||
|
"arg": "dedup"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "!flag Deduped varset newfile fileexists %%newfile.ts action delete",
|
||||||
|
"name": "If still not de-duped and another file with the new name already exists, then delete this one.",
|
||||||
|
"type": "file",
|
||||||
|
"enabled": "1",
|
||||||
|
"criteria": [
|
||||||
|
{
|
||||||
|
"negate": 1,
|
||||||
|
"cmd": "flag",
|
||||||
|
"arg": "Deduped"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"negate": 0,
|
||||||
|
"cmd": "varset",
|
||||||
|
"arg": "newfile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"negate": 0,
|
||||||
|
"cmd": "fileexists",
|
||||||
|
"arg": "%%newfile.ts"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": {
|
||||||
|
"cmd": "delete",
|
||||||
|
"arg": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "!flag Deduped varset newname action {settitle %%newname}",
|
||||||
|
"name": "Otherwise set the recording title.",
|
||||||
|
"type": "file",
|
||||||
|
"enabled": "1",
|
||||||
|
"criteria": [
|
||||||
|
{
|
||||||
|
"negate": 1,
|
||||||
|
"cmd": "flag",
|
||||||
|
"arg": "Deduped"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"negate": 0,
|
||||||
|
"cmd": "varset",
|
||||||
|
"arg": "newname"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": {
|
||||||
|
"cmd": "settitle",
|
||||||
|
"arg": "%%newname"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "lastrule "" action {renamefile %%newname}",
|
||||||
|
"name": "and recording filename.",
|
||||||
|
"type": "file",
|
||||||
|
"enabled": "1",
|
||||||
|
"criteria": [
|
||||||
|
{
|
||||||
|
"negate": 0,
|
||||||
|
"cmd": "lastrule",
|
||||||
|
"arg": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": {
|
||||||
|
"cmd": "renamefile",
|
||||||
|
"arg": "%%newname"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "lastrule "" action {flag dedup}",
|
||||||
|
"name": "Finally, flag recording as de-duped.",
|
||||||
|
"type": "file",
|
||||||
|
"enabled": "1",
|
||||||
|
"criteria": [
|
||||||
|
{
|
||||||
|
"negate": 0,
|
||||||
|
"cmd": "lastrule",
|
||||||
|
"arg": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": {
|
||||||
|
"cmd": "flag",
|
||||||
|
"arg": "dedup"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
example: {
|
example: {
|
||||||
desc: 'Example rules',
|
desc: 'Example rules',
|
||||||
rules: [
|
rules: [
|
||||||
|
|
|
@ -216,6 +216,14 @@ var schema = {
|
||||||
negate: true,
|
negate: true,
|
||||||
def: "0"
|
def: "0"
|
||||||
},
|
},
|
||||||
|
varset: {
|
||||||
|
'class': 'all',
|
||||||
|
type: 'string',
|
||||||
|
desc: 'Variable is set',
|
||||||
|
idesc: 'Variable is not set',
|
||||||
|
negate: true,
|
||||||
|
def: ""
|
||||||
|
},
|
||||||
'or': {
|
'or': {
|
||||||
'class': 'all',
|
'class': 'all',
|
||||||
type: 'composite',
|
type: 'composite',
|
||||||
|
@ -337,6 +345,12 @@ var schema = {
|
||||||
desc: 'Log...',
|
desc: 'Log...',
|
||||||
continues: true
|
continues: true
|
||||||
},
|
},
|
||||||
|
'set': {
|
||||||
|
'class': 'all',
|
||||||
|
argtype: 'string',
|
||||||
|
desc: 'Set variable...',
|
||||||
|
continues: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue