Class: Mp3Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/lyrics_ebook/mp3_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMp3Parser

Returns a new instance of Mp3Parser.



7
8
9
# File 'lib/lyrics_ebook/mp3_parser.rb', line 7

def initialize
  @lyrics= []
end

Instance Attribute Details

#lyricsObject

Returns the value of attribute lyrics.



5
6
7
# File 'lib/lyrics_ebook/mp3_parser.rb', line 5

def lyrics
  @lyrics
end

Instance Method Details

#parse(filename) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lyrics_ebook/mp3_parser.rb', line 11

def parse filename
  if File.directory?(filename)
    Dir.foreach(filename) do |file2|
      unless ['.','..'].include?(file2)
        f= File.join(filename,file2)
        parse f
      end
    end
    return
  end
  
  ext=File.extname(filename)
  if (ext=='.mp3')
    Mp3Info.open(filename) do |mp3|
      if mp3.tag.title
        lyric=Lyric.new(:artist=>mp3.tag.artist, :album=>mp3.tag.album, :title=>mp3.tag.title,
          :tracknum=>mp3.tag.tracknum, :mp3_filename=>filename)
        @lyrics << lyric
        puts "Added : #{lyric.to_s}"  
      end
    end
  end
  
end