summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/cd/parsecd.rb
blob: 6f7f02580b130efa0986dd8b897f30b16124684c (plain)
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
52
53
54
#!/usr/bin/ruby

#
# This script generates a data file using data from freedb.org.
#
# Typical usage:
#
#  wget -O- http://www.freedb.org/freedb/jazz/380a0a05 | ./parsecd.rb
#

track = []

class String
	def tex
		return sub(/&/, "\\\\&").sub(/%/, "\\\\%").sub(/#/, "\\\\#")
	end
end

$stdin.each_line do |line|
	name, content = line.split("=")
	name.strip! if name
	content.strip! if content

	if name == "DTITLE" then
		author, title = content.split("/")
		author = "" if ! author
		title = "" if ! title
		author.strip!
		title.strip!
		author_cap = []
		author.each(" ") { |word| author_cap << word.strip.capitalize.tex }
		print "\\covertext{\n", author_cap.join(" "), "\\\\\n", "\\bfseries ", title.strip.tex, "\n}\n\n"

		print "\\leftspine{", author.upcase.tex, "}\n\n"
		print "\\centerspine{", title.upcase.tex, "}\n\n"

	end
	
	if name.strip =~ /TTITLE.*/ then
		track << content
	end
end

print "\\lefttracklist{\n"

if track.size < 16 then track.each { |x| print "\\track ", x.tex, "\n" }
else
	track[0,(track.size/2)+1].each { |x| print "\\track ", x.tex, "\n" }
	print "}\n\n\\righttracklist{\n"
	track[(track.size/2)+1,track.size].each { |x| print "\\track ", x.tex, "\n" }
end


print "}\n"