webif/var/mongoose/html/dedup/normalise.jim
hummypkg 6ab9318fa9 update dedup
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@926 2a923420-c742-0410-a762-8d5b09965624
2012-04-14 21:31:25 +00:00

49 lines
1002 B
Plaintext
Executable File

#!/mod/bin/jimsh
set dedup_prefixes {
{^new series\.* *}
{^cbeebies\.* *}
{^cbbc\.* *}
{^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
}