summaryrefslogtreecommitdiff
path: root/audio/ruby-freedb/files/patch-lib::freedb.rb
blob: 6f3e4562d2e7fd0ca33ff6ca825b3da01a3b73fb (plain) (blame)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
--- lib/freedb.rb.orig	Wed Sep 25 15:05:37 2002
+++ lib/freedb.rb	Sat Oct  5 00:04:31 2002
@@ -58,34 +58,53 @@
   #  @tracks.clear
     @results[index] =~ /\S+ \S+/
     @handler.send_cmd("read", $&)
+
+    # swallow the whole response into a hash
+    response = Hash.new
+
     @handler.each_line { |line|
       case line
-	when /^4\d\d (.+)/
-	  raise(FreedbError, $1)
-	when /^210 (\S+)/
-	  @genre = $1
-	# #or 
-	when /^DGENRE=(.+)/
-	  @exact_genre = $1
-	when /^DYEAR=(\d+)/
-	  @year = $1.to_i
-        when /^DTITLE=(.*)/
-	  @artist, @title = $1.split(" / ")
-	  @title ||= @artist
-	when /^TTITLE(\d+)=(.*)/
-	  h = @tracks_ext[$1.to_i]
-	  h["title"] = $2
-	  @tracks[$1.to_i] = $2
-	when /^EXTD=(.*)/
-	  @ext_infos ||= ""
-	  @ext_infos += $1
-	when /^EXTT(\d+)=(.*)/
-	  h = @tracks_ext[$1.to_i]
-	  h["ext"] = $2
-	  #@tracks << md[1]
-	#when /^TTITLE\d+=/
+	when /^(\d+) (\S+)/, /^([A-Za-z0-9_]+)=(.*)/
+	  key = $1.upcase
+
+	  val = $2.gsub(/\\(.)/) {
+	    case $1
+	      when "t"
+		"\t"
+	      when "n"
+		"\n"
+	      else
+		$1
+	    end
+          }
+
+	  (response[key] ||= '') << val
       end
     }
+
+    @genre = response['210']
+    @exact_genre = response['DGENRE']
+    @year = response['DYEAR'].to_i
+    @ext_infos = response['EXTD']
+
+    # %r is to avoid ruby >= 1.7 warning
+    @artist, @title = response['DTITLE'].split(%r" / ", 2)
+    # A self-titled album may not have a title part
+    @title ||= @artist
+
+    response.each { |key, val|
+      case key
+	when /^4\d\d$/
+	  raise(FreedbError, val)
+	when /^TTITLE(\d+)$/
+	  i = $1.to_i
+	  @tracks_ext[i]["title"] = @tracks[i] = val
+	when /^EXTT(\d+)$/
+	  i = $1.to_i
+	  @tracks_ext[i]["ext"] = val
+      end
+    }
+
     self
   end