ruby-audioinfo 0.1.7 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.2 / 2012-02-27
2
+
3
+ * text encoding issues fixed
4
+ * updated dependencies
5
+
1
6
  === 0.1.7 / 2010-06-18
2
7
 
3
8
  * included differents patches from Marcello Barnaba (see vtj-ruby-audioinfo fork)
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ lib/audioinfo.rb
6
+ lib/audioinfo/album.rb
7
+ lib/audioinfo/mpcinfo.rb
8
+ test/mpcinfo.rb
@@ -1,8 +1,10 @@
1
1
  = ruby-audioinfo
2
2
 
3
- by Guillaume Pierronnet
4
3
  * http://ruby-audioinfo.rubyforge.org
5
4
  * http://rubyforge.org/projects/ruby-audioinfo/
5
+ * https://github.com/moumar/ruby-audioinfo
6
+
7
+ by Guillaume Pierronnet
6
8
 
7
9
  == DESCRIPTION:
8
10
 
data/Rakefile CHANGED
@@ -1,48 +1,40 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'hoe'
4
+
5
+ Hoe.plugin :yard
6
+ Hoe.plugin :gemspec
7
+
8
+ Hoe.spec('ruby-audioinfo') do
9
+ developer "Guillaume Pierronnet", "guillaume.pierronnet@gmail.com"
10
+ developer 'Marcello Barnaba', "unknown"
11
+ remote_rdoc_dir = ''
12
+ rdoc_locations << "rubyforge.org:/var/www/gforge-projects/ruby-audioinfo/"
13
+
14
+ self.extra_rdoc_files = FileList["*.rdoc"]
15
+ #history_file = "History.txt"
16
+ self.readme_file = "README.rdoc"
17
+ self.test_globs = ["test/test_*.rb"]
18
+ self.rsync_args = "-rv --delete"
19
+
20
+ extra_deps << ['ruby-mp3info', '>= 0.7.1']
21
+ extra_deps << ['ruby-ogginfo', '>= 0.6.8']
22
+ extra_deps << ['mp4info', '>= 1.7.3']
23
+ extra_deps << ['moumar-wmainfo-rb', '>= 0.7']
24
+ extra_deps << ['flacinfo-rb', '>= 0.4']
25
+ extra_deps << ['apetag', '>= 1.1.4']
26
+ #extra_dev_deps << ["rake", ">=0"]
27
+ end
28
+
29
+ =begin
30
+ # vim: syntax=Ruby
1
31
  require 'rubygems'
2
32
  require "rake/rdoctask"
3
33
 
4
- require File.join(File.expand_path(File.dirname(__FILE__)), 'lib', 'audioinfo')
5
-
6
- begin
7
- require 'jeweler'
8
-
9
- #Jeweler::GemcutterTasks.new
10
-
11
- Jeweler::Tasks.new do |gemspec|
12
- gemspec.name = 'ruby-audioinfo'
13
- gemspec.version = AudioInfo::VERSION
14
- gemspec.authors = ['Guillaume Pierronnet', 'Marcello Barnaba']
15
- gemspec.email = 'moumar@rubyforge.org'
16
- gemspec.date = '2010-03-20'
17
-
18
- gemspec.homepage = 'http://ruby-audioinfo.rubyforge.org'
19
- gemspec.summary = 'Unified audio info access library'
20
- gemspec.description = 'ruby-audioinfo glues together various audio libraries and presents a single API to the developer.'
21
- 'Currently, supported formats are: mp3, ogg, mpc, ape, wma, flac, aac, mp4, m4a.'
22
-
23
- gemspec.files = %w( README.txt Rakefile History.txt) + Dir['{lib,test}/**/*']
24
- gemspec.extra_rdoc_files = %w( README.txt )
25
- gemspec.has_rdoc = true
26
- gemspec.require_path = 'lib'
27
-
28
- gemspec.add_dependency 'ruby-mp3info', '>= 0.6.3'
29
- gemspec.add_dependency 'ruby-ogginfo', '>= 0.3.1'
30
- gemspec.add_dependency 'mp4info', '>= 1.7.3'
31
- gemspec.add_dependency 'wmainfo-rb', '>= 0.5'
32
- gemspec.add_dependency 'flacinfo-rb', '>= 0.4'
33
- gemspec.add_dependency 'apetag', '= 1.1.2'
34
- end
35
- Jeweler::GemcutterTasks.new
36
-
37
- Jeweler::RubyforgeTasks.new
38
-
39
- rescue LoadError
40
- puts 'Jeweler not available. Install it with: gem install jeweler'
41
- end
42
-
43
34
  Rake::RDocTask.new do |rd|
