2012-04-11 20:54:59 +00:00
|
|
|
#!/mod/bin/jimsh
|
|
|
|
|
2012-04-14 21:31:25 +00:00
|
|
|
require system.class
|
|
|
|
|
2012-04-11 20:54:59 +00:00
|
|
|
proc dedupprocess {file} {{seen {}}} {
|
|
|
|
set ts [ts fetch $file 1]
|
2013-02-25 22:31:54 +00:00
|
|
|
|
|
|
|
if {[$ts flag "Deduped"]} {
|
|
|
|
lappend seen [file rootname [file tail $file]]
|
|
|
|
return [list nothing $ts "" ""]
|
|
|
|
}
|
|
|
|
|
2012-04-11 20:54:59 +00:00
|
|
|
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
|
2012-04-14 21:31:25 +00:00
|
|
|
regsub -all -- {[?]} $fn "" fn
|
2012-04-11 20:54:59 +00:00
|
|
|
|
|
|
|
set stat ok
|
2013-02-25 22:31:54 +00:00
|
|
|
if {[$ts inuse]} {
|
2012-04-14 21:31:25 +00:00
|
|
|
set stat inuse
|
|
|
|
} elseif {$fn in $seen} {
|
2012-04-11 20:54:59 +00:00
|
|
|
set stat dup
|
|
|
|
} elseif {[string length $syn] > 40} {
|
|
|
|
set stat error
|
|
|
|
} elseif {$base eq $fn} {
|
|
|
|
set stat nothing
|
2013-02-25 22:31:54 +00:00
|
|
|
$ts set_deduped
|
2012-04-11 20:54:59 +00:00
|
|
|
} elseif {[file exists "$dir/$fn.ts"]} {
|
|
|
|
set stat preserve
|
|
|
|
}
|
|
|
|
|
|
|
|
lappend seen $fn
|
|
|
|
|
|
|
|
return [list $stat $ts $syn $fn]
|
|
|
|
}
|
|
|
|
|