diff --git a/CONTROL/control b/CONTROL/control index af9b8a9..73d9911 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,9 +1,9 @@ Package: sweeper Priority: optional Section: misc -Version: 2.0.9 +Version: 2.0.10 Architecture: mipsel Maintainer: af123@hummypkg.org.uk -Depends: webif(>=1.2.3-2) +Depends: webif(>=1.2.4-3) 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/ diff --git a/webif/plugin/sweeper/auto.hook b/webif/plugin/sweeper/auto.hook index 2a9e420..5c8062a 100644 --- a/webif/plugin/sweeper/auto.hook +++ b/webif/plugin/sweeper/auto.hook @@ -83,12 +83,16 @@ proc ::sweeper::expand {ts str {orig ""}} { "%title" [$ts get title] \ "%genre" $genre \ "%definition" [$ts get definition] \ + "%synopsis" [$ts get synopsis] \ "%lcn" [$ts get channel_num] \ "%channel" [$ts get channel_name] \ "%duration" [$ts duration] \ \ %epname [$ts episode_name] \ - %episode [$ts epstr] \ + %series [$ts get seriesnum] \ + %episodes [$ts get episodetot] \ + %episode [$ts get episodenum] \ + %epdescr [$ts epstr] \ \ "%timestamp" $timestamp \ "%yyyymmdd" $yyyymmdd \ @@ -113,13 +117,13 @@ proc ::sweeper::expand {ts str {orig ""}} { "%emm" $emm \ ] - log $map 2 +# log $map 2 set ret [string map $map $str] log " Expanded \[$str] -> \[$ret]" 2 foreach {fn params} $::sweeper::expand_fns { - log " Looking for %$fn" 2 +# log " Looking for %$fn" 2 lassign $params numargs @@ -445,6 +449,28 @@ proc ::sweeper::series {ts flag folder} { return 1 } +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] +} + +proc ::sweeper::intmatch {ts str folder} { + if {![regexp -- {^([^~]+)~~(.*)$} $str x target pattern]} { + log "No pattern in intmatch." 1 + return 0 + } + if {[llength [split $pattern " "]] != 2} { + log "Invalid pattern in numeric comparison." 0 + return 0 + } + log "Intmatch ($target) against ($pattern)" 2 + return [::sweeper::intcomp [::sweeper::expand $ts $target] $pattern] +} + ######################## # Deprecated conditions diff --git a/webif/plugin/sweeper/browse.hook b/webif/plugin/sweeper/browse.hook index cf63c35..8432f4b 100644 --- a/webif/plugin/sweeper/browse.hook +++ b/webif/plugin/sweeper/browse.hook @@ -5,3 +5,8 @@ lappend plugins(dmenu) {sweeper {desc "Sweeper Rules"}} lappend plugins(dmenu) {nosweep {desc "Toggle no-sweep flag"}} +lappend plugins(buttons) "sweeper { + desc {Sweeper Rules} + link {/plugin/sweeper/edit.jim?dir=[cgi_quote_url $dir]} +}" + diff --git a/webif/plugin/sweeper/edit.jim b/webif/plugin/sweeper/edit.jim index a3a44f6..de52ad6 100755 --- a/webif/plugin/sweeper/edit.jim +++ b/webif/plugin/sweeper/edit.jim @@ -161,6 +161,44 @@ For pattern matching, the following special sequences may appear in the pattern: + + + + diff --git a/webif/plugin/sweeper/schema.js b/webif/plugin/sweeper/schema.js index 66cbd0d..5996590 100644 --- a/webif/plugin/sweeper/schema.js +++ b/webif/plugin/sweeper/schema.js @@ -186,6 +186,20 @@ var schema = { negate: true, def: "" }, + textmatch: { + 'class': 'all', + type: 'textmatch', + desc: 'Text comparison', + negate: true, + def: 'Enter text here...' + }, + intmatch: { + 'class': 'all', + type: 'intmatch', + desc: 'Numeric comparison', + negate: true, + def: "0" + }, 'or': { 'class': 'all', type: 'composite', diff --git a/webif/plugin/sweeper/script.js b/webif/plugin/sweeper/script.js index 919df6e..198fd50 100644 --- a/webif/plugin/sweeper/script.js +++ b/webif/plugin/sweeper/script.js @@ -1,5 +1,6 @@ var mroot = '(Media Root)'; +var matchesp = ' ~matches~ '; function quot(str) { @@ -40,6 +41,7 @@ function changed(c) changed.last = c; } +// Setters convert from config file format to display var setters = { noarg: function(cmd, a) { return ''; @@ -66,9 +68,16 @@ var setters = { }, select: function(cmd, a) { return schema.criterion[cmd].select[a]; + }, + textmatch: function(cmd, a) { + return a.replace('~~', matchesp); + }, + intmatch: function(cmd, a) { + return a.replace('~~', matchesp); } }; +// Getters convert from display to config file format var getters = { noarg: function(cmd, a) { return ''; @@ -94,6 +103,12 @@ var getters = { if (c[key] == a) return key; return 'UNKNOWNKEY (' + a + ')'; + }, + textmatch: function(cmd, a) { + return a.replace(matchesp, '~~'); + }, + intmatch: function(cmd, a) { + return a.replace(matchesp, '~~'); } }; @@ -469,6 +484,89 @@ function edit_select(obj, title, options, val, callback) }); } +function edit_textmatch(obj, title, target, pattern, callback, typ) +{ + $('#edit_textmatch_target').val(target); + $('#edit_textmatch_pattern').val(pattern); + $('#edit_textmatch').dialog({ + title: title, + height: 'auto', width: 'auto', + draggable: true, resizable: false, + autoOpen: true, + position: { + my: 'bottom left', + at: 'top right', + of: obj, + collision: 'fit' + }, + buttons: { + "Save": function() { + var pattern = + $.trim($('#edit_textmatch_pattern').val()); + var target = + $.trim($('#edit_textmatch_target').val()); + if (!pattern) + alert("Bad pattern"); + else if (!target) + alert("Bad target"); + else + { + callback(obj, target, pattern); + $(this).dialog('close'); + } + }, + "Close": function() { + $(this).dialog('close'); + } + } + }); + $('.edit_textmatch_help').hide(); + if (typ) + $('#edit_textmatch_help_' + typ).show(); +// if (text == 'Enter text here...') +// $('#edit_text_field').focus().select(); +} + +function edit_intmatch(obj, title, target, op, val, callback) +{ + $('#edit_intmatch_target').val(target); + $('#edit_intmatch_op').val(op); + $('#edit_intmatch_field').val(val); + $('#edit_intmatch').dialog({ + title: title, + height: 'auto', width: 'auto', + draggable: true, resizable: false, + autoOpen: true, + position: { + my: 'bottom left', + at: 'top right', + of: obj, + collision: 'fit' + }, + buttons: { + "Save": function() { + var target = + $.trim($('#edit_intmatch_target').val()); + var op = $.trim($('#edit_intmatch_op').val()); + var val = + $.trim($('#edit_intmatch_field').val()); + if (!target) + alert('Bad target'); + else if (!op || !val) + alert("Bad value"); + else + { + callback(obj, target, op, val); + $(this).dialog('close'); + } + }, + "Close": function() { + $(this).dialog('close'); + } + } + }); +} + function edit_clause(obj) { var cmd = $(obj).find('th.cmd').attr('cmd'); @@ -512,6 +610,62 @@ function edit_clause(obj) changed(1); }); break; + case 'textmatch': + if (tval == 'Enter text here...') + { + tgt = "%field"; + ptn = tval; + } + else + { + b = tval.split(matchesp); + if (b.length != 2) + { + alert('Bad textmatch value'); + break; + } + tgt = b[0]; + ptn = b[1]; + } + edit_textmatch(target, title, tgt, ptn, + function(obj, tgt, ptn) { + $(obj).html(tgt + matchesp + ptn); + rulerefresh($(obj).closest('div.rule')); + changed(1); + }); + break; + case 'intmatch': + if (tval == "0") + { + tgt = "%field"; + op = "="; + val = "0"; + } + else + { + b = tval.split(matchesp); + if (b.length != 2) + { + alert('Bad intmatch value'); + break; + } + c = b[1].split(" "); + if (c.length != 2) + { + alert('Bad intmatch value'); + break; + } + tgt = b[0]; + op = c[0]; + val = c[1]; + } + edit_intmatch(target, title, tgt, op, val, + function(obj, tgt, op, val) { + $(obj).html(tgt + matchesp + op + ' ' + val); + rulerefresh($(obj).closest('div.rule')); + changed(1); + }); + break; case 'noarg': alert('This condition cannot be edited.'); break;