Class: LyricsEbook

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

Overview

The main class

Song lyrics are stored in <home>/Lyrics, if exists,

else in <home>/.lyrics_ebook/Lyrics

Instance Method Summary collapse

Constructor Details

#initializeLyricsEbook

Returns a new instance of LyricsEbook.



15
16
17
18
19
20
21
# File 'lib/lyrics_ebook.rb', line 15

def initialize
  find_base_lyrics_dir
  @cm=CacheManager.new(@base_lyrics_dir)
  @cm.alternative_dir=@alt_lyrics_dir
  @dm=LyricDownload.new
  @mp3_parser=Mp3Parser.new
end

Instance Method Details

#build(epub_name = nil) ⇒ Object



51
52
53
54
55
56
# File 'lib/lyrics_ebook.rb', line 51

def build epub_name=nil
  epub_name="lyrics-ebook.epub" if epub_name.nil? 
  l2h=Lyrics2Html.new
  l2h.add_lyrics @cm.get_lyrics
  l2h.to_epub epub_name
end

#downloadObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lyrics_ebook.rb', line 33

def download
  puts "start downloading..."
  total, new, missing=0,0,0
  lyrics=@mp3_parser.lyrics
  lyrics.each do |lyric|
    total+=1
    if lyric.text.nil? && !@cm.get(lyric)
      if @dm.download(lyric)
        @cm.store(lyric)
        new+=1
      else
        missing+=1 
      end
    end
  end
  puts "#{total} songs in total; #{new} just downloaded; #{missing} missing "
end

#parse_dir(dir) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/lyrics_ebook.rb', line 23

def parse_dir dir
  if dir.nil?
    puts "Dir not set" 
    return 
  end
  @mp3_parser.parse dir
  $stdout.flush
  download
end