Class: Karaoke::Song::Genius

Inherits:
Base
  • Object
show all
Defined in:
lib/karaoke/song/genius.rb

Instance Attribute Summary

Attributes inherited from Base

#lyrics_url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Karaoke::Song::Base

Class Method Details

.matches?(lyrics_url) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/karaoke/song/genius.rb', line 6

def self.matches?(lyrics_url)
  URI.parse(lyrics_url).host.end_with?("genius.com") # Matches new *.genius.com URLs as well as rapgenius.com.
end

Instance Method Details

#artistObject



10
11
12
# File 'lib/karaoke/song/genius.rb', line 10

def artist
  @artist ||= tracking_data["Primary Artist"] || tracking_data["Primary Arist"]
end

#lyricsObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/karaoke/song/genius.rb', line 18

def lyrics
  return @lyrics if defined?(@lyrics)

  el = document.css(".lyrics p").first
  return @lyrics = nil unless el

  el.css("a").each { |a_el| a_el.replace(a_el.inner_html) }

  @lyrics = clean_html(el.inner_html)
end

#titleObject



14
15
16
# File 'lib/karaoke/song/genius.rb', line 14

def title
  @title ||= tracking_data["Title"]
end