0

我想获得一个干净的 Mp3 文件,没有任何附加数据,如 id 标签、封面图像、编码器信息或其他任何数据。只是有效文件中的 mp3,可以播放每个 mp3 播放器。

我从这个开始: 独立于 ID3 标签访问 MP3 音频数据? http://code.google.com/p/kodebucket/source/browse/trunk/bin/mp3dump.rb

在没有 id 标签的情况下获得 mp3 的有效哈希效果很好,但是当您将输出保存到 mp3 文件中时,它会损坏。

也许你有一个想法,如何完成这项工作。

4

2 回答 2

1

这个 Ruby 库应该很简单:

http://unixgods.org/~tilo/Ruby/ID3/docs/index.html

最好是 0.5.0 或更高版本

安装 gem 后检查“示例”目录中的文件

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
于 2011-04-02T07:11:20.767 回答
0

如果您使用的是 Linux 或 Mac,请尝试 BulkID3。http://sourceforge.net/projects/bulkid3

于 2011-10-05T00:27:17.123 回答