#!/mod/bin/jimsh package require cgi source /mod/var/mongoose/lib/setup require ts.class pretty_size altrow puts "Content-Type: text/html" puts "" cgi_input #cgi_dump set dir [cgi_get dir "/media/My Video"] set doit [cgi_get doit 0] # Strip double slashes header puts "
De-duplicate $dir " regsub -all -- {\/+} "$dir/*" "/" sdir set seen {} foreach file [lsort [glob -nocomplain "$sdir"]] { if {[file extension $file] ne ".hmt"} { continue } altrow set ts [ts fetch $file 1] set base [file tail [file rootname $file]] puts "" set syn [$ts get synopsis] regsub -nocase -all -- {^new series\.* *} $syn "" syn regsub -nocase -all -- {^cbeebies\. *} $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 "" } puts {
File Proposed Filename Proposed Title Status
$base$fn$syn" if {$fn in $seen} { 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" } } elseif {[string length $syn] > 40} { puts -nonewline "Cannot process" } elseif {$base eq $fn} { puts -nonewline "Nothing to do" } elseif {[file exists "$dir/$fn.ts"]} { puts -nonewline "Preserving" } elseif {$doit} { # Dooooo, it. $ts settitle $syn ts renamegroup $file $fn puts -nonewline "Done" } lappend seen $fn puts "
} if {!$doit} { puts "" } puts {
" footer