开发者

strip off ID TAGS an other from raw MP3

I want to get an clean Mp3 File, without any aditional data like id Tags, Cover Image, encoder info or what else. Just the mp3 in an valid file, wich can play every mp3 player.

I started with this one: Access MP3 audio data independently of ID3 tags? http://code.google.com/p/kodebucket/source/browse/trunk/bin/mp3dump.rb

It works nice to get an valid hash of the mp3 without id Tags, but when you save the output into an mp3 file, it's broken.

Maybe you have there an idea, how to get this开发者_StackOverflow社区 work.


it should be pretty straight forward with this Ruby library:

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

preferably version 0.5.0 or higher

check the files in the 'examples' directory once the gem is installed

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

e.g.: testing this interactively in 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


Try BulkID3 if you're using Linux or Mac. http://sourceforge.net/projects/bulkid3

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