diff --git a/CONTROL/control b/CONTROL/control index a4fb4a8..ad7de5a 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,9 +1,9 @@ Package: webif Priority: optional Section: web -Version: 0.9.5 +Version: 0.9.5-1 Architecture: mipsel Maintainer: af123@hummypkg.org.uk -Depends: webif-channelicons,mongoose(>=3.0-7),jim(>=0.73-1),jim-oo,jim-sqlite3(>=0.73),jim-cgi(>=0.5),service-control(>=1.2),busybox(>=1.19.3-1),lsof,epg(>=1.0.9),hmt(>=1.1.6),ssmtp,anacron,trm,openssl-command,nicesplice,id3v2,file,rsvsync +Depends: webif-channelicons,mongoose(>=3.0-7),jim(>=0.73-1),jim-oo,jim-sqlite3(>=0.73),jim-cgi(>=0.5),service-control(>=1.2),busybox(>=1.19.3-1),lsof,epg(>=1.0.9),hmt(>=1.1.6),ssmtp,anacron,trm,openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.1) Suggests: ffmpeg,webif-iphone Description: An evolving web interface for the Humax. diff --git a/var/mongoose/cgi-bin/browse/browse.js b/var/mongoose/cgi-bin/browse/browse.js index 350724d..0f74961 100755 --- a/var/mongoose/cgi-bin/browse/browse.js +++ b/var/mongoose/cgi-bin/browse/browse.js @@ -582,7 +582,7 @@ var dmenuclick = function(action, el, pos) // Buttons $('#dedup').button().click(function() { - window.location = '/cgi-bin/dedup.jim?dir=' + window.location = '/dedup/dedup.jim?dir=' + encodeURIComponent(dir); }); diff --git a/var/mongoose/html/dedup/dedup b/var/mongoose/html/dedup/dedup new file mode 100755 index 0000000..2197d09 --- /dev/null +++ b/var/mongoose/html/dedup/dedup @@ -0,0 +1,74 @@ +#!/mod/bin/jimsh + +source /mod/var/mongoose/lib/setup +require ts.class + +source /mod/var/mongoose/html/dedup/normalise.jim +source /mod/var/mongoose/html/dedup/process.jim + +set dirs {} + +set doit 0 +foreach arg $argv { + if {$arg eq "-yes"} { + set doit 1 + } else { + lappend dirs $arg + } +} +if {![llength $dirs]} { lappend dirs [exec pwd] } + +foreach dir $dirs { + if {[string index $dir end] eq "/"} { + set dir [string range $dir 0 end-1] + } + puts "\[$dir\]" + + foreach file [readdir $dir] { + if {[file extension $file] ne ".hmt"} { continue } + + set file "$dir/$file" + + set base [file tail [file rootname $file]] + lassign [dedupprocess $file] stat ts syn fn + + puts -nonewline "$base -> " + + switch $stat { + dup { + puts -nonewline "Duplicate" + if {$doit} { + set dupdir "$dir/_duplicates" + if {![file exists $dupdir]} { + file mkdir $dupdir + } + while {[file exists $dupdir/$fn.hmt]} { + append fn "~" + } + ts renamegroup $file "_duplicates/$fn" + puts -nonewline " - Renamed to _duplicates/$fn" + } + } + error { + puts -nonewline "Cannot process" + } + nothing { + puts -nonewline "Nothing to do" + } + preserve { + puts -nonewline "Preserving" + } + ok { + puts -nonewline $fn + if {$doit} { + # Dooooo, it. + $ts settitle $syn + ts renamegroup $file $fn + puts -nonewline "Done" + } + } + } + puts "" + } +} + diff --git a/var/mongoose/cgi-bin/dedup.jim b/var/mongoose/html/dedup/dedup.jim similarity index 53% rename from var/mongoose/cgi-bin/dedup.jim rename to var/mongoose/html/dedup/dedup.jim index 4d10c59..97d6f17 100755 --- a/var/mongoose/cgi-bin/dedup.jim +++ b/var/mongoose/html/dedup/dedup.jim @@ -4,6 +4,9 @@ package require cgi source /mod/var/mongoose/lib/setup require ts.class pretty_size altrow +source normalise.jim +source process.jim + puts "Content-Type: text/html" puts "" @@ -15,6 +18,8 @@ set doit [cgi_get doit 0] header +puts "" + puts "
De-duplicate $dir @@ -31,34 +36,17 @@ set seen {} foreach file [readdir $dir] { set file "$dir/$file" if {[file extension $file] ne ".hmt"} { continue } - altrow - set ts [ts fetch $file 1] + set base [file tail [file rootname $file]] + lassign [dedupprocess $file] stat ts syn fn + + altrow puts "" - set syn [$ts get synopsis] - regsub -nocase -all -- {^new series\.* *} $syn "" syn - regsub -nocase -all -- {^cbeebies\. *} $syn "" syn - regsub -nocase -all -- {^brand new series - *} $syn "" syn - regsub -all -- { *[:].*$} $syn "" syn - if {[string length $syn] > 40} { - lassign [split $syn "."] v w - set syn $v - if {[string length $syn] < 6 && [string length $w] < 6} { - append syn "_$w" - } - } - if {[string length $syn] < 10} { - if {[string match "${syn}*" [$ts get title]]} { - set syn [$ts get title] - } else { - append syn " [$ts get title]" - } - } - regsub -all -- {[\/ &]} $syn "_" fn puts "" puts "" puts "" puts "" @@ -99,25 +93,8 @@ if {!$doit} { puts "" } puts { - - -" - footer diff --git a/var/mongoose/html/dedup/normalise.jim b/var/mongoose/html/dedup/normalise.jim new file mode 100755 index 0000000..ec77602 --- /dev/null +++ b/var/mongoose/html/dedup/normalise.jim @@ -0,0 +1,47 @@ +#!/mod/bin/jimsh + +set dedup_prefixes { + {^new series\.* *} + {^cbeebies\.* *} + {^brand new series *-* *} + {^\.+} +} + +proc dedupnormalise {title {reserve ""}} { + global dedup_prefixes + + # Strip common prefixes + foreach prefix $dedup_prefixes { + regsub -nocase -all -- $prefix $title "" title + } + + # Strip anything following a colon. + regsub -all -- { *[:].*$} $title "" title + + # If the resulting string is longer than 40 characters then + # split around . and take the left hand side if appropriate. + if {[string length $title] > 40} { + lassign [split $title "."] v w + set title $v + if {[string length $title] < 6 && [string length $w] < 6} { + append title "_$w" + } + } + + # if still short, add the reserve string. + if {[string length $title] < 10} { + if {[string match "${title}*" $reserve]} { + set title $reserve + } else { + append title " $reserve" + } + } + + # Shorten if too long. + if {[string length $title] > 40} { + set title [string range $title 0 39] + } + + return $title +} + diff --git a/var/mongoose/html/dedup/process.jim b/var/mongoose/html/dedup/process.jim new file mode 100755 index 0000000..2a4b507 --- /dev/null +++ b/var/mongoose/html/dedup/process.jim @@ -0,0 +1,26 @@ +#!/mod/bin/jimsh + +proc dedupprocess {file} {{seen {}}} { + set ts [ts fetch $file 1] + set dir [file dirname $file] + set base [file tail [file rootname $file]] + set syn [dedupnormalise [$ts get synopsis] [$ts get title]] + # Escape special characters to create the filename. + regsub -all -- {[\/ &]} $syn "_" fn + + set stat ok + if {$fn in $seen} { + set stat dup + } elseif {[string length $syn] > 40} { + set stat error + } elseif {$base eq $fn} { + set stat nothing + } elseif {[file exists "$dir/$fn.ts"]} { + set stat preserve + } + + lappend seen $fn + + return [list $stat $ts $syn $fn] +} + diff --git a/var/mongoose/html/dedup/script.js b/var/mongoose/html/dedup/script.js new file mode 100755 index 0000000..469fd7c --- /dev/null +++ b/var/mongoose/html/dedup/script.js @@ -0,0 +1,14 @@ + +$(function() { + +$('#browse').button().click(function() { + window.location = '/cgi-bin/browse.jim?dir=' + + encodeURIComponent($('#dir').text()); +}); + +$('#dedup').button().click(function() { + window.location = window.location + '&doit=1'; +}); + +}); +
$base$fn$syn" - if {$fn in $seen} { + switch $stat { + dup { puts -nonewline "Duplicate" if {$doit} { set dupdir "$dir/_duplicates" @@ -69,19 +57,25 @@ foreach file [readdir $dir] { ts renamegroup $file "_duplicates/$fn" puts -nonewline " - Renamed to _duplicates/$fn" } - } elseif {[string length $syn] > 40} { + } + error { puts -nonewline "Cannot process" - } elseif {$base eq $fn} { + } + nothing { puts -nonewline "Nothing to do" - } elseif {[file exists "$dir/$fn.ts"]} { + } + preserve { puts -nonewline "Preserving" - } elseif {$doit} { - # Dooooo, it. - $ts settitle $syn - ts renamegroup $file $fn - puts -nonewline "Done" + } + ok { + if {$doit} { + # Dooooo, it. + $ts settitle $syn + ts renamegroup $file $fn + puts -nonewline "Done" + } + } } - lappend seen $fn puts "