我想获得一个干净的Mp3文件,没有任何附加数据,如id标签,封面图像,编码器信息或其他什么。 只是有效文件中的mp3,可以播放每个MP3播放器。
我从这个开始: Access MP3 audio data independently of ID3 tags? http://code.google.com/p/kodebucket/source/browse/trunk/bin/mp3dump.rb
很好地获取没有id标签的mp3的有效哈希,但是当你将输出保存到mp3文件中时,它已经坏了。
也许你有一个想法,如何让这项工作。
答案 0 :(得分:1)
这个Ruby库应该非常简单:
http://unixgods.org/~tilo/Ruby/ID3/docs/index.html
优选0.5.0或更高版本
安装gem后,检查'examples'目录中的文件
require 'id3'
filename = "bla.mp3"
if ID3.hasID3v1tag?( filename ) || ID3.hasID3v2tag?( filename )
puts "File size: #{ File::Stat.new(filename).size }" # file size including tags
myfile = ID3::AudioFile.new( filename )
puts "Audio length: #{myfile.audioLength}"
puts "Audio MD5sum: #{myfile.audioMD5sum}"
# delete both id3 v1 and id3 v2 tags from the file:
myfile.tagID3v1 = nil # it might be a good idea to store the info somewhere before deleting it
myfile.tagID3v2 = nil
myfile.write # we only write if we modified it..
end
例如:在irb中以交互方式测试
# /usr/bin/irb
irb> RUBY_VERSION
=> "1.8.6"
irb> require 'id3' # version 0.5.0
=> true
irb> filename = '/tmp/b.mp3'
=> "/tmp/b.mp3"
irb> puts "File size: #{ File::Stat.new(filename).size }"
File size: 8040064
irb> myfile = ID3::AudioFile.new( filename )
irb> puts "Audio length: #{myfile.audioLength}"
Audio length: 8037877
irb> puts "Audio MD5sum: #{myfile.audioMD5sum}"
Audio MD5sum: 47719e1881e5a2488e51fc250ccd2396
irb> # /usr/bin/irb
irb> RUBY_VERSION
=> "1.8.6"
irb> require 'id3' # version 0.5.0
=> true
irb> filename = '/tmp/b.mp3'
=> "/tmp/b.mp3"
irb> puts "File size: #{ File::Stat.new(filename).size }"
File size: 8040064
irb> myfile = ID3::AudioFile.new( filename )
irb> puts "Audio length: #{myfile.audioLength}"
Audio length: 8037877
irb> puts "Audio MD5sum: #{myfile.audioMD5sum}"
Audio MD5sum: 47719e1881e5a2488e51fc250ccd2396
irb> myfile.tagID3v2
=> {"ARTIST"=>{"encoding"=>0, "text"=>"Juno reactor"}, "CONTENTTYPE"=>{"encoding"=>0, "text"=>"Electronica/Dance"}, "ALBUM"=>{"encoding"=>0, "text"=>"Bible of Dreams"}, "ENCODEDBY"=>{"encoding"=>0, "text"=>"iTunes v2.0"}, "TRACKNUM"=>{"encoding"=>0, "text"=>"6/9"}, "TITLE"=>{"encoding"=>0, "text"=>"Kaguya Hime"}, "YEAR"=>{"encoding"=>0, "text"=>"1997"}, "COMMENT"=>{"encoding"=>0, "language"=>"eng", "short"=>"iTunes_CDDB_IDs", "long"=>"9+647C467468A248173A4A203ED2204CAB+163399"}}
irb> myfile.tagID3v1 = nil
irb> myfile.tagID3v2 = nil
irb> myfile.write
irb> puts "File size: #{ File::Stat.new(filename).size }"
File size: 8037877
答案 1 :(得分:0)
如果您使用的是Linux或Mac,请尝试使用BulkID3。 http://sourceforge.net/projects/bulkid3