| 1 |
#!/usr/bin/ruby |
| 2 |
|
| 3 |
# |
| 4 |
# This script generates a data file using data from freedb.org. |
| 5 |
# |
| 6 |
# Typical usage: |
| 7 |
# |
| 8 |
# wget -O- http://www.freedb.org/freedb/jazz/380a0a05 | ./parsecd.rb |
| 9 |
# |
| 10 |
|
| 11 |
track = [] |
| 12 |
|
| 13 |
class String |
| 14 |
def tex |
| 15 |
return sub(/&/, "\\\\&").sub(/%/, "\\\\%").sub(/#/, "\\\\#") |
| 16 |
end |
| 17 |
end |
| 18 |
|
| 19 |
$stdin.each_line do |line| |
| 20 |
name, content = line.split("=") |
| 21 |
name.strip! if name |
| 22 |
content.strip! if content |
| 23 |
|
| 24 |
if name == "DTITLE" then |
| 25 |
author, title = content.split("/") |
| 26 |
author = "" if ! author |
| 27 |
title = "" if ! title |
| 28 |
author.strip! |
| 29 |
title.strip! |
| 30 |
author_cap = [] |
| 31 |
author.each(" ") { |word| author_cap << word.strip.capitalize.tex } |
| 32 |
print "\\covertext{\n", author_cap.join(" "), "\\\\\n", "\\bfseries ", title.strip.tex, "\n}\n\n" |
| 33 |
|
| 34 |
print "\\leftspine{", author.upcase.tex, "}\n\n" |
| 35 |
print "\\centerspine{", title.upcase.tex, "}\n\n" |
| 36 |
|
| 37 |
end |
| 38 |
|
| 39 |
if name.strip =~ /TTITLE.*/ then |
| 40 |
track << content |
| 41 |
end |
| 42 |
end |
| 43 |
|
| 44 |
print "\\lefttracklist{\n" |
| 45 |
|
| 46 |
if track.size < 16 then track.each { |x| print "\\track ", x.tex, "\n" } |
| 47 |
else |
| 48 |
track[0,(track.size/2)+1].each { |x| print "\\track ", x.tex, "\n" } |
| 49 |
print "}\n\n\\righttracklist{\n" |
| 50 |
track[(track.size/2)+1,track.size].each { |x| print "\\track ", x.tex, "\n" } |
| 51 |
end |
| 52 |
|
| 53 |
|
| 54 |
print "}\n" |