44
- rd.main = "README.txt"
35
+ rd.main = "README.rdoc"
45
36
  rd.rdoc_dir = "rdoc"
46
- rd.rdoc_files.include("README.txt", "History.txt", "lib/**/*.rb")
37
+ rd.rdoc_files.include("README.rdoc", "History.txt", "lib/**/*.rb")
47
38
  rd.title = "ruby-audioinfo #{AudioInfo::VERSION}"
48
39
  end
40
+ =end
@@ -43,12 +43,15 @@ class AudioInfo::Album
43
43
  @path = path
44
44
  @multicd = false
45
45
  @basename = @path
46
- exts = AudioInfo::SUPPORTED_EXTENSIONS.join(",")
46
+ exts = AudioInfo::SUPPORTED_EXTENSIONS.collect do |ext|
47
+ ext.gsub(/[a-z]/) { |c| "[#{c.downcase}#{c.upcase}]" }
48
+ end.join(",")
47
49
 
48
50
  # need to escape the glob path
49
51
  glob_escaped_path = @path.gsub(/([{}?*\[\]])/) { |s| '\\' << s }
50
52
 
51
- file_names = Dir.glob( File.join(glob_escaped_path, "*.{#{exts}}") , File::FNM_CASEFOLD).sort
53
+ glob_val = File.join(glob_escaped_path, "*.{#{exts}}")
54
+ file_names = Dir.glob(glob_val).sort
52
55
 
53
56
  if fast_lookup
54
57
  file_names = [file_names.first, file_names.last]
@@ -104,12 +107,8 @@ class AudioInfo::Album
104
107
 
105
108
  # title of the album
106
109
  def title
107
- albums = @files.collect { |f| f.album }.uniq
108
- #if albums.size > 1
109
- # "#{albums.first} others candidates: '" + albums[1..-1].join("', '") + "'"
110
- #else
111
- albums.first
112
- #end
110
+ hash_counted = self.files.collect { |f| f.album }.inject(Hash.new(0)) { |hash, album| hash[album] += 1; hash }
111
+ hash_counted.sort_by { |k, v| v }.last[0]
113
112
  end
114
113
 
115
114
  # mbid (MusicBrainz ID) of the album
@@ -146,6 +145,10 @@ class AudioInfo::Album
146
145
  out.string
147
146
  end
148
147
 
148
+ def inspect
149
+ @infos.inspect
150
+ end
151
+
149
152
  end
150
153
 
151
154
 
@@ -52,7 +52,7 @@ class MpcInfo
52
52
  header = StringIO.new(@file.read(25))
53
53
  header_size = 28
54
54
  #stream_version_byte = header.read(4).unpack("V").first
55
- stream_version_byte = header.read(1)[0] #.unpack("c").first
55
+ stream_version_byte = header.read(1)[0].ord #.unpack("c").first
56
56
 
57
57
  @infos['stream_major_version'] = (stream_version_byte & 0x0F)
58
58
  @infos['stream_minor_version'] = (stream_version_byte & 0xF0) >> 4
@@ -168,7 +168,7 @@ class MpcInfo
168
168
  end
