# Re: ID3 Tags (#136)

**URL:** <https://www.ruby-forum.com/t/re-id3-tags-136/225964>\
**Category:** Ruby\
**Created:** [August 27, 2007, 4:22pm UTC](https://www.ruby-forum.com/t/re-id3-tags-136/225964 "2007-08-27T16:22:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lodestone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e495f1/32.png) [@lodestone](https://www.ruby-forum.com/u/lodestone)\
**Post date:** [August 27, 2007, 4:22pm UTC](https://www.ruby-forum.com/t/re-id3-tags-136/225964/1 "2007-08-27T16:22:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lodestone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e495f1/32.png) [@lodestone](https://www.ruby-forum.com/u/lodestone)\
**Post date:** [October 23, 2007, 12:49pm UTC](https://www.ruby-forum.com/t/re-id3-tags-136/225964/2 "2007-10-23T12:49:43Z")

</div>

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 ☹

---

<div class="post-metadata">

**Author:** ![lodestone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e495f1/32.png) [@lodestone](https://www.ruby-forum.com/u/lodestone)\
**Post date:** [October 23, 2007, 3:19pm UTC](https://www.ruby-forum.com/t/re-id3-tags-136/225964/3 "2007-10-23T15:19:02Z")

</div>

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 ☹

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://www.ruby-lang.org/en/documentation/quickstart/)

[http://tryruby.hobix.com/](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 G. II
