2012-04-11 20:54:59 +00:00
|
|
|
#!/mod/bin/jimsh
|
|
|
|
|
|
|
|
set dedup_prefixes {
|
|
|
|
{^new series\.* *}
|
|
|
|
{^cbeebies\.* *}
|
2012-04-14 21:31:25 +00:00
|
|
|
{^cbbc\.* *}
|
2012-04-11 20:54:59 +00:00
|
|
|
{^brand new series *-* *}
|
|
|
|
{^\.+}
|
|
|
|
}
|
|
|
|
|
2012-05-21 20:23:41 +00:00
|
|
|
proc loadseries {dir} {
|
|
|
|
global seriesmap
|
|
|
|
set seriesmap [dict create]
|
|
|
|
|
|
|
|
if {![file exists "$dir/series.info"]} { return }
|
|
|
|
|
|
|
|
if {[catch {set fd [open "$dir/series.info" "r"]} msg]} {
|
|
|
|
puts "Error opening series.info: $msg"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach line [split [read $fd] "\n\r"] {
|
|
|
|
set i [string first " ==> " $line]
|
|
|
|
if {$i == -1} { continue }
|
|
|
|
set name [string range $line 0 $($i - 1)]
|
|
|
|
set prefix [string range $line $($i + 5) end]
|
|
|
|
if {$prefix eq ""} { continue }
|
|
|
|
dict set seriesmap $name $prefix
|
|
|
|
regsub -all -- {[[:space:]]+} [string tolower $name] "" name
|
|
|
|
dict set seriesmap $name $prefix
|
|
|
|
}
|
|
|
|
$fd close
|
|
|
|
}
|
|
|
|
|
2012-04-11 20:54:59 +00:00
|
|
|
proc dedupnormalise {title {reserve ""}} {
|
2012-05-21 20:23:41 +00:00
|
|
|
global dedup_prefixes seriesmap
|
2012-04-11 20:54:59 +00:00
|
|
|
|
|
|
|
# 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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 20:23:41 +00:00
|
|
|
if {[dict exists $seriesmap $title]} {
|
|
|
|
set ntitle "$seriesmap($title): $title"
|
|
|
|
set title $ntitle
|
|
|
|
} else {
|
2012-06-15 21:34:07 +00:00
|
|
|
# Try lower case without spaces
|
2012-05-21 20:23:41 +00:00
|
|
|
regsub -all -- {[[:space:]]+} [string tolower $title] "" ntitle
|
|
|
|
if {[dict exists $seriesmap $ntitle]} {
|
|
|
|
set title "$seriesmap($ntitle): $title"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-31 22:39:54 +00:00
|
|
|
# if still short, add the reserve string.
|
|
|
|
if {[string length $title] < 10} {
|
|
|
|
if {[string match "${title}*" $reserve]} {
|
|
|
|
set title $reserve
|
|
|
|
} else {
|
|
|
|
append title " $reserve"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-11 20:54:59 +00:00
|
|
|
# Shorten if too long.
|
|
|
|
if {[string length $title] > 40} {
|
|
|
|
set title [string range $title 0 39]
|
|
|
|
}
|
|
|
|
|
|
|
|
return $title
|
|
|
|
}
|
|
|
|
|