169
169
 
170
170
  def read8(io)
171
- io.read(1)[0]
171
+ io.read(1)[0].ord
172
172
  end
173
173
 
174
174
  def read16(io)
data/lib/audioinfo.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "iconv"
1
+ # encoding: utf-8
2
2
  require "stringio"
3
3
 
4
4
  require "mp3info"
@@ -15,6 +15,13 @@ require "audioinfo/mpcinfo"
15
15
  class AudioInfoError < Exception ; end
16
16
 
17
17
  class AudioInfo
18
+ if RUBY_VERSION[0..2] == "1.8"
19
+ RUBY_1_8 = true
20
+ require "iconv"
21
+ else
22
+ RUBY_1_8 = false
23
+ end
24
+
18
25
  MUSICBRAINZ_FIELDS = {
19
26
  "trmid" => "TRM Id",
20
27
  "artistid" => "Artist Id",
@@ -28,7 +35,7 @@ class AudioInfo
28
35
 
29
36
  SUPPORTED_EXTENSIONS = %w{mp3 ogg mpc wma mp4 aac m4a flac}
30
37
 
31
- VERSION = "0.1.7"
38
+ VERSION = "0.2"
32
39
 
33
40
  attr_reader :path, :extension, :musicbrainz_infos, :tracknum, :bitrate, :vbr
34
41
  attr_reader :artist, :album, :title, :length, :date
@@ -49,20 +56,29 @@ class AudioInfo
49
56
  ret
50
57
  end
51
58
 
52
- # open the file with path +fn+ and convert all tags from/to specified +encoding+
53
- def initialize(filename, encoding = 'utf-8')
59
+ # test whether +path+ is a valid and supported audiofile
60
+ def self.is_audio_file?(path)
61
+ begin
62
+ AudioInfo.new(path)
63
+ return true
64
+ rescue AudioInfoError
65
+ return false
66
+ end
67
+ end
68
+
69
+ # open the file with path +fn+
70
+ def initialize(filename)
54
71
  raise(AudioInfoError, "path is nil") if filename.nil?
55
72
  @path = filename
56
73
  ext = File.extname(@path)
57
74
  raise(AudioInfoError, "cannot find extension") if ext.empty?
58
75
  @extension = ext[1..-1].downcase
59
76
  @musicbrainz_infos = {}
60
- @encoding = encoding
61
77
 
62
78
  begin
63
79
  case @extension
64
80
  when 'mp3'
65
- @info = Mp3Info.new(filename, :encoding => @encoding)
81
+ @info = Mp3Info.new(filename)
66
82
  default_tag_fill
67
83
  #"TXXX"=>
68
84
  #["MusicBrainz TRM Id\000",
@@ -90,7 +106,7 @@ class AudioInfo
90
106
  @info.close
91
107
 
92
108
  when 'ogg'
93
- @info = OggInfo.new(filename, @encoding)
109
+ @info = OggInfo.new(filename)
94
110
  default_fill_musicbrainz_fields
95
111
  default_tag_fill
96
112
  @bitrate = @info.bitrate/1000
@@ -111,7 +127,7 @@ class AudioInfo
111
127
  fill_ape_tag(filename)
112
128
 
113
129
  when 'wma'
114
- @info = WmaInfo.new(filename, :encoding => @encoding)
130
+ @info = WmaInfo.new(filename, :encoding => 'utf-8')
115
131
  @artist = @info.tags["Author"]
116
132
  @album = @info.tags["AlbumTitle"]
117
133
  @title = @info.tags["Title"]
@@ -125,7 +141,8 @@ class AudioInfo
125
141
  @info.info["MusicBrainz/" + original_key]
126
142
  end
127
143
 
128
- when 'aac', 'mp4', 'm4a'
144
+ when 'mp4', 'aac', 'm4a'
145
+ @extension = 'mp4'
129
146
  @info = MP4Info.open(filename)
130
147
  @artist = @info.ART
131
148
  @album = @info.ALB
@@ -144,19 +161,18 @@ class AudioInfo
144
161
 
145
162
  when 'flac'
146
163
  @info = FlacInfo.new(filename)
147
- tags = convert_tags_encoding(@info.tags, "UTF-8")
148
- @artist = tags["ARTIST"] || tags["artist"]
149
- @album = tags["ALBUM"] || tags["album"]
150
- @title = tags["TITLE"] || tags["title"]
151
- @tracknum = (tags["TRACKNUMBER"]||tags["tracknumber"]).to_i
152
- @date = tags["DATE"]||tags["date"]
164
+ @artist = @info.tags["ARTIST"] || @info.tags["artist"]
165
+ @album = @info.tags["ALBUM"] || @info.tags["album"]
166
+ @title = @info.tags["TITLE"] || @info.tags["title"]
167
+ @tracknum = (@info.tags["TRACKNUMBER"]||@info.tags["tracknumber"]).to_i
168
+ @date = @info.tags["DATE"]||@info.tags["date"]
153
169
  @length = @info.streaminfo["total_samples"] / @info.streaminfo["samplerate"].to_f
154
170
  @bitrate = File.size(filename).to_f*8/@length/1024
155
- tags.each do |tagname, tagvalue|
171
+ @info.tags.each do |tagname, tagvalue|
156
172
  next unless tagname =~ /^musicbrainz_(.+)$/
157
- @musicbrainz_infos[$1] = tags[tagname]
173
+ @musicbrainz_infos[$1] = @info.tags[tagname]
158
174
  end
159
- @musicbrainz_infos["trmid"] = tags["musicip_puid"]
175
+ @musicbrainz_infos["trmid"] = @info.tags["musicip_puid"]
160
176
  #default_fill_musicbrainz_fields
161
177
 
162
178
  else
@@ -233,14 +249,14 @@ class AudioInfo
233
249
  if @needs_commit
234
250
  case @info
235
251
  when Mp3Info
236
- Mp3Info.open(@path, :encoding => @encoding) do |info|
252
+ Mp3Info.open(@path) do |info|
237
253
  info.tag.artist = @artist
238
254
  info.tag.title = @title
239
255
  info.tag.album = @album
240
256
  info.tag.tracknum = @tracknum
241
257
  end
242
258
  when OggInfo
243
- OggInfo.open(@path, @encoding) do |ogg|
259
+ OggInfo.open(@path) do |ogg|
244
260
  { "artist" => @artist,
245
261
  "album" => @album,
246
262
  "title" => @title,
@@ -302,14 +318,13 @@ class AudioInfo
302
318
 
303
319
  def default_tag_fill(tags = @info.tag)
304
320
  %w{artist album title}.each do |v|
305
- instance_variable_set( "@#{v}".to_sym, sanitize(tags[v].to_s) )
321
+ instance_variable_set( "@#{v}".to_sym, sanitize(tags[v]||"") )
306
322
  end
307
323
  end
308
324
 
309
325
  def fill_ape_tag(filename)
310
326
  begin
311
327
  @info = ApeTag.new(filename)
312
- #tags = convert_tags_encoding(@info.fields, "UTF-8")
313
328
  tags = @info.fields.inject({}) do |hash, (k, v)|
314
329
  hash[k.downcase] = v ? v.first : nil
315
330
  hash
@@ -323,19 +338,6 @@ class AudioInfo
323
338
  end
324
339
  end
325
340
 
326
- def convert_tags_encoding(tags_orig, from_encoding)
327
- tags = {}
328
- Iconv.open(@encoding, from_encoding) do |ic|
329
- tags_orig.inject(tags) do |hash, (k, v)|
330
- if v.is_a?(String)
331
- hash[ic.iconv(k)] = ic.iconv(v)
332
- end
333
- hash
334
- end
335
- end
336
- tags
337
- end
338
-
339
341
  def faad_info(file)
340
342
  stdout, stdout_w = IO.pipe
341
343
  stderr, stderr_w = IO.pipe
metadata CHANGED
@@ -1,168 +1,155 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-audioinfo
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 7
10
- version: 0.1.7
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Guillaume Pierronnet
14
9
  - Marcello Barnaba
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2010-06-18 00:00:00 +02:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
13
+ date: 2012-04-02 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
23
16
  name: ruby-mp3info
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &83894570 !ruby/object:Gem::Requirement
26
18
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 1
31
- segments:
32
- - 0
33
- - 6
34
- - 3
35
- version: 0.6.3
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.7.1
36
23
  type: :runtime
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
39
- name: ruby-ogginfo
40
24
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *83894570
26
+ - !ruby/object:Gem::Dependency
27
+ name: ruby-ogginfo
28
+ requirement: &83894300 !ruby/object:Gem::Requirement
42
29
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 17
47
- segments:
48
- - 0
49
- - 3
50
- - 1
51
- version: 0.3.1
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.8
52
34
  type: :runtime
53
- version_requirements: *id002
54
- - !ruby/object:Gem::Dependency
55
- name: mp4info
56
35
  prerelease: false
57
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *83894300
37
+ - !ruby/object:Gem::Dependency
38
+ name: mp4info
39
+ requirement: &83893930 !ruby/object:Gem::Requirement
58
40
  none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 13
63
- segments:
64
- - 1
65
- - 7
66
- - 3
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
67
44
  version: 1.7.3
68
45
  type: :runtime
69
- version_requirements: *id003
70
- - !ruby/object:Gem::Dependency
71
- name: wmainfo-rb
72
46
  prerelease: false
73
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *83893930
48
+ - !ruby/object:Gem::Dependency
49
+ name: moumar-wmainfo-rb
50
+ requirement: &83893420 !ruby/object:Gem::Requirement
74
51
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 1
79
- segments:
80
- - 0
81
- - 5
82
- version: "0.5"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0.7'
83
56
  type: :runtime
84
- version_requirements: *id004
85
- - !ruby/object:Gem::Dependency
86
- name: flacinfo-rb
87
57
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
58
+ version_requirements: *83893420
59
+ - !ruby/object:Gem::Dependency
60
+ name: flacinfo-rb
61
+ requirement: &83893200 !ruby/object:Gem::Requirement
89
62
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- hash: 3
94
- segments:
95
- - 0
96
- - 4
97
- version: "0.4"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0.4'
98
67
  type: :runtime
99
- version_requirements: *id005
100
- - !ruby/object:Gem::Dependency
101
- name: apetag
102
68
  prerelease: false
103
- requirement: &id006 !ruby/object:Gem::Requirement
69
+ version_requirements: *83893200
70
+ - !ruby/object:Gem::Dependency
71
+ name: apetag
72
+ requirement: &83892940 !ruby/object:Gem::Requirement
104
73
  none: false
105
- requirements:
106
- - - "="
107
- - !ruby/object:Gem::Version
108
- hash: 23
109
- segments:
110
- - 1
111
- - 1
112
- - 2
113
- version: 1.1.2
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.1.4
114
78
  type: :runtime
115
- version_requirements: *id006
116
- description: ruby-audioinfo glues together various audio libraries and presents a single API to the developer.
117
- email: moumar@rubyforge.org
118
- executables: []
79
+ prerelease: false
80
+ version_requirements: *83892940
81
+ - !ruby/object:Gem::Dependency
82
+ name: rdoc
83
+ requirement: &83892710 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '3.10'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *83892710
92
+ - !ruby/object:Gem::Dependency
93
+ name: hoe
94
+ requirement: &83892490 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ~>
98
+ - !ruby/object:Gem::Version
99
+ version: '3.0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *83892490
103
+ description: ! 'ruby-audioinfo glue together various audio ruby libraries and presents
104
+ a unified
119
105
 
120
- extensions: []
106
+ API to the developper. Currently, supported formats are: mp3, ogg, mpc, ape,
121
107
 
122
- extra_rdoc_files:
123
- - README.txt
124
- files:
108
+ wma, flac, aac, mp4, m4a.'
109
+ email:
110
+ - guillaume.pierronnet@gmail.com
111
+ - unknown
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files:
115
+ - History.txt
116
+ - Manifest.txt
117
+ - README.rdoc
118
+ files:
125
119
  - History.txt
126
- - README.txt
120
+ - Manifest.txt
121
+ - README.rdoc
127
122
  - Rakefile
128
123
  - lib/audioinfo.rb
129
124
  - lib/audioinfo/album.rb
130
- - lib/audioinfo/apetag.rb
131
125
  - lib/audioinfo/mpcinfo.rb
132
126
  - test/mpcinfo.rb
133
- has_rdoc: true
127
+ - .gemtest
134
128
  homepage: http://ruby-audioinfo.rubyforge.org
135
129
  licenses: []
136
-
137
130
  post_install_message:
138
- rdoc_options:
139
- - --charset=UTF-8
140
- require_paths:
131
+ rdoc_options:
132
+ - --main
133
+ - README.rdoc
134
+ require_paths:
141
135
  - lib
142
- required_ruby_version: !ruby/object:Gem::Requirement
136
+ required_ruby_version: !ruby/object:Gem::Requirement
143
137
  none: false
144
- requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- hash: 3
148
- segments:
149
- - 0
150
- version: "0"
151
- required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
143
  none: false
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- hash: 3
157
- segments:
158
- - 0
159
- version: "0"
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
160
148
  requirements: []
161
-
162
- rubyforge_project:
163
- rubygems_version: 1.3.7
149
+ rubyforge_project: ruby-audioinfo
150
+ rubygems_version: 1.8.17
164
151
  signing_key:
165
152
  specification_version: 3
166
- summary: Unified audio info access library
153
+ summary: ruby-audioinfo glue together various audio ruby libraries and presents a
154
+ unified API to the developper
167
155
  test_files: []
168
-
@@ -1,53 +0,0 @@
1
- # see http://www.personal.uni-jena.de/~pfk/mpp/sv8/apetag.html for specs
2
-
3
- class ApeTagError < StandardError ; end
4
-
5
- class ApeTag
6
- attr_reader :tag, :version
7
-
8
- def initialize(filename)
9
- @tag = {}
10
-
11
- begin
12
- @file = File.new(filename, "rb")
13
- @file.seek(-32, IO::SEEK_END)
14
-
15
- preamble, version, tagsize, itemcount, flags =
16
- @file.read(24).unpack("A8VVVV")
17
- @version = version/1000
18
-
19
- raise(ApeTagError, "cannot find preamble") if preamble != 'APETAGEX'
20
- @file.seek(-tagsize, IO::SEEK_END)
21
- itemcount.times do |i|
22
- len, flags = @file.read(8).unpack("VV")
23
- key = ""
24
- loop do
25
- c = @file.getc
26
- break if c == 0
27
- key << c
28
- end
29
- #ugly FIX
30
- @tag[key.downcase] = @file.read(len) unless len > 100_000
31
- end
32
- ensure
33
- @file.close
34
- end
35
- end
36
- end
37
-
38
- if $0 == __FILE__
39
- while filename = ARGV.shift
40
- puts "Getting info from #{filename}"
41
- begin
42
- ape = ApeTag.new(filename)
43
- rescue ApeTagError
44
- puts "error: doesn't appear to be an ape tagged file"
45
- else
46
- puts ape
47
- ape.tag.each do |key, value|
48
- puts "#{key} => #{value}"
49
- end
50
- end
51
- puts
52
- end
53
- end