[QUIZ] ID3 Tags (#136)

class ID3
   def initialize(tags)
     @tags = tags
     @genres = ['Classic Rock', 'Country', 'Dance', 'Disco', 'Funk', 'Grunge', 'Hip-Hop', 'Jazz',
     'Metal', 'New Age', 'Oldies', 'Other', 'Pop', 'R&B', 'Rap', 'Reggae', 'Rock', 'Techno',
     'Industrial', 'Alternative', 'Ska', 'Death Metal', 'Pranks', 'Soundtrack', 'Euro-Techno',
     'Ambient', 'Trip-Hop', 'Vocal', 'Jazz+Funk', 'Fusion', 'Trance', 'Classical', 'Instrumental',
     'Acid', 'House', 'Game', 'Sound Clip', 'Gospel', 'Noise', 'AlternRock', 'Bass', 'Soul', 'Punk',
     'Space', 'Meditative', 'Instrumental Pop', 'Instrumental Rock', 'Ethnic', 'Gothic', 'Darkwave',
     'Techno-Industrial', 'Electronic', 'Pop-Folk', 'Eurodance', 'Dream', 'Southern Rock', 'Comedy',
     'Cult', 'Gangsta', 'Top 40', 'Christian Rap', 'Pop/Funk', 'Jungle', 'Native American', 'Cabaret',
     'New Wave', 'Psychadelic', 'Rave', 'Showtunes', 'Trailer', 'Lo-Fi', 'Tribal', 'Acid Punk',
     'Acid Jazz', 'Polka', 'Retro', 'Musical', 'Rock & Roll', 'Hard Rock', 'Folk', 'Folk-Rock',
     'National Folk', 'Swing', 'Fast Fusion', 'Bebob', 'Latin', 'Revival', 'Celtic', 'Bluegrass',
     'Avantgarde', 'Gothic Rock', 'Progressive Rock', 'Psychedelic Rock', 'Symphonic Rock', 'Slow Rock',
     'Big Band', 'Chorus', 'Easy Listening', 'Acoustic', 'Humour', 'Speech', 'Chanson', 'Opera',
     'Chamber Music', 'Sonata', 'Symphony', 'Booty Bass', 'Primus', 'Porn Groove', 'Satire', 'Slow Jam',
     'Club', 'Tango', 'Samba', 'Folklore', 'Ballad', 'Power Ballad', 'Rhythmic Soul', 'Freestyle',
     'Duet', 'Punk Rock', 'Drum Solo', 'A capella', 'Euro-House', 'Dance Hall']
     self
   end
   def parse
     if @tags[0..2] = "TAG"
       @song = @tags[3..32].strip
       @album = @tags[33..62].strip
       @artist = @tags[63..92].strip
       @year = @tags[93..96].strip

       #don't strip comment until after track number is checked
       @comment = @tags[97..126]
       @genre = @genres[@tags[127]-1]

       #checks for Track Number
       if @comment[28] == 0
         @track = @comment[29].to_s
       end
       @comment.strip!
     end
     self
   end
   def print
     puts "Title: " + @song.to_s
     puts "Album: " + @album.to_s
     puts "Artist: " + @artist.to_s
     puts "Year: " + @year.to_s
     puts "Comment: " + @comment.to_s
     puts "Genre: " + @genre.to_s
     puts "Track: " + @track.to_s
     self
   end
end

class MP3
   @id3 = 0
   def initialize(file)
     @mp3 = IO.read(file)
     self
   end
   def parse_id3
     @id3 = ID3.new(@mp3[-128..-1])
     @id3.parse
     self
   end
   def print
     @id3.print
     self
   end
end

@mp3 = MP3.new(ARGV[0]).parse_id3.print

--Matt Pruitt

Please tell me how to run it on command line. When I run it, it appears
"can't
convert nil into String (TypeError) from reads_controller.rb: in
"initialize', from reads_controller.rb: in 'new', from
reads_controller.rb

Please help me. I'm a newbie for Ruby :frowning:

Attachments:
http://www.ruby-forum.com/attachment/743/error.JPG

···

--
Posted via http://www.ruby-forum.com/.

The file you show is probably part of a Rails project. For someone new to Ruby, that's pretty much jumping into the deep end of the pool.

You should probably start with some Ruby basics, like perhaps these tutorials:

http://www.ruby-lang.org/en/documentation/quickstart/

http://tryruby.hobix.com/

Also, please create a new message when posting a question to this mailing list. Replying to an existing topic messes up the threading for everyone.

James Edward Gray II

···

On Oct 23, 2007, at 5:49 AM, Gosho Thao wrote:

Please tell me how to run it on command line. When I run it, it appears
"can't
convert nil into String (TypeError) from reads_controller.rb: in
"initialize', from reads_controller.rb: in 'new', from
reads_controller.rb

Please help me. I'm a newbie for Ruby :frowning: