add variables,example dedup rules

This commit is contained in:
hummypkg 2015-11-26 00:33:05 +00:00
parent 2a15e1b6d6
commit 54165e57aa
4 changed files with 206 additions and 4 deletions

View File

@ -1,9 +1,9 @@
Package: sweeper
Priority: optional
Section: misc
Version: 2.0.14
Version: 2.0.15
Architecture: mipsel
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]
Tags: http://hummy.tv/forum/threads/5138/

View File

@ -39,6 +39,7 @@ set ::sweeper::expand_fns {
regsub {2}
asfilename {1 {inline}}
format {2 {inline}}
var {1 {inline}}
}
proc ::sweeper::expand_replace {ts &ret search replace} {
@ -65,6 +66,14 @@ proc ::sweeper::expand_format {ts &ret format arg} {
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
proc ::sweeper::expand {ts str {orig ""}} {
if {[string first "%" $str] == -1} {
@ -193,7 +202,14 @@ proc ::sweeper::expand {ts str {orig ""}} {
"%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]
log " Expanded \[$str] -> \[$ret]" 2
@ -512,13 +528,18 @@ proc ::sweeper::series {ts flag folder} {
return 1
}
proc ::sweeper::varset {ts var folder} {
return [dict exists $::sweeper::stack $var]
}
proc ::sweeper::textmatch {ts str folder} {
if {![regexp -- {^([^~]+)~~(.*)$} $str x target pattern]} {
log "No pattern in textmatch." 1
return 0
}
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} {
@ -779,10 +800,24 @@ proc ::sweeper::action_log {ts cmd arg folder} {
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} {
log "Flagged [$ts get file] as $arg" 0
if {!$::sweeper::dryrun} {
$ts setflag $arg
} else {
$ts setflag $arg 1
}
return 0
}
@ -791,6 +826,8 @@ proc ::sweeper::action_unflag {ts cmd arg folder} {
log "Unflagged [$ts get file] as $arg" 0
if {!$::sweeper::dryrun} {
$ts unsetflag $arg
} else {
$ts unsetflag $arg 1
}
return 0
}
@ -934,6 +971,7 @@ proc ::sweeper::apply {dir cf} {
continue
}
set ::sweeper::stack {}
foreach rule $rules {
if {[string index $rule 0] eq "#" ||
[llength $rule] < 2} continue
@ -998,6 +1036,7 @@ proc ::sweeper::apply {dir cf} {
continue
}
set ::sweeper::stack {}
foreach rule $rules {
if {[string index $rule 0] eq "#" ||
[llength $rule] < 3} continue

View File

@ -44,6 +44,155 @@ var macros = {
}
]
},
dedup: {
desc: 'De-duplicate/tidy',
rules: [
{
"raw": "!flag Deduped intmatch {%episode~~&gt; 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~~&gt; 0"
}
],
"action": {
"cmd": "set",
"arg": "newname=s%format:%02d:%series:e%format:%02d:%episode: - %epname"
}
},
{
"raw": "lastrule &quot;&quot; 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 &quot;&quot; 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 &quot;&quot; action {renamefile %%newname}",
"name": "and recording filename.",
"type": "file",
"enabled": "1",
"criteria": [
{
"negate": 0,
"cmd": "lastrule",
"arg": ""
}
],
"action": {
"cmd": "renamefile",
"arg": "%%newname"
}
},
{
"raw": "lastrule &quot;&quot; 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: {
desc: 'Example rules',
rules: [

View File

@ -216,6 +216,14 @@ var schema = {
negate: true,
def: "0"
},
varset: {
'class': 'all',
type: 'string',
desc: 'Variable is set',
idesc: 'Variable is not set',
negate: true,
def: ""
},
'or': {
'class': 'all',
type: 'composite',
@ -337,6 +345,12 @@ var schema = {
desc: 'Log...',
continues: true
},
'set': {
'class': 'all',
argtype: 'string',
desc: 'Set variable...',
continues: true
}
}
};