-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortgenre.tcl
53 lines (41 loc) · 1.14 KB
/
sortgenre.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
proc load_genre_database {} {
#global genre_db
global sortedgenrelist
global midi
global exec_out
if {[array exist genre_db]} return
#set genrefile [file join $midi(rootfolder) genre.tsv]
set genrefile genre.tsv
#if {![file exist $genrefile]} {
# append exec_out "Could not find genre.tsv in $midi(rootfolder)\ncreating template."
# initialize_genre_database}
set i 0
set genrelist {}
set inhandle [open $genrefile]
while {![eof $inhandle]} {
gets $inhandle line
set data [split $line \t]
set f [lindex $data 0]
set g [lindex $data 1]
#set gtrimmed [string map {\" {}} $g]
set gtrimmed [string trimleft $g \"]
set gtrimmed [string trimright $gtrimmed \"]
set newdata [list $f $gtrimmed]
lappend genrelist $newdata
incr i
}
close $inhandle
set sortedgenrelist [lsort -index 1 $genrelist]
puts "last record number = $i"
}
load_genre_database
set outhandle [open sortedgenre.txt w]
foreach item $sortedgenrelist {
set has_slash [string first \/ [lindex $item 0]]
if {$has_slash < 0} {
puts "illegal artist [lindex $item 0]"
} else {
puts $outhandle "[lindex $item 0]\t[lindex $item 1]"
}
}
close $outhandle