strip off ID TAGS an other from raw MP3

依然范特西╮ 提交于 2019-12-12 05:49:01

问题


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 work.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/4111378/strip-off-id-tags-an-other-from-raw-mp3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!