Class: Song

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Song

Returns a new instance of Song.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lyrix.rb', line 24

def initialize(path)
  @path = path

  # TODO: need to refactor this with a block 
  # TODO: research namespacing issue for blocks
  f = TagLib::MPEG::File.new(path)
  tag = f.id3v2_tag     
  # read basic attributes
  @title = tag.title
  @artist = tag.artist
  
  # Add lyrics frame
  uslt = TagLib::ID3v2::UnsynchronizedLyricsFrame.new
  uslt.text = fetch_lyrics
  tag.add_frame(uslt)

  f.save
  f.close
  # end

end

Instance Attribute Details

#artistObject (readonly)

Returns the value of attribute artist.



22
23
24
# File 'lib/lyrix.rb', line 22

def artist
  @artist
end

#lyricsObject (readonly)

Returns the value of attribute lyrics.



22
23
24
# File 'lib/lyrix.rb', line 22

def lyrics
  @lyrics
end

#pathObject (readonly)

Returns the value of attribute path.



22
23
24
# File 'lib/lyrix.rb', line 22

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



22
23
24
# File 'lib/lyrix.rb', line 22

def title
  @title
end

Instance Method Details

#fetch_lyricsObject

fetches song lyrics, sets @lyrics



47
48
49
# File 'lib/lyrix.rb', line 47

def fetch_lyrics
    @lyrics = WebHelper::fetch_lucky_content_for "#{@title} by #{@artist} lyrics"
end